import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _Menu from "antd/es/menu";
var _excluded = ["mode", "theme", "defaultOpenKeys", "defaultSelectedKeys", "forceSubMenuRender", "selectable", "inlineCollapsed", "inlineIndent", "triggerSubMenuAction", "subMenuCloseDelay", "subMenuOpenDelay", "style", "items", "multiple", "subMenuOpenKeys", "newItems", "controls", "onOpenChange", "openKeys", "selectedKeys"];
/* eslint-disable @typescript-eslint/no-shadow */
import * as React from 'react';
import { useState } from 'react';
import * as Icons from '@ant-design/icons/es/index';
// import Icon from '@ant-design/icons';

var SubMenu = _Menu.SubMenu;

// const item: MenuProps['items'] = [
//   {
//     label: 'Navigation One',
//     key: 'mail',
//     icon: <MailOutlined />,
//   },
//   {
//     label: 'Navigation Two',
//     key: 'app',
//     icon: <AppstoreOutlined />,
//     disabled: true,
//   },
//   {
//     label: 'Navigation Three - Submenu',
//     key: 'SubMenu',
//     icon: <SettingOutlined />,
//     children: [
//       {
//         type: 'group',
//         label: 'Item 1',
//         children: [
//           {
//             label: 'Option 1',
//             key: 'setting:1',
//           },
//           {
//             label: 'Option 2',
//             key: 'setting:2',
//           },
//         ],
//       },
//       {
//         type: 'group',
//         label: 'Item 2',
//         children: [
//           {
//             label: 'Option 3',
//             key: 'setting:3',
//           },
//           {
//             label: 'Option 4',
//             key: 'setting:4',
//           },
//         ],
//       },
//     ],
//   },
//   {
//     label: 'Submenu',
//     key: 'SubMenu11',
//     icon: <SettingOutlined />,
//     children: [
//       {
//         type: 'group',
//         label: 'Item',
//         children: [
//           {
//             label: 'Option22',
//             key: 'setting22',
//           },
//           {
//             label: 'Option22',
//             key: 'setting33',
//           },
//         ],
//       },
//     ],
//   },
// ];

var antSubMenuCopy = function antSubMenuCopy(_ref) {
  var mode = _ref.mode,
    theme = _ref.theme,
    defaultOpenKeys = _ref.defaultOpenKeys,
    defaultSelectedKeys = _ref.defaultSelectedKeys,
    forceSubMenuRender = _ref.forceSubMenuRender,
    selectable = _ref.selectable,
    inlineCollapsed = _ref.inlineCollapsed,
    inlineIndent = _ref.inlineIndent,
    triggerSubMenuAction = _ref.triggerSubMenuAction,
    subMenuCloseDelay = _ref.subMenuCloseDelay,
    subMenuOpenDelay = _ref.subMenuOpenDelay,
    style = _ref.style,
    items = _ref.items,
    multiple = _ref.multiple,
    subMenuOpenKeys = _ref.subMenuOpenKeys,
    newItems = _ref.newItems,
    controls = _ref.controls,
    onOpenChange = _ref.onOpenChange,
    openKeys = _ref.openKeys,
    selectedKeys = _ref.selectedKeys,
    otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
  var defalutprops = _extends({
    mode: mode,
    theme: theme,
    defaultSelectedKeys: defaultSelectedKeys,
    defaultOpenKeys: defaultOpenKeys,
    forceSubMenuRender: forceSubMenuRender,
    // selectable,
    inlineCollapsed: inlineCollapsed,
    inlineIndent: inlineIndent,
    triggerSubMenuAction: triggerSubMenuAction,
    multiple: multiple,
    style: style
  }, otherProps);

  // 是否受控
  if (controls) {
    defalutprops.openKeys = openKeys;
    defalutprops.selectedKeys = selectedKeys;
  }
  console.log(defalutprops, 'defalutprops');
  var Subdefalutprops = _extends({
    mode: mode,
    theme: theme,
    defaultSelectedKeys: defaultSelectedKeys,
    defaultOpenKeys: defaultOpenKeys,
    forceSubMenuRender: forceSubMenuRender,
    inlineCollapsed: inlineCollapsed,
    inlineIndent: inlineIndent,
    triggerSubMenuAction: triggerSubMenuAction,
    multiple: multiple,
    style: style
  }, otherProps);
  var rootSubmenuKeys = [];
  var _useState = useState(['SubMenu']),
    openKey = _useState[0],
    setOpenKeys = _useState[1];

  // 只展示父级 处理数据
  if (subMenuOpenKeys && (newItems === null || newItems === void 0 ? void 0 : newItems.length) >= 0) {
    for (var i = 0; i < (newItems === null || newItems === void 0 ? void 0 : newItems.length); i++) {
      rootSubmenuKeys.push(newItems[i].key);
    }
    console.log(rootSubmenuKeys);
  }

  // SubMenu 展开/关闭的回调
  var onOpenChanges = function onOpenChanges(keys) {
    var latestOpenKey = keys.find(function (key) {
      return openKey.indexOf(key) === -1;
    });
    if (rootSubmenuKeys.indexOf(latestOpenKey) === -1) {
      setOpenKeys(keys);
    } else {
      setOpenKeys(latestOpenKey ? [latestOpenKey] : []);
    }
  };

  // 封装menu 递归处理
  var menuTag = function deep(menuData) {
    if (menuData && menuData.length > 0) {
      return menuData.map(function (item) {
        if (item.children && item.children.length > 0) {
          return /*#__PURE__*/React.createElement(SubMenu, {
            key: item.key,
            icon: item.icon ? /*#__PURE__*/React.createElement(Iconfont, {
              icon: item.icon
            }) : '',
            title: item.label
          }, deep(item.children));
        }
        return /*#__PURE__*/React.createElement(_Menu.Item, {
          key: item.key,
          icon: item.icon ? /*#__PURE__*/React.createElement(Iconfont, {
            icon: item.icon
          }) : ''
        }, item.label);
      });
    }
  };
  if (onOpenChange || controls) {
    Subdefalutprops.onOpenChange = onOpenChange;
    Subdefalutprops.openKeys = openKeys;
  } else {
    Subdefalutprops.onOpenChange = onOpenChanges;
    Subdefalutprops.openKeys = openKey;
  }

  // 处理Icon图标
  var Iconfont = function Iconfont(props) {
    var icon = props.icon;
    var antIcon = Icons;
    return /*#__PURE__*/React.createElement(antIcon[icon]);
  };
  return subMenuOpenKeys ? /*#__PURE__*/React.createElement(_Menu, Subdefalutprops, menuTag(newItems)) : /*#__PURE__*/React.createElement(_Menu, defalutprops, menuTag(items))
  // <Iconfont icon="AppstoreOutlined" />
  ;
};

antSubMenuCopy.displayName = 'antSubMenuCopy';
export default antSubMenuCopy;