"use strict";
var import_Dropdown = require("../Dropdown.css");
const jsxRuntime = require("react/jsx-runtime");
const antd = require("antd");
const React = require("react");
const kit_Theme_UI = require("./Theme/UI.cjs");
require("./Theme/themeUtils.cjs");
require("./Theme/themes.cjs");
const css = {};
const Dropdown = ({
  children,
  content,
  disabled,
  isContextMenu,
  menu = [],
  open,
  autoWidthOverlay,
  placement = "bottomLeft",
  onClick,
  onOpenChange,
  selectable,
  selectedKeys
}) => {
  const {
    themeSettings: { className: themeClass }
  } = kit_Theme_UI.useTheme();
  const addFocusToMenu = React.useCallback((menuItem) => {
    if (menuItem === null)
      return null;
    if (menuItem.type === "divider") {
      return menuItem;
    } else if (menuItem.type === "group") {
      return { ...menuItem, children: menuItem.children.map(addFocusToMenu) };
    } else {
      return { ...menuItem, tabIndex: 0 };
    }
  }, []);
  const antdMenu = React.useMemo(() => {
    return {
      items: menu.map(addFocusToMenu),
      onClick: (info) => {
        info.domEvent.stopPropagation();
        onClick == null ? void 0 : onClick(info.key, info.domEvent);
      },
      selectable,
      selectedKeys
    };
  }, [addFocusToMenu, menu, onClick, selectable, selectedKeys]);
  const overlayStyle = autoWidthOverlay ? { minWidth: "auto" } : void 0;
  const className = [css.base, themeClass].join(" ");
  return content ? /* @__PURE__ */ jsxRuntime.jsx(
    antd.Popover,
    {
      className,
      content,
      open,
      overlayClassName: themeClass,
      overlayStyle,
      placement,
      showArrow: false,
      trigger: "click",
      onOpenChange,
      children
    }
  ) : /* @__PURE__ */ jsxRuntime.jsx(
    antd.Dropdown,
    {
      className,
      disabled,
      menu: antdMenu,
      open,
      overlayClassName: themeClass,
      overlayStyle,
      placement,
      trigger: [isContextMenu ? "contextMenu" : "click"],
      onOpenChange,
      children
    }
  );
};
module.exports = Dropdown;
