"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"), _typeof = require("@babel/runtime/helpers/typeof");

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

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")), _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")), _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")), _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")), _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), _react = _interopRequireWildcard(require("react")), _propTypes = _interopRequireDefault(require("prop-types"));

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : t;
  })(e);
}

function _interopRequireWildcard(e, t) {
  if (!t && e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var r = _getRequireWildcardCache(t);
  if (r && r.has(e)) return r.get(e);
  var n = {}, i = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) {
    var a = i ? Object.getOwnPropertyDescriptor(e, u) : null;
    a && (a.get || a.set) ? Object.defineProperty(n, u, a) : n[u] = e[u];
  }
  return n.default = e, r && r.set(e, n), n;
}

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, n = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var i = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(n, arguments, i);
    } else r = n.apply(this, arguments);
    return (0, _possibleConstructorReturn2.default)(this, r);
  };
}

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), 
    !0;
  } catch (e) {
    return !1;
  }
}

function connectMenu(e) {
  var t;
  return t = function(t) {
    (0, _inherits2.default)(n, t);
    var r = _createSuper(n);
    function n() {
      var e;
      (0, _classCallCheck2.default)(this, n);
      for (var t = arguments.length, i = new Array(t), u = 0; u < t; u++) i[u] = arguments[u];
      return e = r.call.apply(r, [ this ].concat(i)), (0, _defineProperty2.default)((0, 
      _assertThisInitialized2.default)(e), "refreshActive", (function(t) {
        var r = e.getHref(t);
        e.isActive(t, r) && t.setMenuActive && t.setMenuActive(t.menuKey);
      })), e;
    }
    return (0, _createClass2.default)(n, [ {
      key: "componentDidMount",
      value: function() {
        this.refreshActive(this.props);
      }
    }, {
      key: "getHref",
      value: function(e) {
        var t = e.url;
        if (e.isBlank) return t;
        if (!e.index && !t) return "";
        return (t = "".concat("/", "/").concat(t || "")).replace(/\/+/g, "/").replace(/(.+)\/$/, "$1");
      }
    }, {
      key: "isActive",
      value: function(e, t) {
        return e.index ? t === (location.pathname || "/") : t && new RegExp("".concat(t, "(?=/|$|\\?|#)")).test(location.href);
      }
    }, {
      key: "render",
      value: function() {
        return _react.default.createElement(e, this.props);
      }
    } ]), n;
  }(_react.Component), (0, _defineProperty2.default)(t, "propTypes", {
    url: _propTypes.default.string,
    index: _propTypes.default.bool,
    isBlank: _propTypes.default.bool,
    setMenuActive: _propTypes.default.func,
    menuKey: _propTypes.default.string
  }), t;
}