import { jsxs as f, jsx as e } from "react/jsx-runtime";
import { useState as S, useMemo as V, useCallback as j } from "react";
import { RadioContainer as w, RadioItem as C } from "./RadioPrimitive.js";
import k from "../../utils/generateCustomID.js";
import n from "../box/Box.js";
import p from "../label/Label.js";
import D from "../error-message/ErrorMessage.js";
import { c } from "../../index-BtlgVD4m.js";
const E = ({
  ref: g,
  options: r,
  value: u,
  hasBorder: l = !1,
  onChange: t,
  defaultValue: b,
  errorMessage: s,
  ...x
}) => {
  const [N, h] = S(b), I = V(() => r.map(() => k("radio-value")), [r]), i = u !== void 0, y = i ? u : N, R = j(
    (a) => {
      i || h(a), t == null || t(a);
    },
    [i, t]
  );
  return /* @__PURE__ */ f("div", { className: "relative", children: [
    /* @__PURE__ */ e(
      w,
      {
        ref: g,
        ...x,
        defaultValue: String(b),
        value: String(y),
        onValueChange: R,
        className: c(l && "border rounded-[var(--border-radius-md)] border-[var(--base-border)] gap-0"),
        children: r.map((a, v) => {
          const o = I[v], { label: d, description: m } = a;
          return /* @__PURE__ */ f(
            "div",
            {
              className: c(
                "grid grid-flow-row gap-x-[var(--spacing-2)]",
                "grid-cols-2",
                l && "p-[var(--spacing-3)]",
                l && v !== r.length - 1 ? "border-b border-[var(--base-border)]" : ""
              ),
              style: { gridTemplateColumns: "16px 1fr" },
              children: [
                /* @__PURE__ */ e(n, { className: "flex items-center", children: /* @__PURE__ */ e(
                  C,
                  {
                    className: c("align-baseline", !!s && "!border-[var(--base-danger-text)]"),
                    value: String(a.value),
                    id: o
                  }
                ) }),
                d && /* @__PURE__ */ e(n, { className: "flex items-center leading-none", children: /* @__PURE__ */ e(
                  p,
                  {
                    htmlFor: o,
                    variant: "subtitle",
                    className: s ? "text-[var(--base-danger-text)]" : "text-[var(--base-foreground)]",
                    children: d
                  }
                ) }),
                d && m && /* @__PURE__ */ e("div", { className: "empty-cell" }),
                m && /* @__PURE__ */ e(n, { className: "flex justify-start", children: /* @__PURE__ */ e(p, { variant: "subtitle", children: m }) })
              ]
            },
            o
          );
        })
      }
    ),
    /* @__PURE__ */ e(D, { message: s })
  ] });
};
E.displayName = "Radio";
export {
  E as default
};
//# sourceMappingURL=Radio.js.map
