import * as a from "react";
import { useMergedRefs as h } from "../../../../../../../@base-ui_utils@0.2.4_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/utils/esm/useMergedRefs.js";
import { useContextMenuRootContext as y } from "../../context-menu/root/ContextMenuRootContext.js";
import { useButton as P } from "../../use-button/useButton.js";
import { mergeProps as v } from "../../merge-props/mergeProps.js";
import { itemPress as I } from "../../utils/reason-parts.js";
const A = {
  type: "regular-item"
};
function w(M) {
  const {
    closeOnClick: m,
    disabled: R = !1,
    highlighted: f,
    id: l,
    store: n,
    nativeButton: b,
    itemMetadata: o,
    nodeId: r
  } = M, i = a.useRef(null), t = y(!0), u = t !== void 0, {
    events: s
  } = n.useState("floatingTreeRoot"), {
    getButtonProps: p,
    buttonRef: x
  } = P({
    disabled: R,
    focusableWhenDisabled: !0,
    native: b
  }), g = a.useCallback((C) => v({
    id: l,
    role: "menuitem",
    tabIndex: f ? 0 : -1,
    onMouseMove(e) {
      r && s.emit("itemhover", {
        nodeId: r,
        target: e.currentTarget
      });
    },
    onMouseEnter() {
      o.type === "submenu-trigger" && o.setActive();
    },
    onKeyUp(e) {
      e.key === " " && n.context.typingRef.current && e.preventBaseUIHandler();
    },
    onClick(e) {
      m && s.emit("close", {
        domEvent: e,
        reason: I
      });
    },
    onMouseUp(e) {
      if (t) {
        const c = t.initialCursorPointRef.current;
        if (t.initialCursorPointRef.current = null, u && c && Math.abs(e.clientX - c.x) <= 1 && Math.abs(e.clientY - c.y) <= 1)
          return;
      }
      i.current && n.context.allowMouseUpTriggerRef.current && (!u || e.button === 2) && o.type === "regular-item" && i.current.click();
    }
  }, C, p), [l, f, p, m, s, n, u, t, o, r]), d = h(i, x);
  return a.useMemo(() => ({
    getItemProps: g,
    itemRef: d
  }), [g, d]);
}
export {
  A as REGULAR_ITEM,
  w as useMenuItem
};
