import "core-js/modules/es.array.iterator.js";
import "core-js/modules/web.dom-collections.iterator.js";
import React from 'react';
import { DownOutlined } from '@wii/icons';
import classNames from 'classnames';
import useMergedState from 'rc-util/es/hooks/useMergedState';
import Dropdown from '../dropdown';
import Space from '../space';
import Tabs from '../tabs';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
const HeaderMenu = props => {
  const {
    items = [],
    type = 'inline',
    prefixCls,
    activeKey: propActiveKey
  } = props;
  const [activeKey, setActiveKey] = useMergedState(propActiveKey, {
    value: propActiveKey,
    onChange: props.onChange
  });
  if (items.length < 1) {
    return null;
  }
  const activeItem = items.find(item => {
    var _item$key;
    return ((_item$key = item.key) === null || _item$key === void 0 ? void 0 : _item$key.toString()) === (activeKey === null || activeKey === void 0 ? void 0 : activeKey.toString());
  }) || items[0];
  if (type === 'inline') {
    return /*#__PURE__*/_jsx("div", {
      className: classNames(`${prefixCls}-menu`, `${prefixCls}-inline-menu`),
      children: items.map(item => /*#__PURE__*/_jsx("div", {
        onClick: () => {
          setActiveKey(item.key);
        },
        className: classNames(`${prefixCls}-inline-menu-item`, activeItem.key === item.key ? `${prefixCls}-inline-menu-item-active` : undefined),
        children: item.label
      }, item.key))
    });
  }
  if (type === 'tab') {
    return /*#__PURE__*/_jsx(Tabs, {
      activeKey: activeItem.key.toString(),
      onTabClick: key => setActiveKey(key),
      items: items.map(item => ({
        ...item,
        key: item.key.toString()
      }))
    });
  }
  return /*#__PURE__*/_jsx("div", {
    className: classNames(`${prefixCls}-menu`, `${prefixCls}-dropdownmenu`),
    children: /*#__PURE__*/_jsx(Dropdown, {
      trigger: ['click'],
      menu: {
        items,
        onClick: item => {
          setActiveKey(item.key);
        },
        selectedKeys: [activeItem.key]
      },
      children: /*#__PURE__*/_jsxs(Space, {
        className: `${prefixCls}-dropdownmenu-label`,
        children: [activeItem.label, /*#__PURE__*/_jsx(DownOutlined, {})]
      })
    })
  });
};
export default HeaderMenu;