import { cn as e } from "../../../lib/utils.js";
import { Label as t } from "../../ui/label.js";
import { RadioGroup as n, RadioGroupItem as r } from "../../ui/radio-group.js";
import { useFieldConfig as i } from "../hooks/useFieldConfig.js";
import { BaseFieldWrapper as a } from "./BaseFieldWrapper.js";
import "react";
import { jsx as o, jsxs as s } from "react/jsx-runtime";
import { Controller as c } from "react-hook-form";
//#region src/components/dynamic-form/fields/RadioField.tsx
var l = ({ name: l, schema: u, ui: d, required: f, form: p, disabled: m }) => {
	let h = i(l, u, d, m), g = d, _ = g?.enumOptions ?? u.enumOptions, v = _ ? _.map((e) => e.label) : u.enum, y = _ ? _.map((e) => e.value) : u.enum;
	return /* @__PURE__ */ o(c, {
		name: l,
		control: p.control,
		defaultValue: h.defaultValue || "",
		rules: { required: f ? "This field is required" : void 0 },
		render: ({ field: i }) => /* @__PURE__ */ o(a, {
			name: l,
			label: h.fieldLabel,
			required: f,
			error: h.error,
			helpText: h.helpText,
			description: h.description,
			helpTextPosition: "before",
			children: /* @__PURE__ */ o(n, {
				value: i.value,
				onValueChange: h.isReadOnly ? void 0 : i.onChange,
				disabled: h.isDisabled,
				required: f,
				"aria-label": h.fieldLabel,
				className: e((g?.inline ?? u.inline) && "flex flex-row space-y-0 space-x-4"),
				...h.getAriaProps(),
				children: y?.map((n, i) => /* @__PURE__ */ s("div", {
					className: "flex items-center space-x-2",
					children: [/* @__PURE__ */ o(r, {
						value: n,
						id: `${l}-${n}`,
						disabled: h.isDisabled,
						className: e(h.error && "border-destructive")
					}), /* @__PURE__ */ o(t, {
						htmlFor: `${l}-${n}`,
						className: e("cursor-pointer text-sm font-normal", h.isDisabled && "cursor-not-allowed opacity-70"),
						children: v?.[i] || n
					})]
				}, n))
			})
		})
	});
};
//#endregion
export { l as RadioField };
