"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

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

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

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

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

var _ConfigProvider = _interopRequireDefault(require("./config/ConfigProvider"));

var _RootPage = _interopRequireDefault(require("./pages/RootPage"));

var _withClassName = _interopRequireDefault(require("../enhancers/withClassName"));

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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

class App extends _react.Component {
  constructor() {
    super();
    this.showConfirmNavigationModal = this.showConfirmNavigationModal.bind(this);
  }

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

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

  render() {
    const {
      config,
      store,
      router
    } = this.props;
    const {
      basename,
      className,
      index,
      locale,
      messages,
      prettyUrls
    } = config; // 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 _react.default.createElement(_reactIntl.IntlProvider, {
      locale: locale,
      defaultLocale: "en-US",
      messages: messages
    }, _react.default.createElement(_reactRedux.Provider, {
      store: store
    }, _react.default.createElement(_ConfigProvider.default, {
      config: config
    }, _react.default.createElement(Router, {
      basename: basename,
      getUserConfirmation: this.showConfirmNavigationModal
    }, _react.default.createElement(_reactRouter.Switch, null, _react.default.createElement(_reactRouter.Redirect, {
      exact: true,
      path: "/",
      to: index
    }), _react.default.createElement(_reactRouter.Route, {
      component: (0, _withClassName.default)(_RootPage.default, className)
    }))))));
  }

}

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