"use strict";

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

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

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

var _reactRouterBootstrap = require("react-router-bootstrap");

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

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

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

/**
 * This function enhances the routing components imported above
 * by preserving the itinerary search query from the redux state
 * when redirecting the user between the main map and account-related pages,
 * so that when the user returns to the map, the itinerary that was previously
 * displayed is shown again.
 * Implementers only need to specify the 'to' route and
 * do not need to hook to redux store to retrieve the itinerary search query.
 * @param RoutingComponent The routing component to enhance.
 * @returns A new component that passes the redux search params to
 *          the RoutingComponent's 'to' prop.
 */
const withQueryParams = RoutingComponent => ({
  children,
  queryParams,
  to,
  ...props
}) => /*#__PURE__*/_react.default.createElement(RoutingComponent, _extends({}, props, {
  to: {
    pathname: to,
    search: queryParams
  }
}), children); // For connecting to the redux store


const mapStateToProps = (state, ownProps) => {
  return {
    queryParams: state.router.location.search
  };
}; // Enhance routing components, connect the result to redux,
// and export.


var _default = {
  LinkContainerWithQuery: (0, _reactRedux.connect)(mapStateToProps)(withQueryParams(_reactRouterBootstrap.LinkContainer)),
  LinkWithQuery: (0, _reactRedux.connect)(mapStateToProps)(withQueryParams(_reactRouterDom.Link)),
  RedirectWithQuery: (0, _reactRedux.connect)(mapStateToProps)(withQueryParams(_reactRouter.Redirect))
};
exports.default = _default;
module.exports = exports.default;

//# sourceMappingURL=connected-links.js