import _Button from "antd/es/button";
import _Menu from "antd/es/menu";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["menus", "onSelMenu", "title", "theme"];
import "./index.css";
import { useState } from 'react';
import { MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons';
import defaultProps from "./_defaultProps";

// 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 = _objectWithoutPropertiesLoose(props, _excluded);
  console.log('menus=====', menus);
  var _useState = 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.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.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, {
    type: "primary",
    onClick: toggleCollapsed
  }, collapsed ? /*#__PURE__*/React.createElement(MenuUnfoldOutlined, null) : /*#__PURE__*/React.createElement(MenuFoldOutlined, null)), /*#__PURE__*/React.createElement(_Menu, {
    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)));
};
export default FoldMenuComponent;