import { cn } from "../../../lib/utils.js";
import { Label } from "../../ui/label.js";
import { RadioGroup, RadioGroupItem } from "../../ui/radio-group.js";
import { useFieldConfig } from "../hooks/useFieldConfig.js";
import { BaseFieldWrapper } from "./BaseFieldWrapper.js";
import { c } from "react/compiler-runtime";
import React from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { Controller } from "react-hook-form";
const RadioField = (p) => {
	let m = c(21), { name: h, schema: g, ui: _, required: v, form: y, disabled: b } = p, x = useFieldConfig(h, g, _, b), S = g.enumOptions, C;
	m[0] !== S || m[1] !== g.enum ? (C = S ? S.map(_temp) : g.enum, m[0] = S, m[1] = g.enum, m[2] = C) : C = m[2];
	let w = C, T;
	m[3] !== S || m[4] !== g.enum ? (T = S ? S.map(_temp2) : g.enum, m[3] = S, m[4] = g.enum, m[5] = T) : T = m[5];
	let E = T, D = x.defaultValue || "", O = v ? "This field is required" : void 0, k;
	m[6] === O ? k = m[7] : (k = { required: O }, m[6] = O, m[7] = k);
	let A;
	m[8] !== x || m[9] !== w || m[10] !== E || m[11] !== h || m[12] !== v || m[13] !== g.inline ? (A = (d) => {
		let { field: f } = d;
		return /* @__PURE__ */ jsx(BaseFieldWrapper, {
			name: h,
			label: x.fieldLabel,
			required: v,
			error: x.error,
			helpText: x.helpText,
			description: x.description,
			helpTextPosition: "before",
			children: /* @__PURE__ */ jsx(RadioGroup, {
				value: f.value,
				onValueChange: x.isReadOnly ? void 0 : f.onChange,
				disabled: x.isDisabled,
				required: v,
				"aria-label": x.fieldLabel,
				className: cn(g.inline && "flex flex-row space-y-0 space-x-4"),
				...x.getAriaProps(),
				children: E?.map((u, d) => /* @__PURE__ */ jsxs("div", {
					className: "flex items-center space-x-2",
					children: [/* @__PURE__ */ jsx(RadioGroupItem, {
						value: u,
						id: `${h}-${u}`,
						disabled: x.isDisabled,
						className: cn(x.error && "border-destructive")
					}), /* @__PURE__ */ jsx(Label, {
						htmlFor: `${h}-${u}`,
						className: cn("cursor-pointer text-sm font-normal", x.isDisabled && "cursor-not-allowed opacity-70"),
						children: w?.[d] || u
					})]
				}, u))
			})
		});
	}, m[8] = x, m[9] = w, m[10] = E, m[11] = h, m[12] = v, m[13] = g.inline, m[14] = A) : A = m[14];
	let j;
	return m[15] !== y.control || m[16] !== h || m[17] !== D || m[18] !== k || m[19] !== A ? (j = /* @__PURE__ */ jsx(Controller, {
		name: h,
		control: y.control,
		defaultValue: D,
		rules: k,
		render: A
	}), m[15] = y.control, m[16] = h, m[17] = D, m[18] = k, m[19] = A, m[20] = j) : j = m[20], j;
};
function _temp(n) {
	return n.label;
}
function _temp2(n) {
	return n.value;
}
export { RadioField };
