import { n as __exportAll } from "./chunk-B-1-B7_t.js";
import { n as Badge_default } from "./badge-BbQrSqE-.js";
import { t as FieldFrame_default } from "./field-frame-DhCOWcMP.js";
import { Fragment, computed, createBlock, createElementBlock, createElementVNode, createTextVNode, defineComponent, mergeModels, normalizeClass, openBlock, renderList, toDisplayString, unref, useModel, withCtx } from "vue";
//#region src/components/compositions/elements/option-select/ListOption.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = ["data-element-name"];
var ListOption_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "ListOption",
	props: /* @__PURE__ */ mergeModels({
		modelValue: {},
		options: { default: () => [] },
		id: {},
		name: {},
		label: {},
		hideLabel: { type: Boolean },
		required: { type: Boolean },
		readonly: { type: Boolean },
		disabled: { type: Boolean },
		helpText: {},
		errors: { default: () => [] },
		clearable: { type: Boolean }
	}, {
		"modelValue": {},
		"modelModifiers": {}
	}),
	emits: ["update:modelValue"],
	setup(__props) {
		/**
		* Props-driven single-select chip list. Each option becomes a clickable
		* Badge. When `clearable` is true, re-clicking the active chip clears
		* the selection.
		*
		*   <ListOption v-model="status" :options="[...]" label="Status" />
		*/
		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 currentValue = computed(() => {
			if (model.value === void 0 || model.value === null) return;
			return String(model.value);
		});
		function isActive(val) {
			return currentValue.value === val;
		}
		function selectValue(opt) {
			if (opt.disabled || props.disabled || props.readonly) return;
			if (currentValue.value === opt.value && props.clearable) {
				model.value = null;
				return;
			}
			model.value = opt.value;
		}
		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: "flex flex-wrap gap-2",
					"data-element-name": __props.name ?? void 0
				}, [(openBlock(true), createElementBlock(Fragment, null, renderList(normalised.value, (opt) => {
					return openBlock(), createBlock(unref(Badge_default), {
						key: opt.value,
						as: "button",
						type: "button",
						variant: isActive(opt.value) ? "default" : "outline",
						size: "lg",
						class: normalizeClass(["cursor-pointer transition-colors", opt.disabled || __props.disabled || __props.readonly ? "pointer-events-none opacity-50" : ""]),
						"data-active": isActive(opt.value),
						"aria-pressed": isActive(opt.value),
						onClick: ($event) => selectValue(opt)
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(opt.label), 1)]),
						_: 2
					}, 1032, [
						"variant",
						"class",
						"data-active",
						"aria-pressed",
						"onClick"
					]);
				}), 128))], 8, _hoisted_1)]),
				_: 1
			}, 8, [
				"label",
				"required",
				"hide-label",
				"help-text",
				"errors"
			]);
		};
	}
});
//#endregion
//#region src/components/compositions/elements/option-select/ListOption.vue
var ListOption_exports = /* @__PURE__ */ __exportAll({ default: () => ListOption_default });
var ListOption_default = ListOption_vue_vue_type_script_setup_true_lang_default;
//#endregion
export { ListOption_exports as n, ListOption_default as t };

//# sourceMappingURL=ListOption-CYvYHoZ8.js.map