/// <reference path="../../../Scripts/underscore.js" />
/// <reference path="../../common/utils/enums.js" />
/// <reference path="../nav-bar-util.js" />

// AppNavBarController controller for the navigation bar of the application. This controller is responsible for 
// manage the different types of the tabs and corresponding menus.
frameworkModule.controller('AppNavBarController', ['$scope', '$log', '$cookies', '$filter', 'loginContext',
function ($scope, $log, $cookies, $filter, loginContext)
{
    'use strict';

    var shownKey = 'shownChangePasswordOf' + loginContext.passwordHash;

    $log.debug('AppNavController.ctor()...');

    $scope.username = loginContext.userName;
    $scope.isExternalUser = loginContext.isExternalUser;

    $scope.showChangePassword = function ()
    {
        $scope.$emit('event:showChangePasswordModal', 'click');
    }

    var todayIsShowed = $cookies.get(shownKey);

    if (loginContext.needChangePassword & !todayIsShowed)
    {
        $scope.$emit('event:showChangePasswordModal', 'auto');


        $cookies.put(shownKey, true);
    }
}
]);