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, createElementVNode, createTextVNode, createVNode, defineComponent, mergeModels, openBlock, ref, renderList, toDisplayString, unref, useModel, withCtx } from "vue";
import { Code2 } from "@lucide/vue";
//#region src/components/compositions/elements/picker/DataModelPicker.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = { class: "font-mono" };
var DataModelPicker_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "DataModelPicker",
	props: /* @__PURE__ */ mergeModels({
		modelValue: {},
		id: {},
		name: {},
		label: {},
		hideLabel: { type: Boolean },
		placeholder: {},
		required: { type: Boolean },
		readonly: { type: Boolean },
		disabled: { type: Boolean },
		helpText: {},
		errors: { default: () => [] },
		dataModelKeys: { default: () => [] }
	}, {
		"modelValue": {},
		"modelModifiers": {}
	}),
	emits: ["update:modelValue"],
	setup(__props) {
		/**
		* Props-driven data-model picker composition. Searchable combobox over a
		* list of field-path keys supplied via `dataModelKeys`. Used by the
		* FormBuilder inspector to pick a data-model key; the eventual async
		* lookup service will swap in the same surface area.
		*
		*   <DataModelPicker
		*     v-model="key"
		*     label="Field"
		*     :data-model-keys="['first_name', 'last_name', 'email']"
		*   />
		*/
		const props = __props;
		const model = useModel(__props, "modelValue");
		const query = ref("");
		const filtered = computed(() => {
			const q = query.value.trim().toLowerCase();
			const keys = Array.isArray(props.dataModelKeys) ? props.dataModelKeys : [];
			if (!q) return keys.slice(0, 200);
			return keys.filter((k) => k.toLowerCase().includes(q)).slice(0, 200);
		});
		function onSelect(value) {
			model.value = typeof value === "string" ? value : "";
		}
		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": model.value ?? "",
					disabled: __props.disabled,
					"onUpdate:modelValue": onSelect
				}, {
					default: withCtx(() => [createVNode(unref(ComboboxAnchor_default), {
						"data-element-name": __props.name ?? void 0,
						"data-readonly": __props.readonly || void 0
					}, {
						default: withCtx(() => [createVNode(unref(Code2), { class: "mr-2 size-4 shrink-0 opacity-50" }), createVNode(unref(ComboboxInput_default), {
							modelValue: query.value,
							"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => query.value = $event),
							placeholder: __props.placeholder ?? "data.key.path",
							readonly: __props.readonly,
							required: __props.required,
							class: "font-mono text-sm"
						}, null, 8, [
							"modelValue",
							"placeholder",
							"readonly",
							"required"
						])]),
						_: 1
					}, 8, ["data-element-name", "data-readonly"]), createVNode(unref(ComboboxContent_default), null, {
						default: withCtx(() => [createVNode(unref(ComboboxEmpty_default), null, {
							default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("No fields match.", -1)])]),
							_: 1
						}), (openBlock(true), createElementBlock(Fragment, null, renderList(filtered.value, (key) => {
							return openBlock(), createBlock(unref(ComboboxItem_default), {
								key,
								value: key
							}, {
								default: withCtx(() => [createVNode(unref(ComboboxItemIndicator_default)), createElementVNode("span", _hoisted_1, toDisplayString(key), 1)]),
								_: 2
							}, 1032, ["value"]);
						}), 128))]),
						_: 1
					})]),
					_: 1
				}, 8, ["model-value", "disabled"])]),
				_: 1
			}, 8, [
				"label",
				"required",
				"hide-label",
				"for",
				"help-text",
				"errors"
			]);
		};
	}
});
//#endregion
//#region src/components/compositions/elements/picker/DataModelPicker.vue
var DataModelPicker_exports = /* @__PURE__ */ __exportAll({ default: () => DataModelPicker_default });
var DataModelPicker_default = DataModelPicker_vue_vue_type_script_setup_true_lang_default;
//#endregion
export { DataModelPicker_exports as n, DataModelPicker_default as t };

//# sourceMappingURL=DataModelPicker-CEVbJbVY.js.map