import { n as e, t } from "../../utils-C_mWfcFX.js";
import { Checkbox as n } from "./index.js";
//#region src/primitives/checkbox/group.ts
var r = class {
	el;
	checkboxes = [];
	config;
	selectedValues;
	isDestroyed = !1;
	constructor(n) {
		this.config = n, this.selectedValues = new Set(n.value ?? []);
		let r = n.orientation ?? "vertical";
		this.el = document.createElement("div"), this.el.className = `cmm-checkbox-group cmm-checkbox-group--${r}`, this.el.setAttribute("role", "group"), this.el.id = e("cmm-checkbox-group"), n.ariaLabel && this.el.setAttribute("aria-label", n.ariaLabel), n.className && this.el.classList.add(n.className), this.buildCheckboxes(), n.container !== void 0 && t(n.container).appendChild(this.el);
	}
	getValue() {
		return [...this.selectedValues];
	}
	setValue(e) {
		this.selectedValues = new Set(e), this.syncCheckboxes();
	}
	setDisabled(e) {
		for (let t of this.checkboxes) t.setDisabled(e);
	}
	destroy() {
		this.isDestroyed = !0;
		for (let e of this.checkboxes) e.destroy();
		this.checkboxes.length = 0, this.el.remove();
	}
	buildCheckboxes() {
		for (let e of this.checkboxes) e.destroy();
		this.checkboxes.length = 0;
		for (let e of this.config.options) {
			let t = this.selectedValues.has(e.value), r = this.config.disabled === !0 || e.disabled === !0, i = new n({
				label: e.label,
				value: e.value,
				checked: t,
				disabled: r,
				onChange: (t) => {
					this.isDestroyed || (t ? this.selectedValues.add(e.value) : this.selectedValues.delete(e.value), this.config.onChange?.([...this.selectedValues]));
				}
			});
			this.checkboxes.push(i), this.el.appendChild(i.el);
		}
	}
	syncCheckboxes() {
		for (let e of this.checkboxes) {
			let t = e.el.querySelector("input");
			if (t !== null) {
				let n = t.value;
				e.setChecked(this.selectedValues.has(n));
			}
		}
	}
};
//#endregion
export { r as CheckboxGroup };

//# sourceMappingURL=group.js.map