import { Label } from "../../ui/label.js";
import { Switch } from "../../ui/switch.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 SwitchField = (l) => {
	let d = c(15), { name: p, schema: m, ui: h, required: g, form: _, disabled: v } = l, y = useFieldConfig(p, m, h, v), b;
	if (d[0] !== m.const || d[1] !== m.enum) {
		if (b = {}, m.const === !0) {
			let e;
			d[3] === Symbol.for("react.memo_cache_sentinel") ? (e = { mustBeTrue: _temp }, d[3] = e) : e = d[3], b.validate = e;
		}
		if (m.enum?.length === 1 && m.enum[0] === !0) {
			let e;
			d[4] === Symbol.for("react.memo_cache_sentinel") ? (e = { mustBeTrue: _temp2 }, d[4] = e) : e = d[4], b.validate = e;
		}
		d[0] = m.const, d[1] = m.enum, d[2] = b;
	} else b = d[2];
	let x = b, S = y.defaultValue ?? !1, C;
	d[5] !== y || d[6] !== p || d[7] !== g ? (C = (o) => {
		let { field: s } = o, { onChange: l, value: u, ref: d, ...f } = s;
		return /* @__PURE__ */ jsx(BaseFieldWrapper, {
			name: p,
			label: y.fieldLabel,
			required: g,
			error: y.error,
			helpText: y.helpText,
			description: y.description,
			showLabel: !1,
			children: /* @__PURE__ */ jsxs("div", {
				className: "flex items-center space-x-2",
				children: [/* @__PURE__ */ jsx(Switch, {
					id: p,
					checked: !!u,
					onCheckedChange: y.isReadOnly ? void 0 : l,
					disabled: y.isDisabled,
					ref: d,
					...f,
					...y.getAriaProps()
				}), /* @__PURE__ */ jsx(Label, {
					htmlFor: p,
					className: `text-sm leading-none font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70 ${g ? "after:ml-0.5 after:text-red-500 after:content-['*']" : ""}`,
					children: y.fieldLabel
				})]
			})
		});
	}, d[5] = y, d[6] = p, d[7] = g, d[8] = C) : C = d[8];
	let w;
	return d[9] !== _.control || d[10] !== p || d[11] !== S || d[12] !== C || d[13] !== x ? (w = /* @__PURE__ */ jsx(Controller, {
		name: p,
		control: _.control,
		defaultValue: S,
		rules: x,
		render: C
	}), d[9] = _.control, d[10] = p, d[11] = S, d[12] = C, d[13] = x, d[14] = w) : w = d[14], w;
};
function _temp(e) {
	return e === !0 || "This field must be accepted";
}
function _temp2(e) {
	return e === !0 || "This field must be accepted";
}
export { SwitchField };
