(function(){
    angular.module('ctfApp').controller('NavigationController', ['$scope', '$rootScope', '$location', 'AuthenticationService',
        function($scope, $rootScope, $location, AuthenticationService){

        $scope.logged = $rootScope.globals ? !!$rootScope.globals.currentUser : false;

        $scope.user = $rootScope.globals && $rootScope.globals.currentUser ? $rootScope.globals.currentUser.username : undefined;

        $scope.logout = function(){
            $('.title').html('guest@<b>capture-the-flAGH-2016</b>:~$');
            AuthenticationService.logout(function(data){
                $location.path('/');
            });
        };

        $scope.$watch(function(){
            return $rootScope.globals;
        }, function(){
            $scope.logged = $rootScope.globals ? !!$rootScope.globals.currentUser : false;
            $scope.user = $rootScope.globals && $rootScope.globals.currentUser ? $rootScope.globals.currentUser.username : undefined;
        });


    }]);
})();
