import { n as __exportAll } from "./chunk-B-1-B7_t.js";
import { c as ComboboxAnchor_default, i as ComboboxInput_default, l as Combobox_default, n as ComboboxItemIndicator_default, o as ComboboxEmpty_default, r as ComboboxItem_default, s as ComboboxContent_default } from "./combobox-D0Svg8GU.js";
import { t as FieldFrame_default } from "./field-frame-DhCOWcMP.js";
import { Fragment, computed, createBlock, createElementBlock, createTextVNode, createVNode, defineComponent, mergeModels, normalizeClass, openBlock, ref, renderList, toDisplayString, unref, useModel, withCtx } from "vue";
import { Search } from "@lucide/vue";
//#region src/components/compositions/elements/option-select/AutoCompleteOption.vue?vue&type=script&setup=true&lang.ts
var AutoCompleteOption_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "AutoCompleteOption",
	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: () => [] },
		minSearchLength: { default: 0 }
	}, {
		"modelValue": {},
		"modelModifiers": {}
	}),
	emits: ["update:modelValue"],
	setup(__props) {
		/**
		* Props-driven autocomplete composition. Wraps the shadcn Combobox
		* primitive with client-side search filtering.
		*
		*   <AutoCompleteOption v-model="city" :options="[...]" label="City" />
		*/
		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 query = ref("");
		const filtered = computed(() => {
			const q = query.value.trim().toLowerCase();
			if (q.length < props.minSearchLength) return normalised.value;
			if (q === "") return normalised.value;
			return normalised.value.filter((o) => o.label.toLowerCase().includes(q));
		});
		const currentValue = computed(() => {
			if (model.value === void 0 || model.value === null) return;
			return String(model.value);
		});
		function onUpdate(next) {
			if (Array.isArray(next)) {
				model.value = next[0] === void 0 ? null : next[0];
				return;
			}
			model.value = next === void 0 ? null : 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(Combobox_default), {
					"model-value": currentValue.value,
					disabled: __props.disabled || __props.readonly,
					"onUpdate:modelValue": onUpdate
				}, {
					default: withCtx(() => [createVNode(unref(ComboboxAnchor_default), {
						"data-element-name": __props.name ?? void 0,
						class: normalizeClass(__props.errors.length ? "border-destructive ring-destructive" : "")
					}, {
						default: withCtx(() => [createVNode(unref(Search), { class: "mr-2 h-4 w-4 shrink-0 opacity-50" }), createVNode(unref(ComboboxInput_default), {
							id: __props.id,
							modelValue: query.value,
							"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => query.value = $event),
							placeholder: __props.placeholder ?? "Search…"
						}, null, 8, [
							"id",
							"modelValue",
							"placeholder"
						])]),
						_: 1
					}, 8, ["data-element-name", "class"]), createVNode(unref(ComboboxContent_default), null, {
						default: withCtx(() => [createVNode(unref(ComboboxEmpty_default), null, {
							default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("No matches.", -1)])]),
							_: 1
						}), (openBlock(true), createElementBlock(Fragment, null, renderList(filtered.value, (opt) => {
							return openBlock(), createBlock(unref(ComboboxItem_default), {
								key: opt.value,
								value: opt.value,
								disabled: opt.disabled
							}, {
								default: withCtx(() => [createVNode(unref(ComboboxItemIndicator_default)), createTextVNode(" " + toDisplayString(opt.label), 1)]),
								_: 2
							}, 1032, ["value", "disabled"]);
						}), 128))]),
						_: 1
					})]),
					_: 1
				}, 8, ["model-value", "disabled"])]),
				_: 1
			}, 8, [
				"label",
				"required",
				"hide-label",
				"for",
				"help-text",
				"errors"
			]);
		};
	}
});
//#endregion
//#region src/components/compositions/elements/option-select/AutoCompleteOption.vue
var AutoCompleteOption_exports = /* @__PURE__ */ __exportAll({ default: () => AutoCompleteOption_default });
var AutoCompleteOption_default = AutoCompleteOption_vue_vue_type_script_setup_true_lang_default;
//#endregion
export { AutoCompleteOption_exports as n, AutoCompleteOption_default as t };

//# sourceMappingURL=AutoCompleteOption-Bw--WwLh.js.map