'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var core = require('@linaria/core');
var index = require('../Tooltip/index.js');
var antd = require('antd');
var React = require('react');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

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

exports.RenderMenuItem = RenderMenuItem;
exports.default = DropdownMenu$1;
