'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactIntl = require('react-intl');

var _reactRedux = require('react-redux');

var _reactRouter = require('react-router');

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

var _ConfigProvider = require('./config/ConfigProvider');

var _ConfigProvider2 = _interopRequireDefault(_ConfigProvider);

var _RootPage = require('./pages/RootPage');

var _RootPage2 = _interopRequireDefault(_RootPage);

var _withClassName = require('../enhancers/withClassName');

var _withClassName2 = _interopRequireDefault(_withClassName);

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var propTypes = {
  store: _propTypes2.default.object.isRequired,
  config: _propTypes2.default.object.isRequired,
  router: _propTypes2.default.func,
  openModal: _propTypes2.default.func
};

var App = function (_Component) {
  _inherits(App, _Component);

  function App() {
    _classCallCheck(this, App);

    var _this = _possibleConstructorReturn(this, (App.__proto__ || Object.getPrototypeOf(App)).call(this));

    _this.showConfirmNavigationModal = _this.showConfirmNavigationModal.bind(_this);
    return _this;
  }

  _createClass(App, [{
    key: 'showConfirmNavigationModal',
    value: function showConfirmNavigationModal(message, callback) {
      var openModal = this.props.openModal;


      if (openModal) {
        openModal(message, callback);
      }
    }
  }, {
    key: 'render',
    value: function render() {
      var _props = this.props,
          config = _props.config,
          store = _props.store,
          router = _props.router;
      var basename = config.basename,
          className = config.className,
          index = config.index,
          locale = config.locale,
          messages = config.messages,
          prettyUrls = config.prettyUrls;

      // Allow a router to be supplied as a prop. This is used for tests.

      var Router = router;

      if (!Router) {
        Router = prettyUrls ? _reactRouterDom.BrowserRouter : _reactRouterDom.HashRouter;
      }

      return _react2.default.createElement(
        _reactIntl.IntlProvider,
        { locale: locale, defaultLocale: 'en-US', messages: messages },
        _react2.default.createElement(
          _reactRedux.Provider,
          { store: store },
          _react2.default.createElement(
            _ConfigProvider2.default,
            { config: config },
            _react2.default.createElement(
              Router,
              { basename: basename, getUserConfirmation: this.showConfirmNavigationModal },
              _react2.default.createElement(
                _reactRouter.Switch,
                null,
                _react2.default.createElement(_reactRouter.Redirect, { exact: true, path: '/', to: index }),
                _react2.default.createElement(_reactRouter.Route, { component: (0, _withClassName2.default)(_RootPage2.default, className) })
              )
            )
          )
        )
      );
    }
  }]);

  return App;
}(_react.Component);

exports.default = App;


App.propTypes = propTypes;