const NavbarComponent = {
    templateUrl: "/app/navbar/navbar.component.html",
    controller: function ($rootScope, $state, $transitions, $activity, api, $window) {
        let $ctrl = this;
        $ctrl.logged = false;
        $ctrl.progress = null;
        $ctrl.isAdmin = false;
        $ctrl.inActivity = false; //sp4 by JD

        $ctrl.$onInit = function () {
            $ctrl.logged = api.isLoggedIn();
            $ctrl.isAdmin = api.isAdmin();
        }

        $rootScope.$on('auth-changed', function () {
            $ctrl.logged = api.isLoggedIn();
            $ctrl.isAdmin = api.isAdmin();
        });

        $ctrl.logOut = function () {
            api.logOff();
        }

        //this logs off the user when they hit refresh as well 
        //$window.onbeforeunload = api.logOff(); 

        $transitions.onSuccess({}, function (transition) {

            //SP4 by JD
            //console.log("Called from NavBarComponent.... a transition has taken place");
            if ($state.current.name == "activity") {           
                $ctrl.inActivity = true;
                $ctrl.progress = "Activity " + ($activity.getCurrentActivityIndex() + 1) + " of " + $activity.getActivityCount();
            }
            else if ($state.current.name == "done") {
                $ctrl.inActivity = false;
                $ctrl.progress = "Activities Completed";
            } else {
                $ctrl.inActivity = false;
            }
        });
    }
};