import { i as e } from "../../sanitize-CDxuPfMB.js";
import { n as t, t as n } from "../../utils-C_mWfcFX.js";
//#region src/display/alert/index.ts
var r = {
	info: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"M12 16v-4\"/><path d=\"M12 8h.01\"/></svg>",
	success: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"m9 12 2 2 4-4\"/></svg>",
	warning: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z\"/><path d=\"M12 9v4\"/><path d=\"M12 17h.01\"/></svg>",
	error: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"m15 9-6 6\"/><path d=\"m9 9 6 6\"/></svg>"
}, i = class {
	el;
	alertId;
	descriptionEl;
	dismissBtn = null;
	dismissHandler;
	dismissBtnClickHandler = null;
	transitionEndHandler = null;
	constructor(i) {
		this.alertId = t("cmm-alert"), this.dismissHandler = i.onDismiss;
		let a = i.variant ?? "info";
		this.el = document.createElement("div"), this.el.id = this.alertId, this.el.className = this.buildClassName(a, i.className), this.el.setAttribute("role", "alert");
		let o = document.createElement("div");
		o.className = "cmm-alert__icon", o.setAttribute("aria-hidden", "true"), e(o, i.icon ?? r[a]), this.el.appendChild(o);
		let s = document.createElement("div");
		if (s.className = "cmm-alert__content", i.title !== void 0) {
			let e = document.createElement("div");
			e.className = "cmm-alert__title", e.textContent = i.title, s.appendChild(e);
		}
		if (this.descriptionEl = document.createElement("div"), this.descriptionEl.className = "cmm-alert__description", this.descriptionEl.textContent = i.description, s.appendChild(this.descriptionEl), this.el.appendChild(s), i.dismissible === !0) {
			this.dismissBtn = document.createElement("button"), this.dismissBtn.className = "cmm-alert__dismiss", this.dismissBtn.setAttribute("aria-label", "Dismiss"), this.dismissBtn.type = "button", this.dismissBtn.textContent = "×";
			let e = () => {
				this.dismiss();
			};
			this.dismissBtnClickHandler = e, this.dismissBtn.addEventListener("click", e), this.el.appendChild(this.dismissBtn);
		}
		let c = () => {
			this.el.classList.contains("cmm-alert--dismissed") && this.el.remove();
		};
		this.transitionEndHandler = c, this.el.addEventListener("transitionend", c), i.container !== void 0 && n(i.container).appendChild(this.el);
	}
	setDescription(e) {
		this.descriptionEl.textContent = e;
	}
	dismiss() {
		this.el.classList.add("cmm-alert--dismissed"), this.dismissHandler !== void 0 && this.dismissHandler();
	}
	destroy() {
		this.dismissBtn !== null && this.dismissBtnClickHandler !== null && this.dismissBtn.removeEventListener("click", this.dismissBtnClickHandler), this.transitionEndHandler !== null && this.el.removeEventListener("transitionend", this.transitionEndHandler), this.el.remove();
	}
	buildClassName(e, t) {
		let n = ["cmm-alert", `cmm-alert--${e}`];
		return t && n.push(t), n.join(" ");
	}
};
//#endregion
export { i as Alert };

//# sourceMappingURL=index.js.map