"use strict";

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

var _lodash = require("lodash");

var _reactRouterRedux = require("react-router-redux");

var _url = _interopRequireDefault(require("url"));

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

var _default = patchLocation;
exports.default = _default;
const type = "PATCH_LOCATION";
exports.type = type;

function patchLocation(payload) {
  return (dispatch, getState) => {
    const state = getState();
    const location = state.routing.locationBeforeTransitions;

    if (payload.hasOwnProperty("pathname")) {
      payload.pathname = payload.pathname.indexOf(state.base) ? payload.pathname : `${prefix(state.base)}/${payload.pathname}`;
    }

    dispatch((0, _reactRouterRedux.push)((0, _lodash.merge)({}, location, payload)));
  };
}

patchLocation.type = type;

function prefix(base) {
  return base.charAt(base.length - 1) === "/" ? base.slice(0, base.length - 1) : base;
}
//# sourceMappingURL=patch-location.js.map