import { t as e } from "../../utils-B7XIe3qq.js";
import * as t from "react";
import { jsx as n } from "react/jsx-runtime";
//#region src/react/primitives/context-menu.tsx
var r = t.createContext(null);
function i() {
	let e = t.useContext(r);
	if (!e) throw Error("ContextMenu compound components must be used within <ContextMenu>");
	return e;
}
function a({ children: e, onOpenChange: i }) {
	let [a, o] = t.useState(!1), [s, c] = t.useState({
		x: 0,
		y: 0
	}), l = t.useCallback((e) => {
		o(e), i?.(e);
	}, [i]), u = t.useMemo(() => ({
		open: a,
		position: s,
		setOpen: l,
		setPosition: c
	}), [
		a,
		s,
		l
	]);
	return /* @__PURE__ */ n(r.Provider, {
		value: u,
		children: e
	});
}
function o({ className: e, children: r, ...a }) {
	let o = i(), s = t.useCallback((e) => {
		e.preventDefault(), o.setPosition({
			x: e.clientX,
			y: e.clientY
		}), o.setOpen(!0);
	}, [o]);
	return /* @__PURE__ */ n("div", {
		"data-slot": "context-menu-trigger",
		className: e,
		onContextMenu: s,
		...a,
		children: r
	});
}
function s({ className: r, children: a, ...o }) {
	let s = i(), c = t.useRef(null);
	t.useEffect(() => {
		if (!s.open) return;
		let e = (e) => {
			c.current && !c.current.contains(e.target) && s.setOpen(!1);
		}, t = (e) => {
			e.key === "Escape" && s.setOpen(!1);
		};
		return document.addEventListener("click", e, !0), document.addEventListener("keydown", t), () => {
			document.removeEventListener("click", e, !0), document.removeEventListener("keydown", t);
		};
	}, [s, s.open]);
	let [l, u] = t.useState(s.position);
	return t.useEffect(() => {
		if (!s.open || !c.current) {
			u(s.position);
			return;
		}
		let e = c.current.getBoundingClientRect(), t = s.position.x, n = s.position.y;
		t + e.width > window.innerWidth && (t = window.innerWidth - e.width - 4), n + e.height > window.innerHeight && (n = window.innerHeight - e.height - 4), t < 0 && (t = 4), n < 0 && (n = 4), u({
			x: t,
			y: n
		});
	}, [s.open, s.position]), s.open ? /* @__PURE__ */ n("div", {
		ref: c,
		"data-slot": "context-menu-content",
		role: "menu",
		className: e("fixed z-50 min-w-[10rem] overflow-hidden rounded-xl border p-1 shadow-xl", "border-border-glass bg-popover backdrop-blur-xl", "animate-in fade-in-0 zoom-in-95", r),
		style: {
			left: l.x,
			top: l.y
		},
		...o,
		children: a
	}) : null;
}
function c({ className: r, disabled: a, onSelect: o, children: s, ...c }) {
	let l = i(), u = t.useCallback(() => {
		a !== !0 && (o?.(), l.setOpen(!1));
	}, [
		l,
		a,
		o
	]);
	return /* @__PURE__ */ n("div", {
		"data-slot": "context-menu-item",
		role: "menuitem",
		"aria-disabled": a === !0 ? !0 : void 0,
		className: e("relative flex cursor-pointer items-center rounded-lg px-3 py-2 text-sm transition-colors outline-none select-none", "text-foreground hover:bg-accent focus:bg-accent", a === !0 && "pointer-events-none opacity-50", r),
		onClick: u,
		...c,
		children: s
	});
}
function l({ className: t, ...r }) {
	return /* @__PURE__ */ n("div", {
		"data-slot": "context-menu-separator",
		role: "separator",
		className: e("bg-border-glass my-1 h-px", t),
		...r
	});
}
function u({ className: t, ...r }) {
	return /* @__PURE__ */ n("div", {
		"data-slot": "context-menu-label",
		className: e("text-foreground-muted px-3 py-1.5 text-xs font-semibold", t),
		...r
	});
}
function d({ className: t, ...r }) {
	return /* @__PURE__ */ n("span", {
		"data-slot": "context-menu-shortcut",
		className: e("text-foreground-muted ml-auto pl-4 text-xs tracking-widest", t),
		...r
	});
}
//#endregion
export { a as ContextMenu, s as ContextMenuContent, c as ContextMenuItem, u as ContextMenuLabel, l as ContextMenuSeparator, d as ContextMenuShortcut, o as ContextMenuTrigger };

//# sourceMappingURL=context-menu.js.map