(function() {
  'use strict';

  angular.module('Monitour.pages.login')
    .controller('loginCtrl', loginCtrl);

  /** @ngInject */
  function loginCtrl($scope,   AuthenticationService, $localStorage, $state) {
    var vm = this;
    vm.sentence = {static: 'Your total platrom management needs for'};
    
    // should be resolved by the router, and injected in this controller
    // that way, words are ready when the controller is instantiated
    // and when the link function of the directive is triggered
    vm.sentence.options = ['Calls', 'Sms', 'Programable Voice', 'Call Flows', 'Voice Mail'];
   
        vm.login = login;
 
        initController();
 
        function initController() {
            // reset login status
            AuthenticationService.Logout();
        };
 
        function login() {
            vm.loading = true;
            AuthenticationService.Login(vm.username, vm.password, function (result) {
				
				vm.result = result;
				console.log(vm.result.data.data);
				console.log(vm.result.data.success);
		     vm.data = vm.result.data.data;
			  if (vm.result.data.access_token) {
			console.log($localStorage.currentUser);


                  swal({
						title: 'Succesfully logged in',
						text: vm.result.data.data
						});
				     $state.go('main.dashboard');
                } else {

                  swal({title: 'Your login details were incorrect!',
				    text:  vm.data
                  });
       
                }
            });
        };
    }

})();