'use strict';

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

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 }; }

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

class App extends _react.Component {
  constructor() {
    super();

    this.showConfirmNavigationModal = this.showConfirmNavigationModal.bind(this);
  }

  showConfirmNavigationModal(message, callback) {
    const openModal = this.props.openModal;


    if (openModal) {
      openModal(message, callback);
    }
  }

  render() {
    var _props = this.props;
    const config = _props.config,
          store = _props.store,
          router = _props.router;
    const 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.

    let 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) })
            )
          )
        )
      )
    );
  }
}

exports.default = App;
App.propTypes = propTypes;