(function () {
    'use strict';

    angular
        .module('setoresApp')
        .directive('dropDownProfile', dropDownProfile);

    dropDownProfile.$inject = ['configuracoesService', '__env'];

    /* @ngInject */
    function dropDownProfile(configuracoesService, __env) {

        let directive = {
            restrict: 'E',
            replace: true,
            templateUrl: __env.appPath + 'scripts/components/drop-down-profile/drop-down-profile.directive.html',
            scope: false,
            link: link,
        };

        return directive;

        function link(scope, element, attr, ctrl) {

            angular.extend(scope.vm, {
                logoff: logoff
            });

            function logoff() {
                configuracoesService.logoff()
                    .then(() => window.location.href = urlGlobal + "Setores/Setores")
                    .catch(errorRequest);
            }

            configuracoesService.consultaUsuarioLogado()
                .then((data) => scope.vm.usuarioLogado = data.data)
                .catch(errorRequest);

            configuracoesService.consultaVersao()
                .then((data) => scope.vm.versaoSistema = data.data)
                .catch(errorRequest);

            function errorRequest(error) {
                debugger;
                console.error(error);
            }
        }
    }
})();
