import { n as e, t } from "../../utils-C_mWfcFX.js";
//#region src/primitives/switch/index.ts
var n = class {
	el;
	inputEl;
	trackEl;
	thumbEl;
	labelEl = null;
	switchId;
	currentSize;
	changeHandler;
	onChangeCallback;
	constructor(n) {
		this.switchId = e("cmm-switch"), this.currentSize = n.size ?? "md", this.onChangeCallback = n.onChange, this.el = document.createElement("label"), this.el.className = this.buildClassName(n.className), this.inputEl = document.createElement("input"), this.inputEl.type = "checkbox", this.inputEl.className = "cmm-switch__input", this.inputEl.id = this.switchId, n.checked === !0 && (this.inputEl.checked = !0), n.ariaLabel !== void 0 && this.inputEl.setAttribute("aria-label", n.ariaLabel), this.trackEl = document.createElement("span"), this.trackEl.className = "cmm-switch__track", this.thumbEl = document.createElement("span"), this.thumbEl.className = "cmm-switch__thumb", this.trackEl.appendChild(this.thumbEl), this.el.appendChild(this.inputEl), this.el.appendChild(this.trackEl), n.label !== void 0 && (this.labelEl = document.createElement("span"), this.labelEl.className = "cmm-switch__label", this.labelEl.textContent = n.label, this.el.appendChild(this.labelEl)), n.disabled === !0 && this.setDisabled(!0), this.changeHandler = () => {
			this.onChangeCallback?.(this.inputEl.checked);
		}, this.inputEl.addEventListener("change", this.changeHandler), n.container !== void 0 && t(n.container).appendChild(this.el);
	}
	isChecked() {
		return this.inputEl.checked;
	}
	setChecked(e) {
		this.inputEl.checked = e;
	}
	toggle() {
		this.inputEl.checked = !this.inputEl.checked, this.onChangeCallback?.(this.inputEl.checked);
	}
	setDisabled(e) {
		this.inputEl.disabled = e, e ? this.el.classList.add("cmm-switch--disabled") : this.el.classList.remove("cmm-switch--disabled");
	}
	setSize(e) {
		this.el.classList.remove(`cmm-switch--${this.currentSize}`), this.currentSize = e, this.el.classList.add(`cmm-switch--${this.currentSize}`);
	}
	destroy() {
		this.inputEl.removeEventListener("change", this.changeHandler), this.el.remove();
	}
	buildClassName(e) {
		let t = ["cmm-switch", `cmm-switch--${this.currentSize}`];
		return e && t.push(e), t.join(" ");
	}
};
//#endregion
export { n as Switch };

//# sourceMappingURL=index.js.map