'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports['default'] = undefined;

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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactRouterCacheRoute = require('react-router-cache-route');

var _reactRouterCacheRoute2 = _interopRequireDefault(_reactRouterCacheRoute);

var _index = require('../{{ source }}/containers/components/index');

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

var _asyncRouter2 = _interopRequireDefault(_asyncRouter);

var _asyncModuleWrapper = require('../{{ source }}/containers/components/util/asyncModuleWrapper');

var _asyncModuleWrapper2 = _interopRequireDefault(_asyncModuleWrapper);

var _createAxiosInsByModuleName = require('../{{ source }}/containers/components/util/createAxiosInsByModuleName');

var _createAxiosInsByModuleName2 = _interopRequireDefault(_createAxiosInsByModuleName);

var _iframeWrapper = require('../{{ source }}/containers/components/iframeWrapper');

var _iframeWrapper2 = _interopRequireDefault(_iframeWrapper);

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

var routes = {};
var CHOERODON_HAP_FRONT_BOOT_HOME_PAGE = 'home';

function createRoute(path, component, moduleCode) {
  var moduleAxios = (0, _createAxiosInsByModuleName2['default'])(moduleCode);
  if (!routes[path]) {
    var Cmp = (0, _asyncModuleWrapper2['default'])(component, null, null, moduleCode, moduleAxios);
    routes[path] = _react2['default'].createElement(_reactRouterCacheRoute2['default'], { path: path, component: Cmp });
  }
  return routes[path];
}

function createHome(path, component, homePath) {
  if (!routes[path]) {
    var Cmp = (0, _asyncRouter2['default'])(homePath ? component : function () {
      return import('../{{ source }}/containers/components/home');
    }, null, { axios: (0, _createAxiosInsByModuleName2['default'])(CHOERODON_HAP_FRONT_BOOT_HOME_PAGE) });
    routes[path] = _react2['default'].createElement(_reactRouterCacheRoute2['default'], { exact: true, path: path, component: Cmp });
  }
  return routes[path];
}

var Home = (0, _asyncRouter2['default'])(function () {
  return import('../{{ source }}/containers/components/home');
}, null, { axios: (0, _createAxiosInsByModuleName2['default'])(CHOERODON_HAP_FRONT_BOOT_HOME_PAGE) });

var AutoRouter = function (_Component) {
  (0, _inherits3['default'])(AutoRouter, _Component);

  function AutoRouter() {
    (0, _classCallCheck3['default'])(this, AutoRouter);
    return (0, _possibleConstructorReturn3['default'])(this, (AutoRouter.__proto__ || Object.getPrototypeOf(AutoRouter)).apply(this, arguments));
  }

  (0, _createClass3['default'])(AutoRouter, [{
    key: 'render',
    value: function render() {
      return _react2['default'].createElement(
        _reactRouterCacheRoute.CacheSwitch,
        null,
        {{ home }},
        {{ routes }},
        _react2['default'].createElement(_reactRouterCacheRoute2['default'], { path: '/iframe/:name', cacheKey: 'iframe', component: _iframeWrapper2['default'] }),
        _react2['default'].createElement(_reactRouterCacheRoute2['default'], { path: '*', component: _index.nomatch })
      );
    }
  }]);
  return AutoRouter;
}(_react.Component);

exports['default'] = AutoRouter;