import { jsx as C, jsxs as Q, Fragment as X } from "react/jsx-runtime";
import { $ as _, d as Y, f as Z, a as N, c as ee, b as ae, e as ie } from "./utils-B6pV5ewr.es.js";
import { $ as re } from "./FieldError-CXcEMuBf.es.js";
import { $ as oe } from "./Form-CXcEMuBf.es.js";
import { $ as te } from "./Label-DIseLESi.es.js";
import { a as de, $ as le } from "./SelectionIndicator-B27AsfqE.es.js";
import { $ as se } from "./Text-DOcU1ycg.es.js";
import { $ as y, a as ne } from "./mergeProps-Dsl8k3Ig.es.js";
import { $ as F } from "./filterDOMProps-BSVCO5jK.es.js";
import { $ as ce } from "./useObjectRef-CaJ5pgjX.es.js";
import R, { useMemo as M, useState as q, forwardRef as L, createContext as O } from "react";
import { $ as fe } from "./useFormReset-BGuIA_u2.es.js";
import { $ as w } from "./usePress-BuLomD_X.es.js";
import { $ as ue } from "./useFocusable-Cs6i58WP.es.js";
import { a as $e, $ as be } from "./useFormValidation-BCVLtR0U.es.js";
import { $ as pe } from "./utils-oAGBWzI5.es.js";
import { a as ve } from "./FocusScope-CqEZq7sr.es.js";
import { $ as me } from "./useFocusWithin-EFOG-Jn1.es.js";
import { $ as Pe } from "./useField-CHrpmkxe.es.js";
import { $ as he } from "./context-DW7UvQ8z.es.js";
import { $ as T } from "./useFocusRing-FPt2Rwil.es.js";
import { $ as xe } from "./useHover-BQRSM3qT.es.js";
import { $ as Re } from "./VisuallyHidden-BLRzeMsq.es.js";
import { $ as ye } from "./useControlledState-u436Wbp1.es.js";
import { RadioButtonChecked as Ie, RadioButtonUnchecked as Ve } from "@commercetools/nimbus-icons";
import { e as U } from "./extract-style-props-BdibuNZ7.es.js";
import { createSlotRecipeContext as ge } from "@chakra-ui/react";
import { useSlotRecipe as De } from "@chakra-ui/react/styled-system";
import { r as Se } from "./index-C2qW4ynb.es.js";
const W = /* @__PURE__ */ new WeakMap();
function Ce(a, e, r) {
  let { value: o, children: d, "aria-label": t, "aria-labelledby": c, onPressStart: i, onPressEnd: s, onPressChange: f, onPress: l, onPressUp: n, onClick: b } = a;
  const $ = a.isDisabled || e.isDisabled;
  let I = d != null, m = t != null || c != null;
  !I && !m && process.env.NODE_ENV !== "production" && console.warn("If you do not provide children, you must specify an aria-label for accessibility");
  let P = e.selectedValue === o, D = (g) => {
    g.stopPropagation(), e.setSelectedValue(o);
  }, { pressProps: S, isPressed: V } = w({
    onPressStart: i,
    onPressEnd: s,
    onPressChange: f,
    onPress: l,
    onPressUp: n,
    onClick: b,
    isDisabled: $
  }), { pressProps: B, isPressed: v } = w({
    onPressStart: i,
    onPressEnd: s,
    onPressChange: f,
    onPressUp: n,
    onClick: b,
    isDisabled: $,
    onPress(g) {
      var E;
      l?.(g), e.setSelectedValue(o), (E = r.current) === null || E === void 0 || E.focus();
    }
  }), { focusableProps: u } = ue(y(a, {
    onFocus: () => e.setLastFocusedValue(o)
  }), r), h = y(S, u), p = F(a, {
    labelable: !0
  }), x = -1;
  e.selectedValue != null ? e.selectedValue === o && (x = 0) : (e.lastFocusedValue === o || e.lastFocusedValue == null) && (x = 0), $ && (x = void 0);
  let { name: j, form: K, descriptionId: z, errorMessageId: J, validationBehavior: k } = W.get(e);
  return fe(r, e.defaultSelectedValue, e.setSelectedValue), $e({
    validationBehavior: k
  }, e, r), {
    labelProps: y(B, M(() => ({
      onClick: (g) => g.preventDefault(),
      // Prevent label from being focused when mouse down on it.
      // Note, this does not prevent the input from being focused in the `click` event.
      onMouseDown: (g) => g.preventDefault()
    }), [])),
    inputProps: y(p, {
      ...h,
      type: "radio",
      name: j,
      form: K,
      tabIndex: x,
      disabled: $,
      required: e.isRequired && k === "native",
      checked: P,
      value: o,
      onChange: D,
      "aria-describedby": [
        a["aria-describedby"],
        e.isInvalid ? J : null,
        z
      ].filter(Boolean).join(" ") || void 0
    }),
    isDisabled: $,
    isSelected: P,
    isPressed: V || v
  };
}
function Fe(a, e) {
  let { name: r, form: o, isReadOnly: d, isRequired: t, isDisabled: c, orientation: i = "vertical", validationBehavior: s = "aria" } = a, { direction: f } = he(), { isInvalid: l, validationErrors: n, validationDetails: b } = e.displayValidation, { labelProps: $, fieldProps: I, descriptionProps: m, errorMessageProps: P } = Pe({
    ...a,
    // Radio group is not an HTML input element so it
    // shouldn't be labeled by a <label> element.
    labelElementType: "span",
    isInvalid: e.isInvalid,
    errorMessage: a.errorMessage || n
  }), D = F(a, {
    labelable: !0
  }), { focusWithinProps: S } = me({
    onBlurWithin(v) {
      var u;
      (u = a.onBlur) === null || u === void 0 || u.call(a, v), e.selectedValue || e.setLastFocusedValue(null);
    },
    onFocusWithin: a.onFocus,
    onFocusWithinChange: a.onFocusChange
  }), V = (v) => {
    let u;
    switch (v.key) {
      case "ArrowRight":
        f === "rtl" && i !== "vertical" ? u = "prev" : u = "next";
        break;
      case "ArrowLeft":
        f === "rtl" && i !== "vertical" ? u = "next" : u = "prev";
        break;
      case "ArrowDown":
        u = "next";
        break;
      case "ArrowUp":
        u = "prev";
        break;
      default:
        return;
    }
    v.preventDefault();
    let h = ve(v.currentTarget, {
      from: v.target,
      accept: (x) => x instanceof pe(x).HTMLInputElement && x.type === "radio"
    }), p;
    u === "next" ? (p = h.nextNode(), p || (h.currentNode = v.currentTarget, p = h.firstChild())) : (p = h.previousNode(), p || (h.currentNode = v.currentTarget, p = h.lastChild())), p && (p.focus(), e.setSelectedValue(p.value));
  }, B = ne(r);
  return W.set(e, {
    name: B,
    form: o,
    descriptionId: m.id,
    errorMessageId: P.id,
    validationBehavior: s
  }), {
    radioGroupProps: y(D, {
      // https://www.w3.org/TR/wai-aria-1.2/#radiogroup
      role: "radiogroup",
      onKeyDown: V,
      "aria-invalid": e.isInvalid || void 0,
      "aria-errormessage": a["aria-errormessage"],
      "aria-readonly": d || void 0,
      "aria-required": t || void 0,
      "aria-disabled": c || void 0,
      "aria-orientation": i,
      ...I,
      ...S
    }),
    labelProps: $,
    descriptionProps: m,
    errorMessageProps: P,
    isInvalid: l,
    validationErrors: n,
    validationDetails: b
  };
}
let Be = /* @__PURE__ */ Math.round(/* @__PURE__ */ Math.random() * 1e10), Ee = 0;
function Me(a) {
  let e = M(() => a.name || `radio-group-${Be}-${++Ee}`, [
    a.name
  ]);
  var r;
  let [o, d] = ye(a.value, (r = a.defaultValue) !== null && r !== void 0 ? r : null, a.onChange), [t] = q(o), [c, i] = q(null), s = be({
    ...a,
    value: o
  }), f = (b) => {
    !a.isReadOnly && !a.isDisabled && (d(b), s.commitValidation());
  }, l = s.displayValidation.isInvalid;
  var n;
  return {
    ...s,
    name: e,
    selectedValue: o,
    defaultSelectedValue: a.value !== void 0 ? t : (n = a.defaultValue) !== null && n !== void 0 ? n : null,
    setSelectedValue: f,
    lastFocusedValue: c,
    setLastFocusedValue: i,
    isDisabled: a.isDisabled || !1,
    isReadOnly: a.isReadOnly || !1,
    isRequired: a.isRequired || !1,
    validationState: a.validationState || (l ? "invalid" : null),
    isInvalid: l
  };
}
const Oe = /* @__PURE__ */ O(null), ke = /* @__PURE__ */ O(null), A = /* @__PURE__ */ O(null), qe = /* @__PURE__ */ L(function(e, r) {
  [e, r] = _(e, r, Oe);
  let { validationBehavior: o } = ee(oe) || {};
  var d, t;
  let c = (t = (d = e.validationBehavior) !== null && d !== void 0 ? d : o) !== null && t !== void 0 ? t : "native", i = Me({
    ...e,
    validationBehavior: c
  }), [s, f] = ae(!e["aria-label"] && !e["aria-labelledby"]), { radioGroupProps: l, labelProps: n, descriptionProps: b, errorMessageProps: $, ...I } = Fe({
    ...e,
    label: f,
    validationBehavior: c
  }, i), m = N({
    ...e,
    values: {
      orientation: e.orientation || "vertical",
      isDisabled: i.isDisabled,
      isReadOnly: i.isReadOnly,
      isRequired: i.isRequired,
      isInvalid: i.isInvalid,
      state: i
    },
    defaultClassName: "react-aria-RadioGroup"
  }), P = F(e, {
    global: !0
  });
  return /* @__PURE__ */ R.createElement("div", {
    ...y(P, m, l),
    ref: r,
    slot: e.slot || void 0,
    "data-orientation": e.orientation || "vertical",
    "data-invalid": i.isInvalid || void 0,
    "data-disabled": i.isDisabled || void 0,
    "data-readonly": i.isReadOnly || void 0,
    "data-required": i.isRequired || void 0
  }, /* @__PURE__ */ R.createElement(ie, {
    values: [
      [
        A,
        i
      ],
      [
        te,
        {
          ...n,
          ref: s,
          elementType: "span"
        }
      ],
      [
        se,
        {
          slots: {
            description: b,
            errorMessage: $
          }
        }
      ],
      [
        re,
        I
      ]
    ]
  }, /* @__PURE__ */ R.createElement(le, null, m.children)));
}), we = /* @__PURE__ */ L(function(e, r) {
  let { inputRef: o = null, ...d } = e;
  [e, r] = _(d, r, ke);
  let t = R.useContext(A), c = ce(M(() => Y(o, e.inputRef !== void 0 ? e.inputRef : null), [
    o,
    e.inputRef
  ])), { labelProps: i, inputProps: s, isSelected: f, isDisabled: l, isPressed: n } = Ce({
    ...Z(e),
    // ReactNode type doesn't allow function children.
    children: typeof e.children == "function" ? !0 : e.children
  }, t, c), { isFocused: b, isFocusVisible: $, focusProps: I } = T(), m = l || t.isReadOnly, { hoverProps: P, isHovered: D } = xe({
    ...e,
    isDisabled: m
  }), S = N({
    ...e,
    defaultClassName: "react-aria-Radio",
    values: {
      isSelected: f,
      isPressed: n,
      isHovered: D,
      isFocused: b,
      isFocusVisible: $,
      isDisabled: l,
      isReadOnly: t.isReadOnly,
      isInvalid: t.isInvalid,
      isRequired: t.isRequired
    }
  }), V = F(e, {
    global: !0
  });
  return delete V.id, delete V.onClick, /* @__PURE__ */ R.createElement("label", {
    ...y(V, i, P, S),
    ref: r,
    "data-selected": f || void 0,
    "data-pressed": n || void 0,
    "data-hovered": D || void 0,
    "data-focused": b || void 0,
    "data-focus-visible": $ || void 0,
    "data-disabled": l || void 0,
    "data-readonly": t.isReadOnly || void 0,
    "data-invalid": t.isInvalid || void 0,
    "data-required": t.isRequired || void 0
  }, /* @__PURE__ */ R.createElement(Re, {
    elementType: "span"
  }, /* @__PURE__ */ R.createElement("input", {
    ...y(s, I),
    ref: c
  })), /* @__PURE__ */ R.createElement(de.Provider, {
    value: {
      isSelected: f
    }
  }, S.children));
}), { withProvider: _e, withContext: Ne } = /* @__PURE__ */ ge({
  key: "radioInput"
}), Le = /* @__PURE__ */ _e("div", "root"), Te = /* @__PURE__ */ Ne("span", "option"), G = (a) => {
  const e = De({ recipe: Se }), [r, o] = e.splitVariantProps(a), [d, t] = U(o);
  return /* @__PURE__ */ C(Le, { ...r, ...d, asChild: !0, children: /* @__PURE__ */ C(qe, { ...t, children: a.children }) });
};
G.displayName = "RadioInput.Root";
const H = ({
  children: a,
  value: e,
  ...r
}) => {
  const [o, d] = U(r), { isFocused: t, focusProps: c } = T();
  return /* @__PURE__ */ C(
    Te,
    {
      ...o,
      ...c,
      "data-focus": t || void 0,
      asChild: !0,
      children: /* @__PURE__ */ C(we, { value: e, ...d, children: (i) => {
        const s = typeof a == "function" ? a({
          ...i
        }) : a;
        return /* @__PURE__ */ Q(X, { children: [
          i.isSelected ? /* @__PURE__ */ C(Ie, {}) : /* @__PURE__ */ C(Ve, {}),
          s
        ] });
      } })
    }
  );
};
H.displayName = "RadioInput.Option";
const va = {
  /**
   * # RadioInput.Root
   *
   * The root container for a radio input group that manages the selection state and provides context for radio options.
   * Handles keyboard navigation, accessibility attributes, and mutually exclusive selection behavior.
   *
   * @example
   * ```tsx
   * <RadioInput.Root name="selection" defaultValue="option1">
   *   <RadioInput.Option value="option1">First Choice</RadioInput.Option>
   *   <RadioInput.Option value="option2">Second Choice</RadioInput.Option>
   * </RadioInput.Root>
   * ```
   */
  Root: G,
  /**
   * # RadioInput.Option
   *
   * An individual radio option within a RadioInput group that can be selected.
   * Provides visual feedback for selection state and supports keyboard interaction.
   *
   * @example
   * ```tsx
   * <RadioInput.Root name="choice">
   *   <RadioInput.Option value="yes">Yes</RadioInput.Option>
   *   <RadioInput.Option value="no">No</RadioInput.Option>
   * </RadioInput.Root>
   * ```
   */
  Option: H
};
export {
  va as R
};
//# sourceMappingURL=radio-input-DV-hhL4S.es.js.map
