app.controller("barraCabecalhoController", function ($scope, $rootScope, $window, $http, perfilFactory, httpRequestFactory, loginFactory, $modal) {
    $scope.lstApps = [];

    //$rootScope.root_mostraBarraCabecalho = true;

    $scope.listarAplicacoes = function () {

        var getSuccessCallback = function (data, status) {
            $scope.lstApps = data;
        };

        var errorCallback = function (data, status, headers, config) {
            //notificationFactory.error(data);
        };


        httpRequestFactory.getData('../api/application/apps').success(getSuccessCallback).error(errorCallback);
    };

    $scope.mudaDeAplicacao = function (appInfo) {
        if (appInfo == null) {
            notificationFactory.error("Aplicação inválida");
            return;
        }


        var getSuccessCallback = function (data, status) {
            if (data.Success === false) {
                notificationFactory.error(data.Message);
                return;
            }

            
            loginFactory.encerrarSessao();

            $window.location.href = data.Dados;
        };

        var errorCallback = function (data, status, headers, config) {
            //notificationFactory.error(data);
        };


        httpRequestFactory.postData('../api/application/apps/redirectUrl', appInfo).success(getSuccessCallback).error(errorCallback);
    };

    $scope.encerrarSessao = function () {
        loginFactory.encerrarSessao();
    };

    $scope.imprimirManual = function () {
        window.open("../api/downloaddoc/manual?tk=" + sessionStorage.getItem("CibeAtk"));
    };

    $scope.mostraBarraCabecalho = function () {
        $rootScope.root_mostraBarraCabecalho = !$rootScope.root_mostraBarraCabecalho;
    }

    $scope.getImgSrcBotaoColapsar = function () {
        if ($rootScope.root_mostraBarraCabecalho === true)
            return '../app/images/down.png';
        return '../app/images/up.png';
    }
    

});