"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"), _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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 _createSuper(e) {
    var t = _isNativeReflectConstruct();
    return function() {
        var r, i = (0, _getPrototypeOf2.default)(e);
        if (t) {
            var n = (0, _getPrototypeOf2.default)(this).constructor;
            r = Reflect.construct(i, arguments, n);
        } else r = i.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, r;
    return r = t = function(t) {
        (0, _inherits2.default)(i, t);
        var r = _createSuper(i);
        function i() {
            var e;
            (0, _classCallCheck2.default)(this, i);
            for (var t = arguments.length, n = new Array(t), u = 0; u < t; u++) n[u] = arguments[u];
            return e = r.call.apply(r, [ this ].concat(n)), (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)(i, [ {
            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);
            }
        } ]), i;
    }(_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
    }), r;
}