import { n as __exportAll } from "./chunk-B-1-B7_t.js";
import { l as SelectContent_default, n as SelectTrigger_default, s as SelectItem_default, t as SelectValue_default, u as Select_default } from "./select-Dwoxq29k.js";
import { t as FieldFrame_default } from "./field-frame-DhCOWcMP.js";
import { Fragment, computed, createBlock, createElementBlock, createTextVNode, createVNode, defineComponent, mergeModels, normalizeClass, openBlock, renderList, toDisplayString, unref, useModel, withCtx } from "vue";
//#region src/components/compositions/elements/option-select/SelectOption.vue?vue&type=script&setup=true&lang.ts
var SelectOption_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "SelectOption",
	props: /* @__PURE__ */ mergeModels({
		modelValue: {},
		options: { default: () => [] },
		id: {},
		name: {},
		label: {},
		hideLabel: { type: Boolean },
		placeholder: {},
		required: { type: Boolean },
		readonly: { type: Boolean },
		disabled: { type: Boolean },
		helpText: {},
		errors: { default: () => [] }
	}, {
		"modelValue": {},
		"modelModifiers": {}
	}),
	emits: ["update:modelValue"],
	setup(__props) {
		/**
		* Props-driven single-select composition. Composes the shadcn `Select`
		* primitive with `FieldFrame` chrome.
		*
		* Self-contained — usable directly in any Vue app:
		*
		*   <SelectOption v-model="role" :options="[...]" label="Role" />
		*
		* The JSON-driven engine renders this via `ElementRenderer`, which binds
		* `modelValue` / `errors` to the form-data store automatically.
		*/
		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 triggerValue = computed(() => {
			if (model.value === void 0 || model.value === null) return;
			return String(model.value);
		});
		function onUpdate(next) {
			if (next === void 0 || next === null) {
				model.value = null;
				return;
			}
			if (typeof next === "string" || typeof next === "number") {
				model.value = next;
				return;
			}
			if (Array.isArray(next)) {
				const first = next[0];
				model.value = typeof first === "string" || typeof first === "number" ? first : null;
				return;
			}
			model.value = String(next);
		}
		return (_ctx, _cache) => {
			return openBlock(), createBlock(unref(FieldFrame_default), {
				label: __props.label,
				required: __props.required,
				"hide-label": __props.hideLabel,
				for: __props.id,
				"help-text": __props.helpText,
				errors: __props.errors
			}, {
				default: withCtx(() => [createVNode(unref(Select_default), {
					"model-value": triggerValue.value,
					disabled: __props.disabled || __props.readonly,
					name: __props.name,
					required: __props.required,
					"onUpdate:modelValue": onUpdate
				}, {
					default: withCtx(() => [createVNode(unref(SelectTrigger_default), {
						id: __props.id,
						"data-element-name": __props.name ?? void 0,
						class: normalizeClass(__props.errors.length ? "border-destructive ring-destructive" : "")
					}, {
						default: withCtx(() => [createVNode(unref(SelectValue_default), { placeholder: __props.placeholder ?? "Select…" }, null, 8, ["placeholder"])]),
						_: 1
					}, 8, [
						"id",
						"data-element-name",
						"class"
					]), createVNode(unref(SelectContent_default), null, {
						default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(normalised.value, (opt) => {
							return openBlock(), createBlock(unref(SelectItem_default), {
								key: opt.value,
								value: opt.value,
								disabled: opt.disabled
							}, {
								default: withCtx(() => [createTextVNode(toDisplayString(opt.label), 1)]),
								_: 2
							}, 1032, ["value", "disabled"]);
						}), 128))]),
						_: 1
					})]),
					_: 1
				}, 8, [
					"model-value",
					"disabled",
					"name",
					"required"
				])]),
				_: 1
			}, 8, [
				"label",
				"required",
				"hide-label",
				"for",
				"help-text",
				"errors"
			]);
		};
	}
});
//#endregion
//#region src/components/compositions/elements/option-select/SelectOption.vue
var SelectOption_exports = /* @__PURE__ */ __exportAll({ default: () => SelectOption_default });
var SelectOption_default = SelectOption_vue_vue_type_script_setup_true_lang_default;
//#endregion
export { SelectOption_exports as n, SelectOption_default as t };

//# sourceMappingURL=SelectOption-B1isIMM1.js.map