"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, _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")), _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")), _amosTool = require("amos-tool"), _classnames = _interopRequireDefault(require("classnames")), _connectMenu = _interopRequireDefault(require("./connectMenu")), _LevelMenu = _interopRequireDefault(require("./LevelMenu"));

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 u = {}, n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var i in e) if ("default" !== i && Object.prototype.hasOwnProperty.call(e, i)) {
    var l = n ? Object.getOwnPropertyDescriptor(e, i) : null;
    l && (l.get || l.set) ? Object.defineProperty(u, i, l) : u[i] = e[i];
  }
  return u.default = e, t && t.set(e, u), u;
}

function _createSuper(e) {
  var r = _isNativeReflectConstruct();
  return function() {
    var t, u = (0, _getPrototypeOf2.default)(e);
    if (r) {
      var n = (0, _getPrototypeOf2.default)(this).constructor;
      t = Reflect.construct(u, arguments, n);
    } else t = u.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 calcHtmlSize = function(e, r) {
  if (!_amosTool.utils.isNil(e) && !_amosTool.utils.isNull(e)) {
    if (_amosTool.utils.isNumber(e)) return parseFloat(e) * r;
    if (_amosTool.utils.isString(e)) {
      var t = parseFloat(e), u = e.replace(t, "");
      return "".concat(t * r).concat(u);
    }
  }
  return 0;
}, SubMenuItem = (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 u = arguments.length, n = new Array(u), i = 0; i < u; i++) n[i] = arguments[i];
    return e = r.call.apply(r, [ this ].concat(n)), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(e), "genRecursiveStyle", (function(r) {
      var t = e.props.menuWidth;
      return {
        width: t,
        left: calcHtmlSize(t, r)
      };
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(e), "genRecursiveStyle2", (function() {
      var r = e.props.menuWidth;
      return {
        width: r,
        left: r
      };
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(e), "recursiveRender", (function(r) {
      var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 1, u = e.props, n = u.onSubMenuClick, i = u.rootMenuKey, l = u.iconPrefix, a = "recursive-level-menu content-level".concat(t), s = e.genRecursiveStyle2();
      return _react.default.createElement("ul", {
        className: a,
        style: s
      }, r.map((function(r) {
        var u = (0, _classnames.default)("menu-subitem", {}), a = _amosTool.utils.isEmpty(r.children), s = t;
        return a || (s += 1), _react.default.createElement(_LevelMenu.default, (0, _extends2.default)({}, r, {
          key: r.sequenceNbr,
          menuKey: r.sequenceNbr,
          className: u,
          iconPrefix: l,
          nonChild: a,
          onClick: function() {
            return n(i, r.sequenceNbr);
          }
        }), !a && e.recursiveRender(r.children, s));
      })));
    })), e;
  }
  return (0, _createClass2.default)(t, [ {
    key: "render",
    value: function() {
      var e = this.props, r = e.className, t = e.children, u = e.onClick, n = e.subItems;
      return _react.default.createElement("li", {
        className: r,
        onClick: u
      }, t, n && n.length > 0 && this.recursiveRender(n));
    }
  } ]), t;
}(_react.PureComponent)) || _class;

SubMenuItem.displayName = "SubMenuItem", SubMenuItem.propTypes = {
  className: _propTypes.default.string,
  iconPrefix: _propTypes.default.string,
  menuKey: _propTypes.default.string,
  rootMenuKey: _propTypes.default.string,
  onClick: _propTypes.default.func,
  onSubMenuClick: _propTypes.default.func,
  children: _propTypes.default.node,
  subItems: _propTypes.default.array,
  menuWidth: _propTypes.default.oneOfType([ _propTypes.default.string, _propTypes.default.number ])
};

var _default = SubMenuItem;

exports.default = _default;