'use strict';
let env = {};

// Import variables if present (from env.js)
if (window) {
    Object.assign(env, window.__env);
}

$(window).load(() => setTimeout(() => $('body').removeClass('preload'), 800));


(function () {
    /**
     * @ngdoc overview
     * @name setoresApp
     * @description
     * # setoresApp
     *
     * Main module of the application.
     */
    angular
        .module('setoresApp', [
            'ngRaven',
            'ngAnimate',
            'ngCookies',
            'ngSanitize',
            'ngNotify',
            'ui.router',
            'ui.router.stateHelper',
            'ngSanitize',
            'luegg.directives',
            'checklist-model'
        ]).config(function ($urlRouterProvider, stateHelperProvider, $locationProvider, __env, $compileProvider) {
            stateHelperProvider.setNestedState({
                name: 'setores',
                url: '/Setores/Setores',
                templateUrl: __env.appPath + 'scripts/index/setores-index.html',
                authenticate: true,
                resolve: {
                    permissoesUsuario: function (configuracoesService) {
                        return configuracoesService.carregarPermissoesUsuario();
                    }
                },
                controller: 'setoresIndexController as vm'
            });

            stateHelperProvider.setNestedState({
                name: 'setoresDetalhe',
                url: '/Setores/Setores/Detalhes',
                params: { dataSetor: null },
                templateUrl: __env.appPath + 'scripts/detalhes/setores-detalhes.html',
                authenticate: true,
                resolve: {
                    permissoesUsuario: function (configuracoesService) {
                        return configuracoesService.carregarPermissoesUsuario();
                    },
                    ferramentasHabilitadas: function (configuracoesService) {
                        return configuracoesService.carregarFerramentasHabilitadas();
                    }
                },
                controller: 'setoresDetalhesController as vm'
            });
            stateHelperProvider.setNestedState({
                name: 'login',
                url: __env.baseUrl + '/Autenticador/Account/Login',
                authenticate: false
            });

            $urlRouterProvider.otherwise('/Setores/Setores');
            $locationProvider.html5Mode({ enabled: true });

            $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|file|blob):|data:image\//);
        });

    angular
        .module('setoresApp')
        .run(function (ngNotify) {
            ngNotify.addTheme('notifyCustom', 'notification');

            ngNotify.config({
                theme: 'notifyCustom',
                position: 'top',
                target: '#notificationOuter',
                button: true,
                html: false
            });
        });

    angular
        .module('setoresApp')
        .constant('__env', env);
})();
