"use strict";

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

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

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

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

var _immutable = _interopRequireDefault(require("immutable"));

var _ProtectedPage = _interopRequireDefault(require("../pages/ProtectedPage"));

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

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

const propTypes = {
  component: _propTypes.default.func,
  decorated: _propTypes.default.bool,
  openModalName: _propTypes.default.string,
  perms: _propTypes.default.instanceOf(_immutable.default.Map),
  screenName: _propTypes.default.string,
  username: _propTypes.default.string,
  userPrefsLoaded: _propTypes.default.bool,
  closeModal: _propTypes.default.func,
  resetLogin: _propTypes.default.func
};

function ProtectedRoute(props) {
  const {
    component: Component,
    decorated,
    openModalName,
    perms,
    screenName,
    username,
    userPrefsLoaded,
    closeModal,
    resetLogin,
    ...remainingProps
  } = props;
  return /*#__PURE__*/_react.default.createElement(_reactRouter.Route, _extends({}, remainingProps, {
    render: routeProps => username ? /*#__PURE__*/_react.default.createElement(_ProtectedPage.default, _extends({
      openModalName: openModalName,
      perms: perms,
      screenName: screenName,
      username: username,
      userPrefsLoaded: userPrefsLoaded,
      decorated: decorated,
      closeModal: closeModal,
      resetLogin: resetLogin
    }, routeProps), /*#__PURE__*/_react.default.createElement(Component, routeProps)) : /*#__PURE__*/_react.default.createElement(_reactRouter.Redirect, {
      to: {
        pathname: '/login',
        state: {
          continuation: routeProps.location
        }
      }
    })
  }));
}

ProtectedRoute.propTypes = propTypes;