"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _layout = _interopRequireDefault(require("antd/lib/layout"));
var _menu = _interopRequireDefault(require("antd/lib/menu"));
var React = _interopRequireWildcard(require("react"));
var Icons = _interopRequireWildcard(require("@ant-design/icons/es/index"));
var _excluded = ["mode", "theme", "defaultOpenKeys", "defaultSelectedKeys", "forceSubMenuRender", "selectable", "inlineCollapsed", "inlineIndent", "triggerSubMenuAction", "subMenuCloseDelay", "subMenuOpenDelay", "style", "items", "multiple", "subMenuOpenKeys", "newItems", "controls", "onOpenChange", "openKeys", "selectedKeys", "contents"];
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; }
var SubMenu = _menu["default"].SubMenu;
var Header = _layout["default"].Header,
  Content = _layout["default"].Content,
  Footer = _layout["default"].Footer,
  Sider = _layout["default"].Sider;

// 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 antMenuDouble = function antMenuDouble(_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,
    contents = _ref.contents,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var defalutprops = (0, _extends2["default"])({
    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;
  }
  var Subdefalutprops = (0, _extends2["default"])({
    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 = (0, React.useState)(['SubMenu']),
    openKey = _useState[0],
    setOpenKeys = _useState[1];
  var _useState2 = (0, React.useState)(),
    current = _useState2[0],
    setCurrent = _useState2[1];
  var a = {
    1: contents,
    2: contents
  };

  // 只展示父级 处理数据
  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["default"].Item, {
          key: item.key,
          icon: item.icon ? /*#__PURE__*/React.createElement(Iconfont, {
            icon: item.icon
          }) : ''
        }, item.label);
      });
    }
  };
  // 递归处理Content
  var getTableKey = function getTableKey(data) {
    var parentKey = [];
    data.forEach(function (item) {
      if (!item.children) {
        parentKey.push(item.key);
      }
      if (item.children && item.children.length) {
        if (item.children) {
          var temp = getTableKey(item.children);
          if (temp && temp.length) {
            parentKey.push.apply(parentKey, temp);
          }
        }
      }
    });
    return parentKey;
  };

  // const arrKey = getTableKey(items);
  var arrKey = ['mail', 'app', '1', '2', '3', '4', '5', '6', '7', '8'];
  console.log(arrKey, '----------arr---------------');
  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]);
  };

  // 点击切换页面
  var onSelect = function onSelect(e) {
    setCurrent(e.key);
    var div = document.querySelectorAll('.demo');
    var sy = arrKey.indexOf(e.key);
    // var lis = document.getElementById(e.key);
    for (var _i = 0; _i < div.length; _i++) {
      div[_i].style.visibility = 'hidden';
    }
    div[sy].style.visibility = 'visible';
    console.log(document.querySelectorAll('.demo'), '----------');

    // div 添加子节点
    // div.appendChild(btn);
  };

  console.log(contents, 1111111111111111222222222222);
  var dom = arrKey.map(function (item, index) {
    return /*#__PURE__*/React.createElement(Content, {
      id: item,
      key: index
    }, contents, index);
  });
  return (
    /*#__PURE__*/
    // subMenuOpenKeys ? <Menu
    //   // {...extendsProps}
    //   // onOpenChange={onOpenChanges}
    //   // openKeys={openKey}
    //   {...Subdefalutprops}
    // >
    //   {menuTag(newItems)}
    // </Menu> :
    //   <Menu
    //     {...defalutprops}
    //   >
    //     {menuTag(items)}
    //   </Menu>
    React.createElement(_layout["default"], {
      className: "site-layout-background"
    }, /*#__PURE__*/React.createElement(Sider, {
      className: "site-layout-background",
      width: 240
    }, subMenuOpenKeys ? /*#__PURE__*/React.createElement(_menu["default"], Subdefalutprops, menuTag(newItems)) : /*#__PURE__*/React.createElement(_menu["default"], (0, _extends2["default"])({}, defalutprops, {
      onSelect: onSelect
    }), menuTag(items))), arrKey.map(function (item, index) {
      // return <Content className='demo' style={{ visibility: 'visible' }}>{
      //   a[item] ? a[item] : null
      // }</Content>
      if (item === current) {
        //   return <Slotsetter></Slotsetter>
        // return <Content id={item} >{item}</Content>
        return dom[index];
      }
    }))
  );
};
antMenuDouble.displayName = 'antMenuDouble';
var _default = antMenuDouble;
exports["default"] = _default;