import { Label as e } from "../../ui/label.js";
import { Switch as t } from "../../ui/switch.js";
import { useFieldConfig as n } from "../hooks/useFieldConfig.js";
import { BaseFieldWrapper as r } from "./BaseFieldWrapper.js";
import i from "react";
import { jsx as a, jsxs as o } from "react/jsx-runtime";
import { Controller as s } from "react-hook-form";
//#region src/components/dynamic-form/fields/SwitchField.tsx
var c = ({ name: c, schema: l, ui: u, required: d, form: f, disabled: p }) => {
	let m = n(c, l, u, p), h = i.useMemo(() => {
		let e = {};
		return l.const === !0 && (e.validate = { mustBeTrue: (e) => e === !0 || "This field must be accepted" }), l.enum?.length === 1 && l.enum[0] === !0 && (e.validate = { mustBeTrue: (e) => e === !0 || "This field must be accepted" }), e;
	}, [l.const, l.enum]);
	return /* @__PURE__ */ a(s, {
		name: c,
		control: f.control,
		defaultValue: m.defaultValue ?? !1,
		rules: h,
		render: ({ field: { onChange: n, value: i, ref: s, ...l } }) => /* @__PURE__ */ a(r, {
			name: c,
			label: m.fieldLabel,
			required: d,
			error: m.error,
			helpText: m.helpText,
			description: m.description,
			showLabel: !1,
			children: /* @__PURE__ */ o("div", {
				className: "flex items-center space-x-2",
				children: [/* @__PURE__ */ a(t, {
					id: c,
					checked: !!i,
					onCheckedChange: m.isReadOnly ? void 0 : n,
					disabled: m.isDisabled,
					ref: s,
					...l,
					...m.getAriaProps()
				}), /* @__PURE__ */ a(e, {
					htmlFor: c,
					className: `text-sm leading-none font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70 ${d ? "after:ml-0.5 after:text-red-500 after:content-['*']" : ""}`,
					children: m.fieldLabel
				})]
			})
		})
	});
};
//#endregion
export { c as SwitchField };
