import { j as jsxRuntimeExports } from "./jsx-runtime-mMz73N64.js";
import { B as Button, I as Icon, C as CONTEXT_SELECTED, q as CONTEXT_TARGET, r as ContextMenu, s as useContextMenu } from "./Toggle-DcOiWiHG.js";
import { L as Link } from "./Link-BaPpY2rf.js";
import { C as CSS } from "./css-DoalWJF6.js";
import { createContext, useContext } from "react";
const MenuContext = createContext({
  onClick: () => {
  },
  selected: ""
});
const useMenuContext = () => useContext(MenuContext);
const Menu = ({
  children,
  onChange,
  level,
  iconSpacing,
  value = ""
}) => {
  const handleClick = (key) => onChange == null ? void 0 : onChange(key);
  return /* @__PURE__ */ 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__ */ jsxRuntimeExports.jsx(
        Base,
        {
          level,
          ...rest,
          onClick: handleClick,
          variant: "text",
          className: CSS(CSS.B("menu-item"), CSS.selected(_selected), className),
          size: size ?? iconSpacing
        }
      )
    );
  }
);
const CoreItem = menuItemFactory(Button, { noWrap: true });
const ItemIcon = menuItemFactory(Icon);
const ItemLink = menuItemFactory(Link, { noWrap: true });
const Item = CoreItem;
Item.Icon = ItemIcon;
Item.Link = ItemLink;
const external = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  CONTEXT_SELECTED,
  CONTEXT_TARGET,
  ContextMenu,
  CoreItem,
  Item,
  Menu,
  MenuContext,
  useContextMenu,
  useMenuContext
}, Symbol.toStringTag, { value: "Module" }));
export {
  external as e
};
//# sourceMappingURL=external-Bn7V_LTL.js.map
