import { Checkbox } from "../../ui/checkbox.js";
import { Label } from "../../ui/label.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 CheckboxField = (l) => {
	let d = c(12), { name: f, schema: p, ui: m, required: h, form: g, disabled: _ } = l, v = useFieldConfig(f, p, m, _), y = v.defaultValue || !1, b = h ? _temp : void 0, x;
	d[0] === b ? x = d[1] : (x = { validate: b }, d[0] = b, d[1] = x);
	let S;
	d[2] !== v || d[3] !== f || d[4] !== h ? (S = (o) => {
		let { field: s } = o, { onChange: l, value: u, ref: d } = s;
		return /* @__PURE__ */ jsx(BaseFieldWrapper, {
			name: f,
			label: v.fieldLabel,
			required: h,
			error: v.error,
			helpText: v.helpText,
			description: v.description,
			children: /* @__PURE__ */ jsxs("div", {
				className: "flex items-center space-x-2",
				children: [/* @__PURE__ */ jsx(Checkbox, {
					id: f,
					checked: !!u,
					onCheckedChange: v.isReadOnly ? void 0 : (e) => l(e || !1),
					disabled: v.isDisabled,
					ref: d,
					name: f,
					required: h,
					...v.getAriaProps()
				}), /* @__PURE__ */ jsx(Label, {
					htmlFor: f,
					className: "text-sm leading-none font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
					children: v.fieldLabel
				})]
			})
		});
	}, d[2] = v, d[3] = f, d[4] = h, d[5] = S) : S = d[5];
	let C;
	return d[6] !== g.control || d[7] !== f || d[8] !== y || d[9] !== x || d[10] !== S ? (C = /* @__PURE__ */ jsx(Controller, {
		name: f,
		control: g.control,
		defaultValue: y,
		rules: x,
		render: S
	}), d[6] = g.control, d[7] = f, d[8] = y, d[9] = x, d[10] = S, d[11] = C) : C = d[11], C;
};
function _temp(e) {
	return e === !0 || "This field is required";
}
export { CheckboxField };
