import { n as e, t } from "./utils-C_mWfcFX.js";
//#region src/display/avatar/avatar-group.ts
var n = class {
	el;
	maxCount;
	groupSize;
	avatars = [];
	overflowEl = null;
	constructor(e) {
		this.maxCount = e.max, this.groupSize = e.size ?? "md", this.el = document.createElement("div"), this.el.className = this.buildClassName(e.className), this.el.setAttribute("role", "group"), this.el.setAttribute("aria-label", "Avatar group"), e.container !== void 0 && t(e.container).appendChild(this.el);
	}
	add(e) {
		this.avatars.push(e), this.render();
	}
	setAvatars(e) {
		this.avatars = [...e], this.render();
	}
	destroy() {
		this.el.remove();
	}
	buildClassName(e) {
		let t = ["cmm-avatar-group", `cmm-avatar-group--${this.groupSize}`];
		return e && t.push(e), t.join(" ");
	}
	render() {
		this.el.innerHTML = "", this.overflowEl = null;
		let e = this.avatars.length, t = this.maxCount !== void 0 && this.maxCount < e ? this.maxCount : e;
		for (let e = 0; e < t; e++) {
			let t = this.avatars[e];
			t !== void 0 && this.el.appendChild(t.el);
		}
		let n = e - t;
		n > 0 && (this.overflowEl = document.createElement("span"), this.overflowEl.className = "cmm-avatar-group__overflow", this.overflowEl.textContent = `+${String(n)}`, this.overflowEl.setAttribute("aria-label", `${String(n)} more`), this.el.appendChild(this.overflowEl));
	}
}, r = "<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=\"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2\"/><circle cx=\"12\" cy=\"7\" r=\"4\"/></svg>";
function i(e) {
	let t = e.trim().split(/\s+/), n = t[0], r = t[1];
	if (n === void 0) return "";
	let i = n[0] ?? "";
	return r === void 0 ? i.toUpperCase() : `${i}${r[0] ?? ""}`.toUpperCase();
}
var a = class {
	el;
	avatarId;
	currentSize;
	currentShape;
	currentSrc;
	currentName;
	contentEl;
	statusEl = null;
	constructor(n) {
		this.avatarId = e("cmm-avatar"), this.currentSize = n.size ?? "md", this.currentShape = n.shape ?? "circle", this.currentSrc = n.src, this.currentName = n.name, this.el = document.createElement("div"), this.el.id = this.avatarId, this.el.className = this.buildClassName(n.className), n.decorative === !0 ? this.el.setAttribute("role", "presentation") : (this.el.setAttribute("role", "img"), this.el.setAttribute("aria-label", n.alt ?? n.name ?? "User avatar")), this.contentEl = this.createContent(), this.el.appendChild(this.contentEl), n.status !== void 0 && (this.statusEl = this.createStatusEl(n.status), this.el.appendChild(this.statusEl)), n.container !== void 0 && t(n.container).appendChild(this.el);
	}
	setSrc(e) {
		this.currentSrc = e, this.rebuildContent();
	}
	setName(e) {
		this.currentName = e, this.currentSrc === void 0 && this.rebuildContent(), this.el.setAttribute("aria-label", e);
	}
	setStatus(e) {
		this.statusEl !== null && (this.statusEl.remove(), this.statusEl = null), e !== null && (this.statusEl = this.createStatusEl(e), this.el.appendChild(this.statusEl));
	}
	destroy() {
		this.el.remove();
	}
	buildClassName(e) {
		let t = [
			"cmm-avatar",
			`cmm-avatar--${this.currentSize}`,
			`cmm-avatar--${this.currentShape}`
		];
		return e && t.push(e), t.join(" ");
	}
	createContent() {
		return this.currentSrc === void 0 ? this.currentName ? this.createInitialsEl(this.currentName) : this.createDefaultIconEl() : this.createImageEl(this.currentSrc);
	}
	createImageEl(e) {
		let t = document.createElement("img");
		return t.className = "cmm-avatar__image", t.src = e, t.alt = "", t.setAttribute("aria-hidden", "true"), t.addEventListener("error", () => {
			this.currentSrc = void 0, this.rebuildContent();
		}), t;
	}
	createInitialsEl(e) {
		let t = document.createElement("span");
		return t.className = "cmm-avatar__initials", t.setAttribute("aria-hidden", "true"), t.textContent = i(e), t;
	}
	createDefaultIconEl() {
		let e = document.createElement("span");
		return e.className = "cmm-avatar__icon", e.setAttribute("aria-hidden", "true"), e.innerHTML = r, e;
	}
	createStatusEl(e) {
		let t = document.createElement("span");
		return t.className = `cmm-avatar__status cmm-avatar__status--${e}`, t.setAttribute("aria-hidden", "true"), t;
	}
	rebuildContent() {
		this.contentEl.remove(), this.contentEl = this.createContent(), this.statusEl === null ? this.el.appendChild(this.contentEl) : this.el.insertBefore(this.contentEl, this.statusEl);
	}
};
//#endregion
export { n, a as t };

//# sourceMappingURL=avatar-CZGZhjvv.js.map