import { jsxs as d, jsx as s, Fragment as C } from "react/jsx-runtime";
import { forwardRef as F, useState as G, useCallback as M } from "react";
import { cx as r } from "../../utils/classNames.js";
import { useArrowTheme as T } from "../../hooks/useArrowTheme.js";
function q() {
  return /* @__PURE__ */ s(
    "svg",
    {
      role: "img",
      "aria-label": "error",
      width: "12",
      height: "12",
      viewBox: "0 0 24 24",
      fill: "currentColor",
      children: /* @__PURE__ */ s("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z" })
    }
  );
}
function H(c, l) {
  if (l !== void 0)
    return l;
  const a = c.find((o) => o.checked);
  return a ? a.value : "";
}
const J = F(
  ({
    legend: c,
    groupName: l,
    radioButtons: a,
    inverse: o,
    ariaRequired: g = !1,
    ariaInvalid: y = !1,
    legendAsLabel: h = !1,
    errorMessage: x = "",
    value: t,
    defaultValue: N,
    className: u,
    onChange: n,
    ...w
  }, D) => {
    const L = T(), j = o ?? L.inverse, i = x.trim(), k = y && i, [E, I] = G(
      () => H(a, N)
    ), _ = t !== void 0 ? t : E, p = a.some(
      (e) => !!e.action
    ), V = [
      k ? l + "-error" : "",
      p ? "styled-radio-group-helper-text-" + l : ""
    ].filter(Boolean).join(" ") || void 0, S = M(
      (e) => {
        t === void 0 && I(e.target.value), n == null || n(e.target.value, e);
      },
      [n, t]
    );
    return a.length === 0 ? null : /* @__PURE__ */ d(
      "fieldset",
      {
        ref: D,
        className: r("tdds-styled-radio__group", u),
        role: "radiogroup",
        "aria-required": g || void 0,
        "data-inverse": j ? "true" : void 0,
        "aria-label": h ? c : void 0,
        "aria-describedby": V,
        ...w,
        children: [
          h ? null : /* @__PURE__ */ s("legend", { className: "tdds-radiogroup__legend", children: c }),
          p ? /* @__PURE__ */ s(
            "span",
            {
              className: "tdds:screen-reader-only",
              id: "styled-radio-group-helper-text-" + l,
              children: "Edit controls are available which follow each radio button"
            }
          ) : null,
          a.map((e) => {
            var b, f, v;
            const z = _ !== "" ? _ === e.value : !!e.checked, m = typeof e.status == "string" ? e.status : (b = e.status) == null ? void 0 : b.label, R = typeof e.status == "object" && ((f = e.status) != null && f.icon) ? /* @__PURE__ */ s(
              "span",
              {
                "aria-hidden": e.status.a11yLabel ? void 0 : "true",
                "aria-label": e.status.a11yLabel,
                children: e.status.icon
              }
            ) : null, A = typeof e.status == "object" ? (v = e.status) == null ? void 0 : v.type : void 0;
            return /* @__PURE__ */ d("div", { className: "tdds-styled-radio", children: [
              /* @__PURE__ */ s(
                "input",
                {
                  id: e.id,
                  type: "radio",
                  name: l,
                  value: e.value,
                  "aria-disabled": e.disabled || void 0,
                  "aria-invalid": y || void 0,
                  checked: z,
                  className: r("tdds:screen-reader-only", {
                    "force-pressed": e.pressed,
                    "force-focused": e.focused
                  }),
                  onChange: S
                }
              ),
              /* @__PURE__ */ d(
                "div",
                {
                  className: r("tdds-styled-radio__info", {
                    "tdds-styled-radio__info--grid": !!e.action,
                    "tdds-styled-radio__info--error": !!i,
                    "force-hover": e.hover
                  }),
                  children: [
                    /* @__PURE__ */ s(
                      "label",
                      {
                        htmlFor: e.id,
                        className: "tdds-styled-radio__container",
                        children: /* @__PURE__ */ d(
                          "span",
                          {
                            className: r("tdds-styled-radio__wrapper", {
                              "tdds-styled-radio__wrapper--withIcon": !!e.leadingDecoration
                            }),
                            children: [
                              /* @__PURE__ */ s("span", { className: "tdds-styled-radio__icon" }),
                              e.leadingDecoration ? /* @__PURE__ */ s(
                                "span",
                                {
                                  id: e.id + "-leadingDecoration",
                                  className: "tdds-styled-radio__leadingDecoration tdds:px-1",
                                  "aria-label": e.leadingDecorationA11yLabel,
                                  "aria-hidden": e.leadingDecorationA11yLabel ? void 0 : "true",
                                  children: e.leadingDecoration
                                }
                              ) : null,
                              /* @__PURE__ */ d(
                                "span",
                                {
                                  className: r("tdds-styled-radio__text", {
                                    "tdds-styled-radio__text--grid": !e.action && !!e.secondaryLabel
                                  }),
                                  children: [
                                    /* @__PURE__ */ d("span", { className: "tdds-styled-radio__text--flex-col", children: [
                                      /* @__PURE__ */ s(
                                        "span",
                                        {
                                          id: e.id + "-label",
                                          className: "tdds-styled-radio__label",
                                          children: e.label
                                        }
                                      ),
                                      e.body ? /* @__PURE__ */ s(
                                        "span",
                                        {
                                          id: e.id + "-body",
                                          className: "tdds-styled-radio__body",
                                          children: e.body
                                        }
                                      ) : null,
                                      m ? /* @__PURE__ */ d(
                                        "span",
                                        {
                                          className: "tdds-styled-radio__status",
                                          id: e.id + "-status-icon-label",
                                          "data-status": A,
                                          children: [
                                            R,
                                            m
                                          ]
                                        }
                                      ) : null
                                    ] }),
                                    !e.action && e.secondaryLabel ? /* @__PURE__ */ d("span", { className: "tdds-styled-radio__text--flex-col tdds-styled-radio__text--right", children: [
                                      /* @__PURE__ */ s("span", { className: "tdds-styled-radio__label", children: e.secondaryLabel }),
                                      e.secondaryBody ? /* @__PURE__ */ s("span", { className: "tdds-styled-radio__body", children: e.secondaryBody }) : null
                                    ] }) : null
                                  ]
                                }
                              )
                            ]
                          }
                        )
                      }
                    ),
                    e.action ? /* @__PURE__ */ s("div", { className: r(
                      "tdds-styled-radio__button",
                      e.actionVariant === "icon-button" ? "tdds-styled-radio__text--flex-right--small" : "tdds-styled-radio__text--flex-right"
                    ), children: e.action }) : null
                  ]
                }
              )
            ] }, e.id);
          }),
          /* @__PURE__ */ s(
            "p",
            {
              id: l + "-error",
              className: "tdds-styled-radio__group--error-message",
              "aria-hidden": !i || void 0,
              children: i ? /* @__PURE__ */ d(C, { children: [
                /* @__PURE__ */ s(q, {}),
                i
              ] }) : null
            }
          )
        ]
      }
    );
  }
);
J.displayName = "StyledRadioGroup";
export {
  J as StyledRadioGroup
};
//# sourceMappingURL=StyledRadioGroup.js.map
