"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _menu = _interopRequireDefault(require("antd/lib/menu"));
var React = _interopRequireWildcard(require("react"));
var _index = require("@ant-design/icons/es/index");
var _antMenuItem = _interopRequireDefault(require("../ant-menu-item"));
var _antSubmenu = _interopRequireDefault(require("../ant-submenu"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/* eslint-disable @typescript-eslint/no-shadow */

var SubMenu = _menu["default"].SubMenu;
var items = [{
  label: 'Navigation Three - Submenu',
  key: 'SubMenu',
  icon: /*#__PURE__*/React.createElement(_index.SettingOutlined, null),
  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: /*#__PURE__*/React.createElement(_index.SettingOutlined, null),
  children: [{
    type: 'group',
    label: 'Item',
    children: [{
      label: 'Option22',
      key: 'setting22'
    }, {
      label: 'Option22',
      key: 'setting33'
    }]
  }]
}];
var antMenu = function antMenu(_ref) {
  var mode = _ref.mode,
    theme = _ref.theme,
    style = _ref.style,
    Icon = _ref.Icon;
  console.log(Icon);

  // 没有子集
  var MenuItem = function MenuItem() {
    var items = [{
      label: '菜单项一',
      key: 'item-1',
      icon: /*#__PURE__*/React.createElement(_index.MailOutlined, null)
    },
    // 菜单项务必填写 key
    {
      label: '菜单项二',
      key: 'item-2',
      icon: /*#__PURE__*/React.createElement(_index.AppstoreOutlined, null)
    }];
    return items.map(function (item, index) {
      // return <Menu.Item key={item.key} icon={item.icon}>
      //   {item.label}
      // </Menu.Item>
      return /*#__PURE__*/React.createElement(_menu["default"].Item, {
        key: item.key,
        icon: Icon
      }, item.label);
    });
  };

  // 有子集
  var MenuSubMenu = function MenuSubMenu() {
    var items = [{
      label: '子菜单',
      key: 'submenu',
      icon: /*#__PURE__*/React.createElement(_index.SettingOutlined, null),
      children: [{
        label: '子菜单项',
        key: 'submenu-item-1',
        children: [{
          label: '子菜单',
          key: 'submenu',
          icon: /*#__PURE__*/React.createElement(_index.SettingOutlined, null),
          children: [{
            label: '子菜单项',
            key: 'submenu-item-1'
          }]
        }]
      }]
    }];
    return items.map(function (item, index) {
      return /*#__PURE__*/React.createElement(_menu["default"].SubMenu, {
        key: item.key,
        title: item.label,
        icon: Icon
      }, item.children.map(function (item, index) {
        return /*#__PURE__*/React.createElement(_menu["default"].Item, {
          key: item.key,
          icon: Icon
        }, item.label);
      }));
    });
  };
  var rootSubmenuKeys = ['SubMenu11', 'SubMenu'];
  var _useState = (0, React.useState)(['sub1']),
    openKeys = _useState[0],
    setOpenKeys = _useState[1];
  var onOpenChange = function onOpenChange(keys) {
    var latestOpenKey = keys.find(function (key) {
      return openKeys.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,
            title: item.label
          }, deep(item.children));
        }
        return /*#__PURE__*/React.createElement(_menu["default"].Item, {
          key: item.key,
          icon: item.icon
        }, item.label);
      });
    }
  };
  return /*#__PURE__*/React.createElement(_menu["default"], {
    mode: mode,
    defaultSelectedKeys: ['mail'],
    theme: theme,
    style: style
  }, /*#__PURE__*/React.createElement(_antMenuItem["default"], null), /*#__PURE__*/React.createElement(_antSubmenu["default"], null))

  //     <Menu {...defalutprops} style={mode !== 'horizontal' ? { width: 256 , height:'100%'} :style} >
  //     {
  //    items.map((item,index)=>{
  //      return   (item.children && item.children.length > 0) ?
  //      <Menu.SubMenu key={item.key} title={item.label} icon={item.icon} >
  //      {item.children?.map((item, index) => {
  //        return (
  //          <Menu.Item key={item.key} icon={item.icon}>
  //            {item.label}
  //          </Menu.Item>
  //        )
  //      })}
  //    </Menu.SubMenu> : <Menu.Item key={item.key} icon={item.icon}>{item.label}</Menu.Item>
  //    })
  //  }
  //  </Menu>
  // <Menu
  //   mode="inline"
  //   openKeys={openKeys}
  //   onOpenChange={onOpenChange}
  //   style={{ width: 256 }}
  // >
  //    {menuTag(items)}
  // </Menu>
  ;
};

antMenu.displayName = 'antMenu';
var _default = antMenu;
exports["default"] = _default;