import * as a from "react";
import { c as w, u as M, a as ie } from "./index-tyLV0iiH.mjs";
import { u as T } from "./index-DLcqcWxM.mjs";
import { c as G, u as ue } from "./index-DOfn3ixy.mjs";
import { P as F } from "./index-CCNZ9uWB.mjs";
import { c as de } from "./index-MiRhI3nq.mjs";
import { u as le } from "./index-CEQ35j8b.mjs";
import { u as K } from "./index-ByaXH_ih.mjs";
import { jsx as u, jsxs as fe } from "react/jsx-runtime";
import { u as pe } from "./index-DPxjTK4w.mjs";
import { P as me } from "./index-C1AXAWlO.mjs";
var A = "rovingFocusGroup.onEntryFocus", ve = { bubbles: !1, cancelable: !0 }, y = "RovingFocusGroup", [k, L, Re] = de(y), [be, U] = G(
  y,
  [Re]
), [Ie, ge] = be(y), B = a.forwardRef(
  (e, r) => /* @__PURE__ */ u(k.Provider, { scope: e.__scopeRovingFocusGroup, children: /* @__PURE__ */ u(k.Slot, { scope: e.__scopeRovingFocusGroup, children: /* @__PURE__ */ u(he, { ...e, ref: r }) }) })
);
B.displayName = y;
var he = a.forwardRef((e, r) => {
  const {
    __scopeRovingFocusGroup: o,
    orientation: t,
    loop: s = !1,
    dir: i,
    currentTabStopId: d,
    defaultCurrentTabStopId: R,
    onCurrentTabStopIdChange: l,
    onEntryFocus: c,
    preventScrollOnEntryFocus: I = !1,
    ...f
  } = e, p = a.useRef(null), v = T(r, p), n = K(i), [m = null, g] = M({
    prop: d,
    defaultProp: R,
    onChange: l
  }), [h, C] = a.useState(!1), S = ue(c), te = L(o), _ = a.useRef(!1), [re, x] = a.useState(0);
  return a.useEffect(() => {
    const b = p.current;
    if (b)
      return b.addEventListener(A, S), () => b.removeEventListener(A, S);
  }, [S]), /* @__PURE__ */ u(
    Ie,
    {
      scope: o,
      orientation: t,
      dir: n,
      loop: s,
      currentTabStopId: m,
      onItemFocus: a.useCallback(
        (b) => g(b),
        [g]
      ),
      onItemShiftTab: a.useCallback(() => C(!0), []),
      onFocusableItemAdd: a.useCallback(
        () => x((b) => b + 1),
        []
      ),
      onFocusableItemRemove: a.useCallback(
        () => x((b) => b - 1),
        []
      ),
      children: /* @__PURE__ */ u(
        F.div,
        {
          tabIndex: h || re === 0 ? -1 : 0,
          "data-orientation": t,
          ...f,
          ref: v,
          style: { outline: "none", ...e.style },
          onMouseDown: w(e.onMouseDown, () => {
            _.current = !0;
          }),
          onFocus: w(e.onFocus, (b) => {
            const ne = !_.current;
            if (b.target === b.currentTarget && ne && !h) {
              const O = new CustomEvent(A, ve);
              if (b.currentTarget.dispatchEvent(O), !O.defaultPrevented) {
                const P = te().filter((E) => E.focusable), ae = P.find((E) => E.active), se = P.find((E) => E.id === m), ce = [ae, se, ...P].filter(
                  Boolean
                ).map((E) => E.ref.current);
                Y(ce, I);
              }
            }
            _.current = !1;
          }),
          onBlur: w(e.onBlur, () => C(!1))
        }
      )
    }
  );
}), V = "RovingFocusGroupItem", q = a.forwardRef(
  (e, r) => {
    const {
      __scopeRovingFocusGroup: o,
      focusable: t = !0,
      active: s = !1,
      tabStopId: i,
      ...d
    } = e, R = le(), l = i || R, c = ge(V, o), I = c.currentTabStopId === l, f = L(o), { onFocusableItemAdd: p, onFocusableItemRemove: v } = c;
    return a.useEffect(() => {
      if (t)
        return p(), () => v();
    }, [t, p, v]), /* @__PURE__ */ u(
      k.ItemSlot,
      {
        scope: o,
        id: l,
        focusable: t,
        active: s,
        children: /* @__PURE__ */ u(
          F.span,
          {
            tabIndex: I ? 0 : -1,
            "data-orientation": c.orientation,
            ...d,
            ref: r,
            onMouseDown: w(e.onMouseDown, (n) => {
              t ? c.onItemFocus(l) : n.preventDefault();
            }),
            onFocus: w(e.onFocus, () => c.onItemFocus(l)),
            onKeyDown: w(e.onKeyDown, (n) => {
              if (n.key === "Tab" && n.shiftKey) {
                c.onItemShiftTab();
                return;
              }
              if (n.target !== n.currentTarget) return;
              const m = Ee(n, c.orientation, c.dir);
              if (m !== void 0) {
                if (n.metaKey || n.ctrlKey || n.altKey || n.shiftKey) return;
                n.preventDefault();
                let h = f().filter((C) => C.focusable).map((C) => C.ref.current);
                if (m === "last") h.reverse();
                else if (m === "prev" || m === "next") {
                  m === "prev" && h.reverse();
                  const C = h.indexOf(n.currentTarget);
                  h = c.loop ? Fe(h, C + 1) : h.slice(C + 1);
                }
                setTimeout(() => Y(h));
              }
            })
          }
        )
      }
    );
  }
);
q.displayName = V;
var Ce = {
  ArrowLeft: "prev",
  ArrowUp: "prev",
  ArrowRight: "next",
  ArrowDown: "next",
  PageUp: "first",
  Home: "first",
  PageDown: "last",
  End: "last"
};
function we(e, r) {
  return r !== "rtl" ? e : e === "ArrowLeft" ? "ArrowRight" : e === "ArrowRight" ? "ArrowLeft" : e;
}
function Ee(e, r, o) {
  const t = we(e.key, o);
  if (!(r === "vertical" && ["ArrowLeft", "ArrowRight"].includes(t)) && !(r === "horizontal" && ["ArrowUp", "ArrowDown"].includes(t)))
    return Ce[t];
}
function Y(e, r = !1) {
  const o = document.activeElement;
  for (const t of e)
    if (t === o || (t.focus({ preventScroll: r }), document.activeElement !== o)) return;
}
function Fe(e, r) {
  return e.map((o, t) => e[(r + t) % e.length]);
}
var ye = B, Se = q, D = "Radio", [_e, j] = G(D), [Pe, Ae] = _e(D), z = a.forwardRef(
  (e, r) => {
    const {
      __scopeRadio: o,
      name: t,
      checked: s = !1,
      required: i,
      disabled: d,
      value: R = "on",
      onCheck: l,
      form: c,
      ...I
    } = e, [f, p] = a.useState(null), v = T(r, (g) => p(g)), n = a.useRef(!1), m = f ? c || !!f.closest("form") : !0;
    return /* @__PURE__ */ fe(Pe, { scope: o, checked: s, disabled: d, children: [
      /* @__PURE__ */ u(
        F.button,
        {
          type: "button",
          role: "radio",
          "aria-checked": s,
          "data-state": X(s),
          "data-disabled": d ? "" : void 0,
          disabled: d,
          value: R,
          ...I,
          ref: v,
          onClick: w(e.onClick, (g) => {
            s || l?.(), m && (n.current = g.isPropagationStopped(), n.current || g.stopPropagation());
          })
        }
      ),
      m && /* @__PURE__ */ u(
        ke,
        {
          control: f,
          bubbles: !n.current,
          name: t,
          value: R,
          checked: s,
          required: i,
          disabled: d,
          form: c,
          style: { transform: "translateX(-100%)" }
        }
      )
    ] });
  }
);
z.displayName = D;
var H = "RadioIndicator", W = a.forwardRef(
  (e, r) => {
    const { __scopeRadio: o, forceMount: t, ...s } = e, i = Ae(H, o);
    return /* @__PURE__ */ u(me, { present: t || i.checked, children: /* @__PURE__ */ u(
      F.span,
      {
        "data-state": X(i.checked),
        "data-disabled": i.disabled ? "" : void 0,
        ...s,
        ref: r
      }
    ) });
  }
);
W.displayName = H;
var ke = (e) => {
  const { control: r, checked: o, bubbles: t = !0, ...s } = e, i = a.useRef(null), d = ie(o), R = pe(r);
  return a.useEffect(() => {
    const l = i.current, c = window.HTMLInputElement.prototype, f = Object.getOwnPropertyDescriptor(c, "checked").set;
    if (d !== o && f) {
      const p = new Event("click", { bubbles: t });
      f.call(l, o), l.dispatchEvent(p);
    }
  }, [d, o, t]), /* @__PURE__ */ u(
    "input",
    {
      type: "radio",
      "aria-hidden": !0,
      defaultChecked: o,
      ...s,
      tabIndex: -1,
      ref: i,
      style: {
        ...e.style,
        ...R,
        position: "absolute",
        pointerEvents: "none",
        opacity: 0,
        margin: 0
      }
    }
  );
};
function X(e) {
  return e ? "checked" : "unchecked";
}
var Te = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"], N = "RadioGroup", [Ge] = G(N, [
  U,
  j
]), $ = U(), J = j(), [De, Ne] = Ge(N), Q = a.forwardRef(
  (e, r) => {
    const {
      __scopeRadioGroup: o,
      name: t,
      defaultValue: s,
      value: i,
      required: d = !1,
      disabled: R = !1,
      orientation: l,
      dir: c,
      loop: I = !0,
      onValueChange: f,
      ...p
    } = e, v = $(o), n = K(c), [m, g] = M({
      prop: i,
      defaultProp: s,
      onChange: f
    });
    return /* @__PURE__ */ u(
      De,
      {
        scope: o,
        name: t,
        required: d,
        disabled: R,
        value: m,
        onValueChange: g,
        children: /* @__PURE__ */ u(
          ye,
          {
            asChild: !0,
            ...v,
            orientation: l,
            dir: n,
            loop: I,
            children: /* @__PURE__ */ u(
              F.div,
              {
                role: "radiogroup",
                "aria-required": d,
                "aria-orientation": l,
                "data-disabled": R ? "" : void 0,
                dir: n,
                ...p,
                ref: r
              }
            )
          }
        )
      }
    );
  }
);
Q.displayName = N;
var Z = "RadioGroupItem", ee = a.forwardRef(
  (e, r) => {
    const { __scopeRadioGroup: o, disabled: t, ...s } = e, i = Ne(Z, o), d = i.disabled || t, R = $(o), l = J(o), c = a.useRef(null), I = T(r, c), f = i.value === s.value, p = a.useRef(!1);
    return a.useEffect(() => {
      const v = (m) => {
        Te.includes(m.key) && (p.current = !0);
      }, n = () => p.current = !1;
      return document.addEventListener("keydown", v), document.addEventListener("keyup", n), () => {
        document.removeEventListener("keydown", v), document.removeEventListener("keyup", n);
      };
    }, []), /* @__PURE__ */ u(
      Se,
      {
        asChild: !0,
        ...R,
        focusable: !d,
        active: f,
        children: /* @__PURE__ */ u(
          z,
          {
            disabled: d,
            required: i.required,
            checked: f,
            ...l,
            ...s,
            name: i.name,
            ref: I,
            onCheck: () => i.onValueChange(s.value),
            onKeyDown: w((v) => {
              v.key === "Enter" && v.preventDefault();
            }),
            onFocus: w(s.onFocus, () => {
              p.current && c.current?.click();
            })
          }
        )
      }
    );
  }
);
ee.displayName = Z;
var xe = "RadioGroupIndicator", oe = a.forwardRef(
  (e, r) => {
    const { __scopeRadioGroup: o, ...t } = e, s = J(o);
    return /* @__PURE__ */ u(W, { ...s, ...t, ref: r });
  }
);
oe.displayName = xe;
var He = Q, We = ee, Xe = oe;
export {
  We as I,
  He as R,
  Xe as a
};
//# sourceMappingURL=index-DSf4qCR-.mjs.map
