import * as n from "react";
import { composeEventHandlers as I } from "../../../../../@radix-ui_primitive@1.1.2/node_modules/@radix-ui/primitive/dist/index.js";
import { useComposedRefs as E } from "../../../../../@radix-ui_react-compose-refs@1.1.2_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-compose-refs/dist/index.js";
import { createContextScope as w } from "../../../../../@radix-ui_react-context@1.1.2_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-context/dist/index.js";
import { Primitive as C } from "../../../../../@radix-ui_react-primitive@2.1.3_@types_react-dom@19.1.6_@types_react@19.1.6__@types_rea_ec571b14c8dc7e1c1fa1383d9a1e10bd/node_modules/@radix-ui/react-primitive/dist/index.js";
import { createRovingFocusGroupScope as P, Root as B, Item as q } from "../../../../../@radix-ui_react-roving-focus@1.1.10_@types_react-dom@19.1.6_@types_react@19.1.6__@types_2d3f19e691372edf0bc25a87278ce401/node_modules/@radix-ui/react-roving-focus/dist/index.js";
import { useControllableState as K } from "../../../../../@radix-ui_react-use-controllable-state@1.2.2_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-use-controllable-state/dist/index.js";
import { useDirection as T } from "../../../../../@radix-ui_react-direction@1.1.1_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-direction/dist/index.js";
import { useSize as U } from "../../../../../@radix-ui_react-use-size@1.1.1_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-use-size/dist/index.js";
import { usePrevious as V } from "../../../../../@radix-ui_react-use-previous@1.1.1_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-use-previous/dist/index.js";
import { Presence as j } from "../../../../../@radix-ui_react-presence@1.1.4_@types_react-dom@19.1.6_@types_react@19.1.6__@types_reac_14564cac32122309a7cc56096494b6e8/node_modules/@radix-ui/react-presence/dist/index.js";
import { jsx as u, jsxs as z } from "react/jsx-runtime";
var _ = "Radio", [H, k] = w(_), [W, X] = H(_), G = n.forwardRef(
  (t, d) => {
    const {
      __scopeRadio: o,
      name: i,
      checked: e = !1,
      required: r,
      disabled: a,
      value: l = "on",
      onCheck: f,
      form: m,
      ...R
    } = t, [p, v] = n.useState(null), s = E(d, (y) => v(y)), c = n.useRef(!1), h = p ? m || !!p.closest("form") : !0;
    return /* @__PURE__ */ z(W, { scope: o, checked: e, disabled: a, children: [
      /* @__PURE__ */ u(
        C.button,
        {
          type: "button",
          role: "radio",
          "aria-checked": e,
          "data-state": N(e),
          "data-disabled": a ? "" : void 0,
          disabled: a,
          value: l,
          ...R,
          ref: s,
          onClick: I(t.onClick, (y) => {
            e || f?.(), h && (c.current = y.isPropagationStopped(), c.current || y.stopPropagation());
          })
        }
      ),
      h && /* @__PURE__ */ u(
        A,
        {
          control: p,
          bubbles: !c.current,
          name: i,
          value: l,
          checked: e,
          required: r,
          disabled: a,
          form: m,
          style: { transform: "translateX(-100%)" }
        }
      )
    ] });
  }
);
G.displayName = _;
var S = "RadioIndicator", g = n.forwardRef(
  (t, d) => {
    const { __scopeRadio: o, forceMount: i, ...e } = t, r = X(S, o);
    return /* @__PURE__ */ u(j, { present: i || r.checked, children: /* @__PURE__ */ u(
      C.span,
      {
        "data-state": N(r.checked),
        "data-disabled": r.disabled ? "" : void 0,
        ...e,
        ref: d
      }
    ) });
  }
);
g.displayName = S;
var Y = "RadioBubbleInput", A = n.forwardRef(
  ({
    __scopeRadio: t,
    control: d,
    checked: o,
    bubbles: i = !0,
    ...e
  }, r) => {
    const a = n.useRef(null), l = E(a, r), f = V(o), m = U(d);
    return n.useEffect(() => {
      const R = a.current;
      if (!R) return;
      const p = window.HTMLInputElement.prototype, s = Object.getOwnPropertyDescriptor(
        p,
        "checked"
      ).set;
      if (f !== o && s) {
        const c = new Event("click", { bubbles: i });
        s.call(R, o), R.dispatchEvent(c);
      }
    }, [f, o, i]), /* @__PURE__ */ u(
      C.input,
      {
        type: "radio",
        "aria-hidden": !0,
        defaultChecked: o,
        ...e,
        tabIndex: -1,
        ref: l,
        style: {
          ...e.style,
          ...m,
          position: "absolute",
          pointerEvents: "none",
          opacity: 0,
          margin: 0
        }
      }
    );
  }
);
A.displayName = Y;
function N(t) {
  return t ? "checked" : "unchecked";
}
var J = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"], b = "RadioGroup", [Q, le] = w(b, [
  P,
  k
]), x = P(), D = k(), [Z, $] = Q(b), M = n.forwardRef(
  (t, d) => {
    const {
      __scopeRadioGroup: o,
      name: i,
      defaultValue: e,
      value: r,
      required: a = !1,
      disabled: l = !1,
      orientation: f,
      dir: m,
      loop: R = !0,
      onValueChange: p,
      ...v
    } = t, s = x(o), c = T(m), [h, y] = K({
      prop: r,
      defaultProp: e ?? null,
      onChange: p,
      caller: b
    });
    return /* @__PURE__ */ u(
      Z,
      {
        scope: o,
        name: i,
        required: a,
        disabled: l,
        value: h,
        onValueChange: y,
        children: /* @__PURE__ */ u(
          B,
          {
            asChild: !0,
            ...s,
            orientation: f,
            dir: c,
            loop: R,
            children: /* @__PURE__ */ u(
              C.div,
              {
                role: "radiogroup",
                "aria-required": a,
                "aria-orientation": f,
                "data-disabled": l ? "" : void 0,
                dir: c,
                ...v,
                ref: d
              }
            )
          }
        )
      }
    );
  }
);
M.displayName = b;
var O = "RadioGroupItem", F = n.forwardRef(
  (t, d) => {
    const { __scopeRadioGroup: o, disabled: i, ...e } = t, r = $(O, o), a = r.disabled || i, l = x(o), f = D(o), m = n.useRef(null), R = E(d, m), p = r.value === e.value, v = n.useRef(!1);
    return n.useEffect(() => {
      const s = (h) => {
        J.includes(h.key) && (v.current = !0);
      }, c = () => v.current = !1;
      return document.addEventListener("keydown", s), document.addEventListener("keyup", c), () => {
        document.removeEventListener("keydown", s), document.removeEventListener("keyup", c);
      };
    }, []), /* @__PURE__ */ u(
      q,
      {
        asChild: !0,
        ...l,
        focusable: !a,
        active: p,
        children: /* @__PURE__ */ u(
          G,
          {
            disabled: a,
            required: r.required,
            checked: p,
            ...f,
            ...e,
            name: r.name,
            ref: R,
            onCheck: () => r.onValueChange(e.value),
            onKeyDown: I((s) => {
              s.key === "Enter" && s.preventDefault();
            }),
            onFocus: I(e.onFocus, () => {
              v.current && m.current?.click();
            })
          }
        )
      }
    );
  }
);
F.displayName = O;
var ee = "RadioGroupIndicator", L = n.forwardRef(
  (t, d) => {
    const { __scopeRadioGroup: o, ...i } = t, e = D(o);
    return /* @__PURE__ */ u(g, { ...e, ...i, ref: d });
  }
);
L.displayName = ee;
var fe = M, me = F, Re = L;
export {
  Re as Indicator,
  me as Item,
  M as RadioGroup,
  L as RadioGroupIndicator,
  F as RadioGroupItem,
  fe as Root,
  le as createRadioGroupScope
};
//# sourceMappingURL=index.js.map
