"use strict";
const jsxRuntime = require("./jsx-runtime-B3vWrP5x.cjs");
const Toggle = require("./Toggle-CAW20E9V.cjs");
const Link = require("./Link-B6B7MB7O.cjs");
const css = require("./css-Pf9qxhQ4.cjs");
const React = require("react");
const MenuContext = React.createContext({
  onClick: () => {
  },
  selected: ""
});
const useMenuContext = () => React.useContext(MenuContext);
const Menu = ({
  children,
  onChange,
  level,
  iconSpacing,
  value = ""
}) => {
  const handleClick = (key) => onChange == null ? void 0 : onChange(key);
  return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
    MenuContext.Provider,
    {
      value: { onClick: handleClick, selected: value, level, iconSpacing },
      children
    }
  );
};
const menuItemFactory = (Base, defaultProps) => (
  // eslint-disable-next-line react/display-name
  (props) => {
    const { itemKey, className, onClick, size, ...rest } = {
      ...defaultProps,
      ...props
    };
    const { onClick: ctxOnClick, selected, level, iconSpacing } = useMenuContext();
    const handleClick = (e) => {
      ctxOnClick(itemKey);
      onClick == null ? void 0 : onClick(e);
    };
    const _selected = selected === itemKey;
    return (
      // @ts-expect-error
      /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
        Base,
        {
          level,
          ...rest,
          onClick: handleClick,
          variant: "text",
          className: css.CSS(css.CSS.B("menu-item"), css.CSS.selected(_selected), className),
          size: size ?? iconSpacing
        }
      )
    );
  }
);
const CoreItem = menuItemFactory(Toggle.Button, { noWrap: true });
const ItemIcon = menuItemFactory(Toggle.Icon);
const ItemLink = menuItemFactory(Link.Link, { noWrap: true });
const Item = CoreItem;
Item.Icon = ItemIcon;
Item.Link = ItemLink;
const external = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  CONTEXT_SELECTED: Toggle.CONTEXT_SELECTED,
  CONTEXT_TARGET: Toggle.CONTEXT_TARGET,
  ContextMenu: Toggle.ContextMenu,
  CoreItem,
  Item,
  Menu,
  MenuContext,
  useContextMenu: Toggle.useContextMenu,
  useMenuContext
}, Symbol.toStringTag, { value: "Module" }));
exports.external = external;
//# sourceMappingURL=external-axSECIuu.cjs.map
