"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _button = _interopRequireDefault(require("antd/lib/button"));
var _menu = _interopRequireDefault(require("antd/lib/menu"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
require("./index.css");
var _react = require("react");
var _icons = require("@ant-design/icons");
var _defaultProps = _interopRequireDefault(require("./_defaultProps"));
var _excluded = ["menus", "onSelMenu", "title", "theme"];
// type MenuItem = Required<MenuProps>['items'][number];

;
var FoldMenuComponent = function FoldMenuComponent(props) {
  var _props$menus = props.menus,
    menus = _props$menus === void 0 ? [{
      key: '1',
      icon: /*#__PURE__*/React.createElement(PieChartOutlined, null),
      children: [{}],
      label: '选项1',
      type: 'group'
    }] : _props$menus,
    onSelMenu = props.onSelMenu,
    _props$title = props.title,
    title = _props$title === void 0 ? '标题' : _props$title,
    theme = props.theme,
    others = (0, _objectWithoutPropertiesLoose2["default"])(props, _excluded);
  console.log('menus=====', menus);
  var _useState = (0, _react.useState)(false),
    collapsed = _useState[0],
    setCollapsed = _useState[1];
  var toggleCollapsed = function toggleCollapsed() {
    setCollapsed(!collapsed);
  };
  var _callback = function _callback(menus) {
    if (!Array.isArray(menus)) return '';
    return menus.map(function (item) {
      var _item$children;
      if (item !== null && item !== void 0 && item.children && (item === null || item === void 0 ? void 0 : (_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) > 0) {
        return /*#__PURE__*/React.createElement(_menu["default"].SubMenu, {
          title: item === null || item === void 0 ? void 0 : item.label
        }, _callback(item === null || item === void 0 ? void 0 : item.children));
      } else {
        return /*#__PURE__*/React.createElement(_menu["default"].Item, {
          key: item === null || item === void 0 ? void 0 : item.key,
          icon: item === null || item === void 0 ? void 0 : item.icon
        }, item === null || item === void 0 ? void 0 : item.label);
      }
    });
  };
  var getItem = function getItem(label, key, icon, children, type) {
    return {
      key: key,
      icon: icon,
      children: children,
      label: label,
      type: type
    };
  };
  return /*#__PURE__*/React.createElement("div", {
    style: {
      height: 'auto'
    }
  }, /*#__PURE__*/React.createElement(_button["default"], {
    type: "primary",
    onClick: toggleCollapsed
  }, collapsed ? /*#__PURE__*/React.createElement(_icons.MenuUnfoldOutlined, null) : /*#__PURE__*/React.createElement(_icons.MenuFoldOutlined, null)), /*#__PURE__*/React.createElement(_menu["default"], {
    defaultSelectedKeys: (menus === null || menus === void 0 ? void 0 : menus.length) > 0 ? [menus[0].key] : [2, 3],
    defaultOpenKeys: (menus === null || menus === void 0 ? void 0 : menus.length) > 0 ? [menus[0].key] : [2, 3],
    onSelect: onSelMenu,
    theme: theme || 'light',
    inlineCollapsed: collapsed,
    mode: "inline"
  }, _callback((menus === null || menus === void 0 ? void 0 : menus.length) > 0 ? menus : _defaultProps["default"])));
};
var _default = FoldMenuComponent;
exports["default"] = _default;