"use strict";

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

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

var _class, _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")), _amosReactRouter = require("amos-react-router"), _amosIcon = _interopRequireDefault(require("amos-icon")), _amosFramework = require("amos-framework"), _connectMenu = _interopRequireDefault(require("./connectMenu"));

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

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

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

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

var LevelMenu = (0, _connectMenu.default)(_class = function(e) {
  (0, _inherits2.default)(t, e);
  var r = _createSuper(t);
  function t() {
    var e;
    (0, _classCallCheck2.default)(this, t);
    for (var n = arguments.length, a = new Array(n), i = 0; i < n; i++) a[i] = arguments[i];
    return e = r.call.apply(r, [ this ].concat(a)), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(e), "renderItemLink", (function(r) {
      var t = e.props.iconPrefix, n = r.icon, a = (r.label, r.isBlank), i = r.path, u = r.permissionName, o = n && _react.default.createElement(_amosIcon.default, {
        icon: n,
        prefix: t,
        className: "menu-item-icon"
      });
      return a ? _react.default.createElement("a", {
        href: i,
        target: "_blank",
        rel: "noopener noreferrer",
        className: "menu-item-link"
      }, o, u) : _react.default.createElement(_amosReactRouter.Link, {
        to: i,
        className: "menu-item-link"
      }, o, u);
    })), e;
  }
  return (0, _createClass2.default)(t, [ {
    key: "render",
    value: function() {
      var e = this.props, r = e.className, t = e.onClick, n = e.nonChild, a = e.children;
      return _react.default.createElement("li", {
        className: r,
        onClick: t
      }, this.renderItemLink(this.props), !n && _react.default.createElement(_amosFramework.Icon, {
        icon: "right",
        className: "menu-subitem-icon"
      }), !n && a);
    }
  } ]), t;
}(_react.Component)) || _class;

exports.default = LevelMenu, LevelMenu.propTypes = {
  nonChild: _propTypes.default.bool,
  className: _propTypes.default.string,
  iconPrefix: _propTypes.default.string,
  onClick: _propTypes.default.func,
  children: _propTypes.default.node
};