(function () {
    global.dashModule
        .controller('suppliersProcurementViewCtrl', ['$scope', '$', '$http', '$rootScope', '$compile', 'utilsService', 'ordersUtilsService', suppliersProcurementViewCtrl])
        .directive('suppliersProcurementView', [suppliersProcurementViewDirective]);

    function suppliersProcurementViewDirective() {
        return {
            restrict: 'E',
            templateUrl: 'orders/html/suppliersProcurementViewTemplate'
        };
    }

    function suppliersProcurementViewCtrl($scope, $, $http, $rootScope, $compile, utilsService, ordersUtilsService) {
        $scope.hasExtraAction = ordersUtilsService.hasExtraAction;
        $scope.getOrderSteps = getOrderSteps;

        function getOrderSteps() {
            const idOrder = global.getParameterByName('idOrder') || 0;
            const params = $.param({
                idOrder
            });
            $http({
                method: 'POST',
                url: 'orders/api/getOrderSteps',
                data: params
            }).then(showOrderSteps, utilsService.onHttpError);
        }

        function showOrderSteps(response) {
            if (typeof response.data === 'object') {
                $scope.processSteps = response.data;
            }
        }
    }
})();
