import { n as e, t } from "../../utils-CSEWuKHo.js";
import { n } from "../../svg-C7L0aW2M.js";
//#region src/primitives/select/native.ts
var r = class {
	el;
	selectEl;
	config;
	currentOptions;
	isDestroyed = !1;
	handleChange;
	constructor(r) {
		this.config = r, this.currentOptions = [...r.options], this.el = document.createElement("div"), this.el.className = "cmm-native-select", r.className && this.el.classList.add(r.className), this.selectEl = document.createElement("select"), this.selectEl.className = "cmm-native-select__select", this.selectEl.id = e("cmm-native-select"), r.name && (this.selectEl.name = r.name), r.required === !0 && (this.selectEl.required = !0), r.disabled === !0 && (this.selectEl.disabled = !0, this.el.classList.add("cmm-native-select--disabled"));
		let i = r.ariaLabel ?? "Select an option";
		this.selectEl.setAttribute("aria-label", i), this.populateOptions(), r.value !== void 0 && (this.selectEl.value = r.value);
		let a = document.createElement("span");
		a.className = "cmm-native-select__chevron", a.setAttribute("aria-hidden", "true"), n(a, {
			width: 12,
			height: 12,
			viewBox: "0 0 12 12",
			fill: "none"
		}, [{
			tag: "path",
			attrs: {
				d: "M3 4.5L6 7.5L9 4.5",
				stroke: "currentColor",
				"stroke-width": 1.5,
				"stroke-linecap": "round",
				"stroke-linejoin": "round"
			},
			children: []
		}]), this.el.appendChild(this.selectEl), this.el.appendChild(a), this.handleChange = () => {
			this.isDestroyed || this.config.onChange?.(this.selectEl.value);
		}, this.selectEl.addEventListener("change", this.handleChange), r.container !== void 0 && t(r.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.replaceChildren();
		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 { r as NativeSelect };

//# sourceMappingURL=native.js.map