import { jsx as o, jsxs as F, Fragment as D } from "@emotion/react/jsx-runtime";
import { useFormContext as N, Controller as T } from "react-hook-form";
import { useId as W } from "react";
import { Radio as $ } from "../../extended/mui/Radio/Radio.js";
import { RootStyled as j, RadioGroupStyled as U, OptionWrapperStyled as y, OptionControlStyled as B, OptionStartAdornmentStyled as K, OptionLabelStyled as M } from "./slots/styled.js";
import { useComponentSize as V } from "../../../hooks/useComponentSize/index.js";
import { RHFRADIO_GROUP_KEY_COMPONENT as Y, RHFRADIO_GROUP_CLASSES as q } from "./constants.js";
import J from "clsx";
import { getPropDataTestId as Q } from "../../../test/getNameDataTestId.js";
import { getOptionLabelColor as X } from "../../../utils/getOptionLabelColor.js";
import { RHFRadioGroupSlots as Z } from "./slots/slots.js";
import { Label as oo } from "../../Label/Label.js";
import { RenderOptionStartAdornment as ro } from "./subcomponents/RenderOptionStartAdornment/RenderOptionStartAdornment.js";
import { HelperError as to } from "../../HelperError/HelperError.js";
function Fo({
  id: A,
  name: C,
  options: s,
  getOptionLabel: I,
  getOptionValue: x,
  getOptionStartAdornment: a,
  label: p,
  mandatory: G,
  mandatoryMessage: b,
  helperMessage: k,
  size: z,
  dataTestId: E,
  labelSkeletonWidth: H,
  helperErrorSkeletonWidth: eo,
  disabled: S,
  className: L,
  ControlOption: f = $,
  rowColumns: P,
  ..._
}) {
  const g = W(), n = A || g, { currentSize: i } = V(z), { control: v } = N(), h = s.some((e) => {
    const r = a?.(e);
    return r != null;
  });
  return /* @__PURE__ */ o(
    j,
    {
      ownerState: { hasStartAdornment: h },
      className: J(q.root, L),
      children: /* @__PURE__ */ o(
        T,
        {
          name: C,
          control: v,
          render: ({ field: { onChange: e, value: r }, fieldState: { error: m } }) => /* @__PURE__ */ F(D, { children: [
            p && /* @__PURE__ */ o(
              oo,
              {
                id: `${n}-label`,
                htmlFor: n,
                label: p,
                mandatory: G,
                mandatoryMessage: b,
                helperMessage: k,
                size: i,
                skeletonWidth: H,
                error: !!m,
                disabled: S
              }
            ),
            /* @__PURE__ */ o(
              U,
              {
                ownerState: { hasStartAdornment: h, rowColumns: P },
                onChange: e,
                value: r,
                ..._,
                ...Q(
                  Y,
                  Z.radioGroup,
                  E
                ),
                children: s.map((l) => {
                  const t = x(l), u = I(l), d = a?.(l), w = d != null, R = `${n}-option-${String(t)}`, c = r === t, O = {
                    checked: c,
                    onChange: e,
                    value: t
                  };
                  return w ? /* @__PURE__ */ F(y, { children: [
                    /* @__PURE__ */ o(B, { children: /* @__PURE__ */ o(
                      f,
                      {
                        id: R,
                        ...O
                      }
                    ) }),
                    /* @__PURE__ */ o(K, { children: /* @__PURE__ */ o(
                      ro,
                      {
                        adornment: d,
                        size: i
                      }
                    ) }),
                    /* @__PURE__ */ o(
                      M,
                      {
                        component: "label",
                        htmlFor: R,
                        variant: "bodyStandard",
                        size: i,
                        color: X(c, S),
                        ownerState: { checked: c },
                        children: u
                      }
                    )
                  ] }, t) : /* @__PURE__ */ o(y, { children: /* @__PURE__ */ o(
                    f,
                    {
                      ...O,
                      inlineText: u
                    }
                  ) }, t);
                })
              }
            ),
            m && /* @__PURE__ */ o(to, { message: m.message || "" })
          ] })
        }
      )
    }
  );
}
export {
  Fo as RHFRadioGroup
};
