import { a as e, r as t, t as n } from "./dist-DCjaNViz.js";
import { o as r, t as i } from "./dist-D-6_qntS.js";
import { t as a } from "./dist-DjSP8Xx2.js";
import { t as o } from "./dist-BN9-Ksur.js";
import { t as s } from "./dist-o21Z8vCD.js";
import { t as c } from "./dist-C-DOdUAW.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] = a(p), [_, v] = e(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((e, a) => {
	let { __scopeRovingFocusGroup: o, orientation: m, loop: g = !1, dir: _, currentTabStopId: v, defaultCurrentTabStopId: b, onCurrentTabStopIdChange: x, onEntryFocus: S, preventScrollOnEntryFocus: C = !1, ...w } = e, T = l.useRef(null), E = r(a, T), D = s(_), [k, A] = n({
		prop: v,
		defaultProp: b ?? null,
		onChange: x,
		caller: p
	}), [j, M] = l.useState(!1), N = c(S), P = h(o), 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: o,
		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(i.div, {
			tabIndex: j || I === 0 ? -1 : 0,
			"data-orientation": m,
			...w,
			ref: E,
			style: {
				outline: "none",
				...e.style
			},
			onMouseDown: t(e.onMouseDown, () => {
				F.current = !0;
			}),
			onFocus: t(e.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: t(e.onBlur, () => M(!1))
		})
	});
}), C = "RovingFocusGroupItem", w = l.forwardRef((e, n) => {
	let { __scopeRovingFocusGroup: r, focusable: a = !0, active: s = !1, tabStopId: c, children: d, ...f } = e, p = o(), g = c || p, _ = b(C, r), v = _.currentTabStopId === g, y = h(r), { onFocusableItemAdd: x, onFocusableItemRemove: S, currentTabStopId: w } = _;
	return l.useEffect(() => {
		if (a) return x(), () => S();
	}, [
		a,
		x,
		S
	]), /* @__PURE__ */ u(m.ItemSlot, {
		scope: r,
		id: g,
		focusable: a,
		active: s,
		children: /* @__PURE__ */ u(i.span, {
			tabIndex: v ? 0 : -1,
			"data-orientation": _.orientation,
			...f,
			ref: n,
			onMouseDown: t(e.onMouseDown, (e) => {
				a ? _.onItemFocus(g) : e.preventDefault();
			}),
			onFocus: t(e.onFocus, () => _.onItemFocus(g)),
			onKeyDown: t(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-DmFwV39u.js.map