'use strict';

var _regenerator = require('babel-runtime/regenerator');

var _regenerator2 = _interopRequireDefault(_regenerator);

var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _class;

require('babel-polyfill');

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactDom = require('react-dom');

var _reactRouterDom = require('react-router-dom');

var _history = require('history');

var _mobxReact = require('mobx-react');

var _Loading = require('../{{ source }}/containers/components/entryCmp/Loading');

var _Loading2 = _interopRequireDefault(_Loading);

var _stores = require('../{{ source }}/containers/stores');

var _stores2 = _interopRequireDefault(_stores);

var _AppState = require('../{{ source }}/containers/stores/AppState');

var _AppState2 = _interopRequireDefault(_AppState);

var _asyncRouter = require('../{{ source }}/containers/components/util/asyncRouter');

var _asyncRouter2 = _interopRequireDefault(_asyncRouter);

require('../{{ source }}/containers/components/style');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var Masters = (0, _asyncRouter2['default'])(function () {
  return import('../{{ source }}/containers/components/master/MasterWithoutSider.js');
}, {
  AutoRouter: function AutoRouter() {
    return import('{{ routesPath }}');
  }
}, {
  __refresh__: true
});

var App = (0, _mobxReact.observer)(_class = function (_Component) {
  (0, _inherits3['default'])(App, _Component);

  function App() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3['default'])(this, App);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3['default'])(this, (_ref = App.__proto__ || Object.getPrototypeOf(App)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
      loading: true
    }, _temp), (0, _possibleConstructorReturn3['default'])(_this, _ret);
  }

  (0, _createClass3['default'])(App, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      var _this2 = this;

      Promise.all([this.auth(), this.loadLocale(), this.loadSysInfo()]).then(function (res) {
        if (res.every(function (item) {
          return item;
        })) {
          _this2.setState({
            loading: false
          });
        }
      });
    }
  }, {
    key: 'auth',
    value: function () {
      var _ref2 = (0, _asyncToGenerator3['default'])( /*#__PURE__*/_regenerator2['default'].mark(function _callee() {
        return _regenerator2['default'].wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.prev = 0;
                _context.t0 = _AppState2['default'];
                _context.next = 4;
                return _AppState2['default'].loadUserInfo();

              case 4:
                _context.t1 = _context.sent;

                _context.t0.setUserInfo.call(_context.t0, _context.t1);

                return _context.abrupt('return', true);

              case 9:
                _context.prev = 9;
                _context.t2 = _context['catch'](0);
                return _context.abrupt('return', false);

              case 12:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, this, [[0, 9]]);
      }));

      function auth() {
        return _ref2.apply(this, arguments);
      }

      return auth;
    }()
  }, {
    key: 'loadLocale',
    value: function () {
      var _ref3 = (0, _asyncToGenerator3['default'])( /*#__PURE__*/_regenerator2['default'].mark(function _callee2() {
        return _regenerator2['default'].wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                _context2.prev = 0;
                _context2.t0 = _AppState2['default'];
                _context2.next = 4;
                return _AppState2['default'].loadLocale();

              case 4:
                _context2.t1 = _context2.sent;

                _context2.t0.setLocales.call(_context2.t0, _context2.t1);

                return _context2.abrupt('return', true);

              case 9:
                _context2.prev = 9;
                _context2.t2 = _context2['catch'](0);
                return _context2.abrupt('return', false);

              case 12:
              case 'end':
                return _context2.stop();
            }
          }
        }, _callee2, this, [[0, 9]]);
      }));

      function loadLocale() {
        return _ref3.apply(this, arguments);
      }

      return loadLocale;
    }()
  }, {
    key: 'loadSysInfo',
    value: function () {
      var _ref4 = (0, _asyncToGenerator3['default'])( /*#__PURE__*/_regenerator2['default'].mark(function _callee3() {
        return _regenerator2['default'].wrap(function _callee3$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                _context3.prev = 0;
                _context3.t0 = _AppState2['default'];
                _context3.next = 4;
                return _AppState2['default'].loadSysInfo();

              case 4:
                _context3.t1 = _context3.sent;

                _context3.t0.setSysInfo.call(_context3.t0, _context3.t1);

                return _context3.abrupt('return', true);

              case 9:
                _context3.prev = 9;
                _context3.t2 = _context3['catch'](0);
                return _context3.abrupt('return', false);

              case 12:
              case 'end':
                return _context3.stop();
            }
          }
        }, _callee3, this, [[0, 9]]);
      }));

      function loadSysInfo() {
        return _ref4.apply(this, arguments);
      }

      return loadSysInfo;
    }()
  }, {
    key: 'render',
    value: function render() {
      var loading = this.state.loading;

      return _react2['default'].createElement(
        _mobxReact.Provider,
        _stores2['default'],
        _react2['default'].createElement(
          _reactRouterDom.HashRouter,
          { hashHistory: _history.createBrowserHistory },
          _react2['default'].createElement(
            _reactRouterDom.Switch,
            null,
            _react2['default'].createElement(_reactRouterDom.Route, {
              path: '/',
              component: loading ? _Loading2['default'] : Masters
            })
          )
        )
      );
    }
  }]);
  return App;
}(_react.Component)) || _class;

(0, _reactDom.render)(_react2['default'].createElement(App, null), document.getElementById('app'));