'use strict';

var	angular	= require('angular');
require('../modules');
  require('../services/GesturePasswordService');

var	module = angular.module('gesturepassword.controller');

module.controller('configGesturePasswordController', function($scope, GesturePasswordService, $state, appFlowConfigService) {
    
    $scope.configChange = configChange;
    $scope.setGesturePassword = setGesturePassword;
    
    init(); 
    
    function init() {
      $scope.config = {
         start: appFlowConfigService.needGesturePassword()
      };
    }
    
    function configChange() {
      var value = $scope.config.start;    
      if (value === false) {
        appFlowConfigService.setNeedGesturePassword(value);
        GesturePasswordService.clear();
      } else if (value === true) { 
        setGesturePassword();
      }
    }
    
    function setGesturePassword() {
      GesturePasswordService.transferGesturePassword().then(function(gesturePassword) {
        if (gesturePassword) {
          $state.go('gesturepassword.modifyGesturepassword');
        } else {
          $state.go('gesturepassword.setGesturePwd2CanBack');
        }
      });
    }

});
