import { t as e } from "../../../chunks/clsx.js";
import { useValue as t } from "../../hooks/useValue.js";
import { Children as n, cloneElement as r, isValidElement as i, useId as a } from "react";
import { jsx as o } from "react/jsx-runtime";
//#region lib/ui/forms/checkboxes/Checkboxes.tsx
function s(s) {
	let c = a(), { id: l = c, name: u = l, children: d, value: f, defaultValue: p, onChange: m, disabled: h, readOnly: g, tabIndex: _ = 0, ...v } = s, { value: y, setValue: b } = t({
		initialValue: f,
		formatter(e) {
			return e === void 0 ? e : [].concat(e);
		},
		defaultValue: p || [],
		onChange: m
	});
	return /* @__PURE__ */ o("div", {
		...v,
		className: v.className,
		role: "listbox",
		children: n.map(d, (t, n) => {
			if (i(t)) {
				let i = t.props.value;
				return r(t, {
					...t.props,
					name: u,
					id: `${l}-${n}`,
					disabled: h,
					readOnly: g,
					tabIndex: _ + n + 1,
					className: e(t.props.className || "mt-8 first:mt-0"),
					checked: y.includes(i),
					onChange(...e) {
						let t = e[0] instanceof Event ? e[0] : e[0]?.nativeEvent ?? new Event("change");
						(typeof e[2] == "boolean" ? e[2] : typeof e[1] == "boolean" ? e[1] : e[0]?.target?.checked) ? b(y.concat(i), t) : b(y.filter((e) => e !== i), t);
					}
				});
			}
			return t;
		})
	});
}
//#endregion
export { s as Checkboxes };

//# sourceMappingURL=Checkboxes.js.map