import { n as e, t } from "../../utils-C_mWfcFX.js";
//#region src/primitives/checkbox/index.ts
var n = class {
	el;
	inputEl;
	boxEl;
	labelEl;
	config;
	isDestroyed = !1;
	handleChange;
	constructor(n) {
		this.config = n, this.el = document.createElement("label"), this.el.className = "cmm-checkbox", n.className && this.el.classList.add(n.className), n.disabled === !0 && this.el.classList.add("cmm-checkbox--disabled"), this.inputEl = document.createElement("input"), this.inputEl.type = "checkbox", this.inputEl.className = "cmm-checkbox__input", this.inputEl.id = e("cmm-checkbox"), n.name && (this.inputEl.name = n.name), n.value && (this.inputEl.value = n.value), n.checked === !0 && (this.inputEl.checked = !0), n.indeterminate === !0 && (this.inputEl.indeterminate = !0), n.disabled === !0 && (this.inputEl.disabled = !0), n.ariaLabel && this.inputEl.setAttribute("aria-label", n.ariaLabel), this.boxEl = document.createElement("span"), this.boxEl.className = "cmm-checkbox__box", this.boxEl.setAttribute("aria-hidden", "true"), this.labelEl = document.createElement("span"), this.labelEl.className = "cmm-checkbox__label", n.label && (this.labelEl.textContent = n.label), this.el.appendChild(this.inputEl), this.el.appendChild(this.boxEl), this.el.appendChild(this.labelEl), this.handleChange = () => {
			this.isDestroyed || (this.inputEl.indeterminate = !1, this.config.onChange?.(this.inputEl.checked));
		}, this.inputEl.addEventListener("change", this.handleChange), n.container !== void 0 && t(n.container).appendChild(this.el);
	}
	isChecked() {
		return this.inputEl.checked;
	}
	setChecked(e) {
		this.inputEl.checked = e, this.inputEl.indeterminate = !1;
	}
	setIndeterminate(e) {
		this.inputEl.indeterminate = e;
	}
	setDisabled(e) {
		this.inputEl.disabled = e, e ? this.el.classList.add("cmm-checkbox--disabled") : this.el.classList.remove("cmm-checkbox--disabled");
	}
	toggle() {
		this.inputEl.checked = !this.inputEl.checked, this.inputEl.indeterminate = !1, this.config.onChange?.(this.inputEl.checked);
	}
	destroy() {
		this.isDestroyed = !0, this.inputEl.removeEventListener("change", this.handleChange), this.el.remove();
	}
};
//#endregion
export { n as Checkbox };

//# sourceMappingURL=index.js.map