import { n as __exportAll } from "./chunk-B-1-B7_t.js";
import { t as Checkbox_default } from "./checkbox-CyVKkarV.js";
import { n as Label_default } from "./label-C5K3zowH.js";
import { t as FieldFrame_default } from "./field-frame-DhCOWcMP.js";
import { Fragment, computed, createBlock, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, mergeModels, normalizeClass, openBlock, renderList, toDisplayString, unref, useModel, withCtx } from "vue";
//#region src/components/compositions/elements/option-select/CheckboxOption.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = ["data-element-name"];
var CheckboxOption_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "CheckboxOption",
	props: /* @__PURE__ */ mergeModels({
		modelValue: {},
		options: { default: () => [] },
		id: {},
		name: {},
		label: {},
		hideLabel: { type: Boolean },
		inline: { type: Boolean },
		required: { type: Boolean },
		readonly: { type: Boolean },
		disabled: { type: Boolean },
		helpText: {},
		errors: { default: () => [] }
	}, {
		"modelValue": {},
		"modelModifiers": {}
	}),
	emits: ["update:modelValue"],
	setup(__props) {
		/**
		* Props-driven multi-checkbox composition. Renders one Checkbox per
		* option and stores the result as an array of selected values.
		*
		*   <CheckboxOption v-model="prefs" :options="[...]" label="Preferences" />
		*/
		const props = __props;
		const model = useModel(__props, "modelValue");
		function normaliseOption(opt) {
			if (typeof opt === "string") return {
				label: opt,
				value: opt,
				disabled: false
			};
			return {
				label: opt.label,
				value: String(opt.value),
				disabled: Boolean(opt.disabled)
			};
		}
		const normalised = computed(() => (props.options ?? []).map(normaliseOption));
		const selected = computed(() => {
			const v = model.value;
			if (!v) return [];
			if (Array.isArray(v)) return v.map((x) => String(x));
			return [String(v)];
		});
		function isChecked(val) {
			return selected.value.includes(val);
		}
		function onToggle(val, checked) {
			const current = selected.value;
			if (checked === true) {
				if (!current.includes(val)) model.value = [...current, val];
			} else model.value = current.filter((v) => v !== val);
		}
		return (_ctx, _cache) => {
			return openBlock(), createBlock(unref(FieldFrame_default), {
				label: __props.label,
				required: __props.required,
				"hide-label": __props.hideLabel,
				"help-text": __props.helpText,
				errors: __props.errors
			}, {
				default: withCtx(() => [createElementVNode("div", {
					class: normalizeClass(__props.inline ? "flex flex-row flex-wrap gap-4" : "grid gap-2"),
					"data-element-name": __props.name ?? void 0
				}, [(openBlock(true), createElementBlock(Fragment, null, renderList(normalised.value, (opt) => {
					return openBlock(), createElementBlock("div", {
						key: opt.value,
						class: "flex items-center gap-2"
					}, [createVNode(unref(Checkbox_default), {
						id: `${__props.id ?? "checkbox"}-${opt.value}`,
						name: __props.name,
						"model-value": isChecked(opt.value),
						disabled: opt.disabled || __props.disabled || __props.readonly,
						"onUpdate:modelValue": (c) => onToggle(opt.value, c)
					}, null, 8, [
						"id",
						"name",
						"model-value",
						"disabled",
						"onUpdate:modelValue"
					]), createVNode(unref(Label_default), {
						for: `${__props.id ?? "checkbox"}-${opt.value}`,
						class: "cursor-pointer"
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(opt.label), 1)]),
						_: 2
					}, 1032, ["for"])]);
				}), 128))], 10, _hoisted_1)]),
				_: 1
			}, 8, [
				"label",
				"required",
				"hide-label",
				"help-text",
				"errors"
			]);
		};
	}
});
//#endregion
//#region src/components/compositions/elements/option-select/CheckboxOption.vue
var CheckboxOption_exports = /* @__PURE__ */ __exportAll({ default: () => CheckboxOption_default });
var CheckboxOption_default = CheckboxOption_vue_vue_type_script_setup_true_lang_default;
//#endregion
export { CheckboxOption_exports as n, CheckboxOption_default as t };

//# sourceMappingURL=CheckboxOption-Cyr6s2Pg.js.map