import { t as e } from "./purify.es-Dsqc2y0I.js";
import { n as t, t as n } from "./utils-C_mWfcFX.js";
//#region src/primitives/button/button-group.ts
var r = class {
	el;
	constructor(e) {
		let t = e.orientation ?? "horizontal";
		this.el = document.createElement("div"), this.el.className = `cmm-btn-group cmm-btn-group--${t}`, this.el.setAttribute("role", "group"), e.className && this.el.classList.add(e.className), e.container !== void 0 && n(e.container).appendChild(this.el);
	}
	add(e) {
		this.el.appendChild(e.el);
	}
	remove(e) {
		this.el.contains(e.el) && this.el.removeChild(e.el);
	}
	destroy() {
		this.el.remove();
	}
}, i = class {
	el;
	labelEl;
	iconEl = null;
	spinnerEl = null;
	loadingTextEl = null;
	btnId;
	currentVariant;
	currentSize;
	isLoading;
	clickHandler;
	constructor(r) {
		this.btnId = t("cmm-btn"), this.currentVariant = r.variant ?? "primary", this.currentSize = r.size ?? "md", this.isLoading = r.loading === !0, this.clickHandler = r.onClick, this.el = document.createElement("button"), this.el.id = this.btnId, this.el.type = r.type ?? "button", this.el.className = this.buildClassName(r.className), r.ariaLabel !== void 0 && this.el.setAttribute("aria-label", r.ariaLabel), (r.disabled === !0 || this.isLoading) && (this.el.disabled = !0, this.el.setAttribute("aria-disabled", "true")), this.labelEl = document.createElement("span"), this.labelEl.className = "cmm-btn__label", r.label !== void 0 && (this.labelEl.textContent = r.label), r.icon !== void 0 && (this.iconEl = document.createElement("span"), this.iconEl.className = "cmm-btn__icon", this.iconEl.innerHTML = e.sanitize(r.icon, { USE_PROFILES: { svg: !0 } })), this.buildContent(r.iconPosition ?? "left"), this.isLoading && this.applyLoadingState(), this.clickHandler !== void 0 && this.el.addEventListener("click", this.clickHandler), r.container !== void 0 && n(r.container).appendChild(this.el);
	}
	setLabel(e) {
		this.labelEl.textContent = e;
	}
	setDisabled(e) {
		this.el.disabled = e || this.isLoading, e ? this.el.setAttribute("aria-disabled", "true") : this.isLoading || this.el.removeAttribute("aria-disabled");
	}
	setLoading(e) {
		this.isLoading = e, e ? (this.el.classList.add("cmm-btn--loading"), this.el.disabled = !0, this.el.setAttribute("aria-disabled", "true"), this.applyLoadingState()) : (this.el.classList.remove("cmm-btn--loading"), this.el.disabled = !1, this.el.removeAttribute("aria-disabled"), this.removeLoadingState());
	}
	setVariant(e) {
		this.el.classList.remove(`cmm-btn--${this.currentVariant}`), this.currentVariant = e, this.el.classList.add(`cmm-btn--${this.currentVariant}`);
	}
	destroy() {
		this.clickHandler !== void 0 && this.el.removeEventListener("click", this.clickHandler), this.el.remove();
	}
	buildClassName(e) {
		let t = [
			"cmm-btn",
			`cmm-btn--${this.currentVariant}`,
			`cmm-btn--${this.currentSize}`
		];
		return this.isLoading && t.push("cmm-btn--loading"), e && t.push(e), t.join(" ");
	}
	buildContent(e) {
		this.el.innerHTML = "", this.iconEl !== null && e === "left" && this.el.appendChild(this.iconEl), this.el.appendChild(this.labelEl), this.iconEl !== null && e === "right" && this.el.appendChild(this.iconEl);
	}
	applyLoadingState() {
		this.spinnerEl === null && (this.spinnerEl = document.createElement("span"), this.spinnerEl.className = "cmm-btn__spinner", this.spinnerEl.setAttribute("aria-hidden", "true"), this.el.insertBefore(this.spinnerEl, this.el.firstChild), this.loadingTextEl = document.createElement("span"), this.loadingTextEl.className = "cmm-sr-only", this.loadingTextEl.textContent = "Loading", this.loadingTextEl.style.cssText = "\n      position: absolute;\n      width: 1px;\n      height: 1px;\n      padding: 0;\n      margin: -1px;\n      overflow: hidden;\n      clip: rect(0, 0, 0, 0);\n      white-space: nowrap;\n      border: 0;\n    ", this.el.insertBefore(this.loadingTextEl, this.el.firstChild), this.el.setAttribute("aria-busy", "true"));
	}
	removeLoadingState() {
		this.spinnerEl !== null && (this.spinnerEl.remove(), this.spinnerEl = null), this.loadingTextEl !== null && (this.loadingTextEl.remove(), this.loadingTextEl = null), this.el.removeAttribute("aria-busy");
	}
};
//#endregion
export { r as n, i as t };

//# sourceMappingURL=button-19KWzy7c.js.map