"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("core-js/modules/es.array.iterator.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _react = _interopRequireDefault(require("react"));
var _icons = require("@wii/icons");
var _classnames = _interopRequireDefault(require("classnames"));
var _useMergedState = _interopRequireDefault(require("rc-util/es/hooks/useMergedState"));
var _dropdown = _interopRequireDefault(require("../dropdown"));
var _menu = _interopRequireDefault(require("../menu"));
var _space = _interopRequireDefault(require("../space"));
var _tabs = _interopRequireDefault(require("../tabs"));
var _jsxRuntime = require("react/jsx-runtime");
const HeaderMenu = props => {
  const {
    items = [],
    type = 'inline',
    prefixCls,
    activeKey: propActiveKey
  } = props;
  const [activeKey, setActiveKey] = (0, _useMergedState.default)(propActiveKey, {
    value: propActiveKey,
    onChange: props.onChange
  });
  if (items.length < 1) {
    return null;
  }
  const activeItem = items.find(item => {
    return item.key === activeKey;
  }) || items[0];
  if (type === 'inline') {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: (0, _classnames.default)(`${prefixCls}-menu`, `${prefixCls}-inline-menu`),
      children: items.map(item => /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        onClick: () => {
          setActiveKey(item.key);
        },
        className: (0, _classnames.default)(`${prefixCls}-inline-menu-item`, activeItem.key === item.key ? `${prefixCls}-inline-menu-item-active` : undefined),
        children: item.label
      }, item.key))
    });
  }
  if (type === 'tab') {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_tabs.default, {
      activeKey: activeItem.key,
      onTabClick: key => setActiveKey(key),
      children: items.map(({
        label,
        key,
        ...rest
      }) => {
        return /*#__PURE__*/(0, _jsxRuntime.jsx)(_tabs.default.TabPane, {
          tab: label,
          ...rest
        }, key);
      })
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: (0, _classnames.default)(`${prefixCls}-menu`, `${prefixCls}-dropdownmenu`),
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdown.default, {
      trigger: ['click'],
      overlay: /*#__PURE__*/(0, _jsxRuntime.jsx)(_menu.default, {
        selectedKeys: [activeItem.key],
        onClick: item => {
          setActiveKey(item.key);
        },
        items: items
      }),
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_space.default, {
        className: `${prefixCls}-dropdownmenu-label`,
        children: [activeItem.label, /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.DownOutlined, {})]
      })
    })
  });
};
var _default = HeaderMenu;
exports.default = _default;