import { cx } from '@linaria/core';
import Tooltip from '../Tooltip/index.js';
import { Menu, Dropdown } from 'antd';
import React__default from 'react';

const DropdownOverlayStyle = "E_4100_0_7_d133fzv0";
const RenderMenuItem = item => {
  if (item.hidden === true) {
    return /* @__PURE__ */React__default.createElement(React__default.Fragment, null);
  }
  if (item.type === "group") {
    return /* @__PURE__ */React__default.createElement(Menu.ItemGroup, {
      title: item.title,
      key: item.key
    }, (item.children || []).map(childItem => RenderMenuItem(childItem)));
  }
  if (item.type === "divider") {
    return /* @__PURE__ */React__default.createElement(Menu.Divider, {
      key: item.key
    });
  }
  if (item.tooltip) {
    return /* @__PURE__ */React__default.createElement(Menu.Item, {
      danger: item.danger,
      key: item.key,
      disabled: item.disabled,
      onClick: item.onClick,
      "data-testid": item["data-testid"]
    }, /* @__PURE__ */React__default.createElement(Tooltip, {
      title: item.tooltip
    }, item.icon ? React__default.cloneElement(item.icon, {}, item.text) : /* @__PURE__ */React__default.createElement("div", null, item.text)));
  }
  return /* @__PURE__ */React__default.createElement(Menu.Item, {
    danger: item.danger,
    key: item.key,
    disabled: item.disabled,
    onClick: item.onClick,
    "data-testid": item["data-testid"]
  }, item.icon ? React__default.cloneElement(item.icon, {}, item.text) : item.text);
};
const DropdownMenu = ({
  items,
  disabled,
  placement,
  trigger,
  customStyle,
  slotsElements = {},
  "data-testid": dataTestId
}) => {
  const menuItems = items.filter(item => !item.hidden);
  const menuDisabled = disabled || menuItems.length === 0;
  return /* @__PURE__ */React__default.createElement(Dropdown, {
    disabled: menuDisabled,
    placement,
    trigger,
    overlayClassName: cx(DropdownOverlayStyle, customStyle == null ? void 0 : customStyle.content),
    overlay: /* @__PURE__ */React__default.createElement(Menu, null, menuItems.map(item => {
      return RenderMenuItem(item);
    }))
  }, /* @__PURE__ */React__default.createElement("span", {
    "data-testid": dataTestId
  }, slotsElements.trigger ? slotsElements.trigger({}) : null));
};
var DropdownMenu$1 = DropdownMenu;

export { RenderMenuItem, DropdownMenu$1 as default };
