import { n as e } from "./dist-CTlQcJNK.js";
import { a as t, o as n, t as r } from "./dist-koa_pEtu.js";
import { t as i } from "./dist-CpMqmV-i.js";
import { t as a } from "./dist-C0wG5dwG.js";
import { t as o } from "./dist-RmXz0NYF.js";
import { t as s } from "./dist-cMlzVrN6.js";
import { t as c } from "./dist-CVCn7F_m.js";
import * as l from "react";
import { jsx as u } from "react/jsx-runtime";
//#region node_modules/@radix-ui/react-roving-focus/dist/index.mjs
var d = "rovingFocusGroup.onEntryFocus", f = {
	bubbles: !1,
	cancelable: !0
}, p = "RovingFocusGroup", [m, h, g] = s(p), [_, v] = t(p, [g]), [y, b] = _(p), x = l.forwardRef((e, t) => /* @__PURE__ */ u(m.Provider, {
	scope: e.__scopeRovingFocusGroup,
	children: /* @__PURE__ */ u(m.Slot, {
		scope: e.__scopeRovingFocusGroup,
		children: /* @__PURE__ */ u(S, {
			...e,
			ref: t
		})
	})
}));
x.displayName = p;
var S = l.forwardRef((t, i) => {
	let { __scopeRovingFocusGroup: s, orientation: m, loop: g = !1, dir: _, currentTabStopId: v, defaultCurrentTabStopId: b, onCurrentTabStopIdChange: x, onEntryFocus: S, preventScrollOnEntryFocus: C = !1, ...w } = t, T = l.useRef(null), E = e(i, T), D = c(_), [k, A] = a({
		prop: v,
		defaultProp: b ?? null,
		onChange: x,
		caller: p
	}), [j, M] = l.useState(!1), N = o(S), P = h(s), F = l.useRef(!1), [I, L] = l.useState(0);
	return l.useEffect(() => {
		let e = T.current;
		if (e) return e.addEventListener(d, N), () => e.removeEventListener(d, N);
	}, [N]), /* @__PURE__ */ u(y, {
		scope: s,
		orientation: m,
		dir: D,
		loop: g,
		currentTabStopId: k,
		onItemFocus: l.useCallback((e) => A(e), [A]),
		onItemShiftTab: l.useCallback(() => M(!0), []),
		onFocusableItemAdd: l.useCallback(() => L((e) => e + 1), []),
		onFocusableItemRemove: l.useCallback(() => L((e) => e - 1), []),
		children: /* @__PURE__ */ u(r.div, {
			tabIndex: j || I === 0 ? -1 : 0,
			"data-orientation": m,
			...w,
			ref: E,
			style: {
				outline: "none",
				...t.style
			},
			onMouseDown: n(t.onMouseDown, () => {
				F.current = !0;
			}),
			onFocus: n(t.onFocus, (e) => {
				let t = !F.current;
				if (e.target === e.currentTarget && t && !j) {
					let t = new CustomEvent(d, f);
					if (e.currentTarget.dispatchEvent(t), !t.defaultPrevented) {
						let e = P().filter((e) => e.focusable);
						O([
							e.find((e) => e.active),
							e.find((e) => e.id === k),
							...e
						].filter(Boolean).map((e) => e.ref.current), C);
					}
				}
				F.current = !1;
			}),
			onBlur: n(t.onBlur, () => M(!1))
		})
	});
}), C = "RovingFocusGroupItem", w = l.forwardRef((e, t) => {
	let { __scopeRovingFocusGroup: a, focusable: o = !0, active: s = !1, tabStopId: c, children: d, ...f } = e, p = i(), g = c || p, _ = b(C, a), v = _.currentTabStopId === g, y = h(a), { onFocusableItemAdd: x, onFocusableItemRemove: S, currentTabStopId: w } = _;
	return l.useEffect(() => {
		if (o) return x(), () => S();
	}, [
		o,
		x,
		S
	]), /* @__PURE__ */ u(m.ItemSlot, {
		scope: a,
		id: g,
		focusable: o,
		active: s,
		children: /* @__PURE__ */ u(r.span, {
			tabIndex: v ? 0 : -1,
			"data-orientation": _.orientation,
			...f,
			ref: t,
			onMouseDown: n(e.onMouseDown, (e) => {
				o ? _.onItemFocus(g) : e.preventDefault();
			}),
			onFocus: n(e.onFocus, () => _.onItemFocus(g)),
			onKeyDown: n(e.onKeyDown, (e) => {
				if (e.key === "Tab" && e.shiftKey) {
					_.onItemShiftTab();
					return;
				}
				if (e.target !== e.currentTarget) return;
				let t = D(e, _.orientation, _.dir);
				if (t !== void 0) {
					if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return;
					e.preventDefault();
					let n = y().filter((e) => e.focusable).map((e) => e.ref.current);
					if (t === "last") n.reverse();
					else if (t === "prev" || t === "next") {
						t === "prev" && n.reverse();
						let r = n.indexOf(e.currentTarget);
						n = _.loop ? k(n, r + 1) : n.slice(r + 1);
					}
					setTimeout(() => O(n));
				}
			}),
			children: typeof d == "function" ? d({
				isCurrentTabStop: v,
				hasTabStop: w != null
			}) : d
		})
	});
});
w.displayName = C;
var T = {
	ArrowLeft: "prev",
	ArrowUp: "prev",
	ArrowRight: "next",
	ArrowDown: "next",
	PageUp: "first",
	Home: "first",
	PageDown: "last",
	End: "last"
};
function E(e, t) {
	return t === "rtl" ? e === "ArrowLeft" ? "ArrowRight" : e === "ArrowRight" ? "ArrowLeft" : e : e;
}
function D(e, t, n) {
	let r = E(e.key, n);
	if (!(t === "vertical" && ["ArrowLeft", "ArrowRight"].includes(r)) && !(t === "horizontal" && ["ArrowUp", "ArrowDown"].includes(r))) return T[r];
}
function O(e, t = !1) {
	let n = document.activeElement;
	for (let r of e) if (r === n || (r.focus({ preventScroll: t }), document.activeElement !== n)) return;
}
function k(e, t) {
	return e.map((n, r) => e[(t + r) % e.length]);
}
var A = x, j = w;
//#endregion
export { A as n, v as r, j as t };

//# sourceMappingURL=dist-B1veE5DO.js.map