"use client";
import { a as e, l as t, o as n, t as r } from "./useRenderElement-CmuWsiNa.js";
import { t as i } from "./useStableCallback-CqEVb76s.js";
import { t as a } from "./CompositeList-DJUJLDbx.js";
import { t as o } from "./DirectionContext-B4CbbM--.js";
import { t as s } from "./isElementDisabled-Cibvw8mz.js";
import { n as c } from "./useButton-AXffhTAZ.js";
import { r as l } from "./shadowDom-C-4Ejp9R.js";
import { a as u, i as d, l as f, n as p, o as m, r as h, s as g, t as _, u as v } from "./composite-HOje5ugx.js";
import { _ as y, a as b, c as x, g as S, h as C, i as w, l as T, m as E, n as D, o as O, r as k, t as A, u as j } from "./composite-BlDfbDkL.js";
import * as M from "react";
import { jsx as N } from "react/jsx-runtime";
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/internals/composite/constants.js
var P = "data-composite-item-active", F = [];
function I(e) {
	let { itemSizes: n, cols: r = 1, loopFocus: a = !0, onLoop: o, dense: c = !1, orientation: j = "both", direction: N, highlightedIndex: P, onHighlightedIndexChange: I, rootRef: R, enableHomeAndEndKeys: z = !1, stopEventPropagation: B = !1, disabledIndices: V, modifierKeys: H = F } = e, [U, W] = M.useState(0), G = r > 1, K = M.useRef(null), q = t(K, R), J = M.useRef([]), Y = M.useRef(!1), X = P ?? U, Z = i((e, t = !1) => {
		if ((I ?? W)(e), t) {
			let t = J.current[e];
			y(K.current, t, N, j);
		}
	}), Q = i((e) => {
		if (e.size === 0 || Y.current) return;
		Y.current = !0;
		let t = Array.from(e.keys()), n = t.find((e) => e?.hasAttribute("data-composite-item-active")) ?? null, r = n ? t.indexOf(n) : -1;
		r !== -1 && Z(r), y(K.current, n, N, j);
	}), ee = i((e, t, n) => o ? o?.(e, t, n, J) : n), $ = M.useMemo(() => ({
		"aria-orientation": j === "both" ? void 0 : j,
		ref: q,
		onFocus(e) {
			let t = K.current, n = l(e.nativeEvent);
			!t || n == null || !S(n) || n.setSelectionRange(0, n.value.length ?? 0);
		},
		onKeyDown(e) {
			let t = z ? O : D;
			if (!t.has(e.key) || L(e, H) || !K.current) return;
			let i = N === "rtl", y = i ? k : w, M = {
				horizontal: y,
				vertical: A,
				both: y
			}[j], P = i ? w : k, F = {
				horizontal: P,
				vertical: b,
				both: P
			}[j], I = l(e.nativeEvent);
			if (I != null && S(I) && !s(I)) {
				let t = I.selectionStart, n = I.selectionEnd, r = I.value ?? "";
				if (t == null || e.shiftKey || t !== n || e.key !== F && t < r.length || e.key !== M && t > 0) return;
			}
			let R = X, U = g(J, V), W = m(J, V);
			if (G) {
				let t = n || Array.from({ length: J.current.length }, () => ({
					width: 1,
					height: 1
				})), o = _(t, r, c), s = o.findIndex((e) => e != null && !v(J.current, e, V)), l = o.reduce((e, t, n) => t != null && !v(J.current, t, V) ? n : e, -1);
				R = o[u(o.map((e) => e == null ? null : J.current[e]), {
					event: e,
					orientation: j,
					loopFocus: a,
					onLoop: ee,
					cols: r,
					disabledIndices: d([...V || J.current.map((e, t) => v(J.current, t) ? t : void 0), void 0], o),
					minIndex: s,
					maxIndex: l,
					prevIndex: h(X > W ? U : X, t, o, r, e.key === "ArrowDown" ? "bl" : e.key === "ArrowRight" ? "tr" : "tl"),
					rtl: i
				})];
			}
			let q = {
				horizontal: [y],
				vertical: [A],
				both: [y, A]
			}[j], Y = {
				horizontal: [P],
				vertical: [b],
				both: [P, b]
			}[j], Q = G ? t : {
				horizontal: z ? T : x,
				vertical: z ? C : E,
				both: t
			}[j];
			z && (e.key === "Home" ? R = U : e.key === "End" && (R = W)), R === X && (q.includes(e.key) || Y.includes(e.key)) && (a && R === W && q.includes(e.key) ? (R = U, o && (R = o(e, X, R, J))) : a && R === U && Y.includes(e.key) ? (R = W, o && (R = o(e, X, R, J))) : R = p(J.current, {
				startingIndex: R,
				decrement: Y.includes(e.key),
				disabledIndices: V
			})), R !== X && !f(J.current, R) && (B && e.stopPropagation(), Q.has(e.key) && e.preventDefault(), Z(R, !0), queueMicrotask(() => {
				J.current[R]?.focus();
			}));
		}
	}), [
		r,
		c,
		N,
		V,
		J,
		z,
		X,
		G,
		n,
		a,
		o,
		ee,
		q,
		H,
		Z,
		j,
		B
	]);
	return M.useMemo(() => ({
		props: $,
		highlightedIndex: X,
		onHighlightedIndexChange: Z,
		elementsRef: J,
		disabledIndices: V,
		onMapChange: Q,
		relayKeyboardEvent: $.onKeyDown
	}), [
		$,
		X,
		Z,
		J,
		V,
		Q
	]);
}
function L(e, t) {
	for (let n of j.values()) if (!t.includes(n) && e.getModifierState(n)) return !0;
	return !1;
}
//#endregion
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/internals/composite/root/CompositeRoot.js
function R(t) {
	let { render: i, className: s, style: l, refs: u = e, props: d = e, state: f = n, stateAttributesMapping: p, highlightedIndex: m, onHighlightedIndexChange: h, orientation: g, dense: _, itemSizes: v, loopFocus: y, onLoop: b, cols: x, enableHomeAndEndKeys: S, onMapChange: C, stopEventPropagation: w = !0, rootRef: T, disabledIndices: E, modifierKeys: D, highlightItemOnHover: O = !1, tag: k = "div", ...A } = t, { props: j, highlightedIndex: P, onHighlightedIndexChange: F, elementsRef: L, onMapChange: R, relayKeyboardEvent: z } = I({
		itemSizes: v,
		cols: x,
		loopFocus: y,
		onLoop: b,
		dense: _,
		orientation: g,
		highlightedIndex: m,
		onHighlightedIndexChange: h,
		rootRef: T,
		stopEventPropagation: w,
		enableHomeAndEndKeys: S,
		direction: o(),
		disabledIndices: E,
		modifierKeys: D
	}), B = r(k, t, {
		state: f,
		ref: u,
		props: [
			j,
			...d,
			A
		],
		stateAttributesMapping: p
	}), V = M.useMemo(() => ({
		highlightedIndex: P,
		onHighlightedIndexChange: F,
		highlightItemOnHover: O,
		relayKeyboardEvent: z
	}), [
		P,
		F,
		O,
		z
	]);
	return /*#__PURE__*/ N(c.Provider, {
		value: V,
		children: /*#__PURE__*/ N(a, {
			elementsRef: L,
			onMapChange: (e) => {
				C?.(e), R(e);
			},
			children: B
		})
	});
}
//#endregion
export { P as n, R as t };
