'use strict';
angular.module('Authentication', []);
var app = angular.module('bmcApp', [
  'Authentication', 'ngCookies', 'ui.bootstrap', 'ui.router', 'restangular',
  'ngSanitize', 'ngWebSocket'
]);


app.controller('MainCtrl', function($scope, Restangular) {

});

app.run(['$rootScope', '$cookieStore', '$state', 'Restangular', 'AuthenticationService',
  function($rootScope, $cookieStore, $state, Restangular, AuthenticationService) {
    if ($rootScope.globals == undefined){
        $rootScope.globals = {};
    }
    
    // keep user logged in after page refresh
    AuthenticationService.RestoreCredientials();

    $rootScope.$on(
        '$stateChangeStart',
        function(event, toState, toParams, fromState, fromParams, options) {
          // redirect to login page if not logged in
          if (toState.name !== 'login' && !$rootScope.globals.currentUser) {
            // If logged out and transitioning to a logged in page:
            event.preventDefault();
            $state.go('login');
          }
        });

    // RestangularProvider.setDefaultHttpFields({cache: true});
    Restangular.setErrorInterceptor(function(response) {
      if (response.status == 401) {
        console.log("Login required... ");

        var invalidate_reason = "Your user was logged out.";
        var continue_promise_chain = false;

        // if we're attempting to log in, we need to
        // continue the promise chain to make sure the user is informed
        if ($state.current.name === "login") {
          invalidate_reason = "Your username and password was incorrect";
          continue_promise_chain = true
        } else {
          $state.after_login_state = $state.current.name;
          $state.go('login');
        }
        AuthenticationService.ClearCredentials(invalidate_reason);

        return continue_promise_chain;  // stop the promise chain
      } else if (response.status == 404) {
        console.log("Resource not available...");
      } else {
        console.log(
            "Response received with HTTP error code: " + response.status);
      }

    });

  }
]);

app.config(function(RestangularProvider) {
  // set the base url for api calls on our RESTful services
  var newBaseUrl = "";

  var deployedAt = window.location.href.substring(0, window.location.href);
  newBaseUrl = deployedAt + "/restui";

  RestangularProvider.setBaseUrl(newBaseUrl);
});

app.config(function($stateProvider, $urlRouterProvider) {

  $urlRouterProvider.otherwise('/systeminfo');

  $stateProvider
      // nested list with just some random string data
      .state('login', {
        url: '/login',
        templateUrl: 'login.html',
        controller: 'LoginController',
      })
      // systeminfo view ========================================
      .state(
          'systeminfo',
          {url: '/systeminfo', templateUrl: 'partial-systeminfo.html'})


      // HOME STATES AND NESTED VIEWS ========================================
      .state(
          'eventlog', {url: '/eventlog', templateUrl: 'partial-eventlog.html'})


      .state(
          'kvm', {url: '/kvm', templateUrl: 'partial-kvm.html'})

      // ABOUT PAGE AND MULTIPLE NAMED VIEWS =================================
      .state('about', {url: '/about', templateUrl: 'partial-fruinfo.html'})

      // nested list with custom controller
      .state('about.list', {
        url: '/list',
        templateUrl: 'partial-home-list.html',
        controller: function($scope) {
          $scope.dogs = ['Bernese', 'Husky', 'Goldendoodle'];
        }
      })


});

app.controller('PaginationDemoCtrl', function($scope, $log) {
  $scope.totalItems = 64;
  $scope.currentPage = 4;

  $scope.setPage = function(pageNo) { $scope.currentPage = pageNo; };

  $scope.pageChanged = function() {
    $log.log('Page changed to: ' + $scope.currentPage);
  };

  $scope.maxSize = 5;
  $scope.bigTotalItems = 175;
  $scope.bigCurrentPage = 1;
});

angular
    .module('Authentication')

    .controller('LoginController', [
      '$scope', '$rootScope', '$location', '$state', 'AuthenticationService',
      function($scope, $rootScope, $location, $state, AuthenticationService) {
        $scope.logoutreason = AuthenticationService.logoutreason;

        $scope.login = function() {
          $scope.dataLoading = true;
          AuthenticationService.Login(
              $scope.username, $scope.password,
              function(response) {
                AuthenticationService.SetCredentials(
                    $scope.username, response.token);
                if (typeof $state.after_login_state === "undefined") {
                  $state.after_login_state = "systeminfo";
                }
                $state.go($state.after_login_state);
                delete $state.after_login_state;

              },
              function(response) {
                if (response.status === 401) {
                  // reset login status
                  AuthenticationService.ClearCredentials(
                      "Username or Password is incorrect");
                }
                $scope.logoutreason = AuthenticationService.logoutreason;
                $scope.error = response.message;
                $scope.dataLoading = false;
              });
        };
      }
    ]);

angular
    .module('Authentication')

    .factory(
        'AuthenticationService',
        [
          'Restangular', '$cookieStore', '$rootScope', '$timeout',
          function(Restangular, $cookieStore, $rootScope, $timeout) {
            var service = {};

            service.Login = function(
                username, password, success_callback, fail_callback) {

              var user = {"username": username, "password": password};
              Restangular.all("login").post(user).then(
                  success_callback, fail_callback);
            };

            service.SetCredentials = function(username, token) {
              $rootScope.globals["currentUser"] = {username: username, authdata: token};
              Restangular.setDefaultHeaders(
                  {'Authorization': 'Token ' + token});
              $cookieStore.put('globals', $rootScope.globals);
            };

            service.ClearCredentials = function(reason) {
              $rootScope.globals["currentUser"] = null;
              if (reason !== null) {
                service.logoutreason = reason;
              }
              $cookieStore.remove('globals');
              Restangular.setDefaultHeaders({});
            };

            service.RestoreCredientials = function() {
              var globals = $cookieStore.get('globals') || {};
              if (globals.currentUser) {
                service.SetCredentials(
                    globals.currentUser.username, globals.currentUser.authdata);
              }
            };

            service.logoutreason = "";
            return service;
          }
        ])

    .factory('Websocket_URI', 
        function($rootScope, $http) {
          var loc = window.location, websocket_uri;
          if (loc.protocol === "https:") {
            websocket_uri = "wss:";
          } else {
            websocket_uri = "ws:";
          }
          websocket_uri += "//" + loc.hostname + ":9000";
          // Append the authentication token
          websocket_uri += "?token="
          websocket_uri += $rootScope.globals["currentUser"]["authdata"]
          var methods = {
            uri: websocket_uri
          }
          return methods;
        })
    .factory('Base64', function() {
      /* jshint ignore:start */

      var keyStr =
          'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

      return {
        encode: function(input) {
          var output = "";
          var chr1, chr2, chr3 = "";
          var enc1, enc2, enc3, enc4 = "";
          var i = 0;

          do {
            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
              enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
              enc4 = 64;
            }

            output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
                keyStr.charAt(enc3) + keyStr.charAt(enc4);
            chr1 = chr2 = chr3 = "";
            enc1 = enc2 = enc3 = enc4 = "";
          } while (i < input.length);

          return output;
        },

        decode: function(input) {
          var output = "";
          var chr1, chr2, chr3 = "";
          var enc1, enc2, enc3, enc4 = "";
          var i = 0;

          // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
          var base64test = /[^A-Za-z0-9\+\/\=]/g;
          if (base64test.exec(input)) {
            window.alert(
                "There were invalid base64 characters in the input text.\n" +
                "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
                "Expect errors in decoding.");
          }
          input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

          do {
            enc1 = keyStr.indexOf(input.charAt(i++));
            enc2 = keyStr.indexOf(input.charAt(i++));
            enc3 = keyStr.indexOf(input.charAt(i++));
            enc4 = keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
              output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
              output = output + String.fromCharCode(chr3);
            }

            chr1 = chr2 = chr3 = "";
            enc1 = enc2 = enc3 = enc4 = "";

          } while (i < input.length);

          return output;
        }
      };

      /* jshint ignore:end */
    });
