var angular = require('angular');
require('../modules');
'use strict';

var module = angular.module('setting');
angular
  .module('setting')
  .controller('SettingCtrl', SettingCtrl);

/** @ngInject */
function SettingCtrl($scope, $state, AppConfig, LinkerService) {

  $scope.$on('$ionicView.beforeEnter', function() {
    getLoginUser();
  });

  /**
   * 获取当前登录人信息。
   */
  function getLoginUser() {
    var user = LinkerService.currentUser,
      userId = LinkerService.currentUserId;
    $scope.loginUser = user || {};
  }

  $scope.setItems = AppConfig.getSetItems();

  $scope.toState = function(setItem) {
    if (typeof setItem.state === 'function') {
      setItem.state();
    } else if (setItem.state) {
      $state.go(setItem.state);
    }
  }
}
