import { n as e, t } from "../../utils-C_mWfcFX.js";
//#region src/primitives/select/native.ts
var n = class {
	el;
	selectEl;
	config;
	currentOptions;
	isDestroyed = !1;
	handleChange;
	constructor(n) {
		this.config = n, this.currentOptions = [...n.options], this.el = document.createElement("div"), this.el.className = "cmm-native-select", n.className && this.el.classList.add(n.className), this.selectEl = document.createElement("select"), this.selectEl.className = "cmm-native-select__select", this.selectEl.id = e("cmm-native-select"), n.name && (this.selectEl.name = n.name), n.required === !0 && (this.selectEl.required = !0), n.disabled === !0 && (this.selectEl.disabled = !0, this.el.classList.add("cmm-native-select--disabled"));
		let r = n.ariaLabel ?? "Select an option";
		this.selectEl.setAttribute("aria-label", r), this.populateOptions(), n.value !== void 0 && (this.selectEl.value = n.value);
		let i = document.createElement("span");
		i.className = "cmm-native-select__chevron", i.setAttribute("aria-hidden", "true"), i.innerHTML = "<svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\" fill=\"none\"><path d=\"M3 4.5L6 7.5L9 4.5\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>", this.el.appendChild(this.selectEl), this.el.appendChild(i), this.handleChange = () => {
			this.isDestroyed || this.config.onChange?.(this.selectEl.value);
		}, this.selectEl.addEventListener("change", this.handleChange), n.container !== void 0 && t(n.container).appendChild(this.el);
	}
	getValue() {
		return this.selectEl.value;
	}
	setValue(e) {
		this.selectEl.value = e;
	}
	setOptions(e) {
		this.currentOptions = [...e], this.populateOptions();
	}
	setDisabled(e) {
		this.selectEl.disabled = e, e ? this.el.classList.add("cmm-native-select--disabled") : this.el.classList.remove("cmm-native-select--disabled");
	}
	destroy() {
		this.isDestroyed = !0, this.selectEl.removeEventListener("change", this.handleChange), this.el.remove();
	}
	populateOptions() {
		this.selectEl.innerHTML = "";
		let e = /* @__PURE__ */ new Map(), t = [];
		for (let n of this.currentOptions) if (n.group) {
			let t = e.get(n.group);
			t === void 0 ? e.set(n.group, [n]) : t.push(n);
		} else t.push(n);
		for (let e of t) this.selectEl.appendChild(this.createOptionEl(e));
		for (let [t, n] of e) {
			let e = document.createElement("optgroup");
			e.label = t;
			for (let t of n) e.appendChild(this.createOptionEl(t));
			this.selectEl.appendChild(e);
		}
	}
	createOptionEl(e) {
		let t = document.createElement("option");
		return t.value = e.value, t.textContent = e.label, e.disabled === !0 && (t.disabled = !0), t;
	}
};
//#endregion
export { n as NativeSelect };

//# sourceMappingURL=native.js.map