'use strict';

angular.module('app').controller('UserController', ['$scope', '$state', function ($scope, $state) {

  lxtalkClient.Invoke('{FB60F992-A0FD-47B3-AAA7-E80DF209C5A4}', '_Register', '', $scope);

  $scope.update = function (userJson) {
    var user = JSON.parse(userJson);

    $scope.user = user;
    
    $scope.user.shortL = $scope.user.l.substring(7);
    if ($state.current.name == 'simple-enterprise' || $state.current.name == 'simple') {
      // alert($state.current.name);
      if ($scope.user.l.length >= 15 && $state.current.name !== 'simple-enterprise')
        $state.go('simple-enterprise');
      else if ($scope.user.l.length < 15 && $state.current.name !== 'simple')
        $state.go('simple');
    }
    else if ($state.current.name == 'details-enterprise' || $state.current.name == 'details')
    {
      if ($scope.user.l.length >= 15 && $state.current.name !== 'details-enterprise')
        $state.go('details-enterprise');
      else if ($scope.user.l.length < 15 && $state.current.name !== 'details')
        $state.go('details');
    }

  }
}]);