"use client";
import { t as e } from "./error-CAd3pM3X.js";
import { n as t, t as n } from "./useIsoLayoutEffect-CKOv1bV_.js";
import { n as r, r as i, u as a } from "./useRenderElement-CmuWsiNa.js";
import { t as o } from "./useStableCallback-CqEVb76s.js";
import { f as s } from "./floating-ui.utils.dom-5U5b4xPf.js";
import * as c from "react";
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/internals/composite/root/CompositeRootContext.js
var l = /*#__PURE__*/ c.createContext(void 0);
process.env.NODE_ENV !== "production" && (l.displayName = "CompositeRootContext");
function u(e = !1) {
	let t = c.useContext(l);
	if (t === void 0 && !e) throw Error(process.env.NODE_ENV === "production" ? a(16) : "Base UI: CompositeRootContext is missing. Composite parts must be placed within <Composite.Root>.");
	return t;
}
//#endregion
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/utils/useFocusableWhenDisabled.js
function d(e) {
	let { focusableWhenDisabled: t, disabled: n, composite: r = !1, tabIndex: i = 0, isNativeButton: a } = e, o = r && t !== !1, s = r && t === !1;
	return { props: c.useMemo(() => {
		let e = { onKeyDown(e) {
			n && t && e.key !== "Tab" && e.preventDefault();
		} };
		return r || (e.tabIndex = i, !a && n && (e.tabIndex = t ? i : -1)), (a && (t || o) || !a && n) && (e["aria-disabled"] = n), a && (!t || s) && (e.disabled = n), e;
	}, [
		r,
		n,
		t,
		o,
		s,
		a,
		i
	]) };
}
//#endregion
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/internals/use-button/useButton.js
function f(a = {}) {
	let { disabled: s = !1, focusableWhenDisabled: l, tabIndex: f = 0, native: h = !0, composite: g } = a, _ = c.useRef(null), v = u(!0), y = g ?? v !== void 0, { props: b } = d({
		focusableWhenDisabled: l,
		disabled: s,
		composite: y,
		tabIndex: f,
		isNativeButton: h
	});
	process.env.NODE_ENV !== "production" && c.useEffect(() => {
		if (!_.current) return;
		let n = p(_.current);
		h ? n || e(`A component that acts as a button expected a native <button> because the \`nativeButton\` prop is true. Rendering a non-<button> removes native button semantics, which can impact forms and accessibility. Use a real <button> in the \`render\` prop, or set \`nativeButton\` to \`false\`.${t.captureOwnerStack?.() || ""}`) : n && e(`A component that acts as a button expected a non-<button> because the \`nativeButton\` prop is false. Rendering a <button> keeps native behavior while Base UI applies non-native attributes and handlers, which can add unintended extra attributes (such as \`role\` or \`aria-disabled\`). Use a non-<button> in the \`render\` prop, or set \`nativeButton\` to \`true\`.${t.captureOwnerStack?.() || ""}`);
	}, [h]);
	let x = c.useCallback(() => {
		let e = _.current;
		p(e) && y && s && b.disabled === void 0 && e.disabled && (e.disabled = !1);
	}, [
		s,
		b.disabled,
		y
	]);
	return n(x, [x]), {
		getButtonProps: c.useCallback((e = {}) => {
			let { onClick: t, onMouseDown: n, onKeyUp: a, onKeyDown: o, onPointerDown: c, ...l } = e;
			return i({
				onClick(e) {
					if (s) {
						e.preventDefault();
						return;
					}
					t?.(e);
				},
				onMouseDown(e) {
					s || n?.(e);
				},
				onKeyDown(e) {
					if (s || (r(e), o?.(e), e.baseUIHandlerPrevented)) return;
					let n = e.target === e.currentTarget, i = e.currentTarget, a = p(i), c = !h && m(i), l = n && (h ? a : !c), u = e.key === "Enter", d = e.key === " ", f = i.getAttribute("role"), g = f?.startsWith("menuitem") || f === "option" || f === "gridcell";
					if (n && y && d) {
						if (e.defaultPrevented && g) return;
						e.preventDefault(), c || h && a ? (i.click(), e.preventBaseUIHandler()) : l && (t?.(e), e.preventBaseUIHandler());
						return;
					}
					l && (!h && (d || u) && e.preventDefault(), !h && u && t?.(e));
				},
				onKeyUp(e) {
					if (!s) {
						if (r(e), a?.(e), e.target === e.currentTarget && h && y && p(e.currentTarget) && e.key === " ") {
							e.preventDefault();
							return;
						}
						e.baseUIHandlerPrevented || e.target === e.currentTarget && !h && !y && e.key === " " && t?.(e);
					}
				},
				onPointerDown(e) {
					if (s) {
						e.preventDefault();
						return;
					}
					c?.(e);
				}
			}, h ? { type: "button" } : { role: "button" }, b, l);
		}, [
			s,
			b,
			y,
			h
		]),
		buttonRef: o((e) => {
			_.current = e, x();
		})
	};
}
function p(e) {
	return s(e) && e.tagName === "BUTTON";
}
function m(e) {
	return !!(e?.tagName === "A" && e?.href);
}
//#endregion
export { l as n, u as r, f as t };
