"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 _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")), _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")), _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")), _MenuItem = _interopRequireDefault(require("./MenuItem"));

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

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, u = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var n = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(u, arguments, n);
    } else r = u.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;
  }
}

var MenuList = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var u;
    return (0, _classCallCheck2.default)(this, r), u = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(u), "onSubMenuClick", (function(e, t) {
      u.setState({
        activeKey: e,
        activeSubKey: t
      }), u.props.onMenuClosed();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(u), "setMenuActive", (function(e) {
      u.state.activeKey !== e && u.setState({
        activeKey: e
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(u), "setSubMenuActive", (function(e) {
      u.state.activeSubKey !== e && u.setState({
        activeSubKey: e
      });
    })), u.state = {
      activeKey: "",
      activeSubKey: ""
    }, u;
  }
  return (0, _createClass2.default)(r, [ {
    key: "render",
    value: function() {
      var e = this, t = this.state, r = t.activeKey, u = t.activeSubKey, n = this.props, i = n.height, a = n.navs, s = n.onMenuOpen, o = n.onMenuClosed, l = n.toggleSubMenu, p = n.renderSubmenu, c = n.menuWidth, f = n.iconPrefix, d = i > 0 ? "nav-menu-box menu-expanded" : "nav-menu-box";
      return _react.default.createElement("div", {
        className: "nav-menu-wrapper"
      }, _react.default.createElement("div", {
        className: d
      }, _react.default.createElement("div", {
        className: "nav-menu-bg",
        style: {
          height: i
        },
        onMouseOver: this.onMouseOver,
        onMouseOut: this.onMouseOut
      }), _react.default.createElement("ul", {
        className: "nav-menu-list",
        onMouseOver: s,
        onMouseOut: o
      }, (a || []).map((function(t) {
        var n = t.sequenceNbr, a = (0, _objectWithoutProperties2.default)(t, [ "sequenceNbr" ]);
        return _react.default.createElement(_MenuItem.default, (0, _extends2.default)({
          key: n
        }, a, {
          iconPrefix: f,
          menuKey: n,
          height: i,
          activeKey: r,
          activeSubKey: u,
          setMenuActive: e.setMenuActive,
          setSubMenuActive: e.setSubMenuActive,
          onSubMenuClick: e.onSubMenuClick,
          onMenuClosed: o,
          toggleSubMenu: l,
          renderSubmenu: p,
          menuWidth: c
        }));
      })))));
    }
  } ]), r;
}(_react.PureComponent);

MenuList.displayName = "MenuList", MenuList.propTypes = {
  height: _propTypes.default.number,
  navs: _propTypes.default.arrayOf(_propTypes.default.shape({
    sequenceNbr: _propTypes.default.string.isRequired,
    permissionName: _propTypes.default.string.isRequired,
    icon: _propTypes.default.string,
    path: _propTypes.default.string,
    children: _propTypes.default.array
  })),
  toggleSubMenu: _propTypes.default.func,
  onMenuOpen: _propTypes.default.func,
  onMenuClosed: _propTypes.default.func,
  renderSubmenu: _propTypes.default.func,
  menuWidth: _propTypes.default.oneOfType([ _propTypes.default.string, _propTypes.default.number ])
};

var _default = MenuList;

exports.default = _default;