import { n as e, t } from "../../utils-C_mWfcFX.js";
//#region src/display/card/index.ts
var n = class {
	el;
	cardId;
	headerEl = null;
	bodyEl = null;
	footerEl = null;
	clickHandler;
	keydownHandler = null;
	constructor(n) {
		if (this.cardId = e("cmm-card"), this.clickHandler = n.onClick, this.el = document.createElement("div"), this.el.id = this.cardId, this.el.className = this.buildClassName(n), n.header !== void 0 && (this.headerEl = this.createSection("cmm-card__header", n.header), this.el.appendChild(this.headerEl)), n.body !== void 0 && (this.bodyEl = this.createSection("cmm-card__body", n.body), this.el.appendChild(this.bodyEl)), n.footer !== void 0 && (this.footerEl = this.createSection("cmm-card__footer", n.footer), this.el.appendChild(this.footerEl)), this.clickHandler !== void 0) {
			this.el.setAttribute("role", "button"), this.el.setAttribute("tabindex", "0"), this.el.classList.add("cmm-card--clickable"), this.el.addEventListener("click", this.clickHandler);
			let e = (e) => {
				(e.key === "Enter" || e.key === " ") && (e.preventDefault(), this.clickHandler !== void 0 && this.clickHandler());
			};
			this.keydownHandler = e, this.el.addEventListener("keydown", e);
		}
		n.container !== void 0 && t(n.container).appendChild(this.el);
	}
	setHeader(e) {
		this.headerEl === null ? (this.headerEl = this.createSection("cmm-card__header", e), this.el.insertBefore(this.headerEl, this.el.firstChild)) : this.setSectionContent(this.headerEl, e);
	}
	setBody(e) {
		this.bodyEl === null ? (this.bodyEl = this.createSection("cmm-card__body", e), this.footerEl === null ? this.el.appendChild(this.bodyEl) : this.el.insertBefore(this.bodyEl, this.footerEl)) : this.setSectionContent(this.bodyEl, e);
	}
	setFooter(e) {
		this.footerEl === null ? (this.footerEl = this.createSection("cmm-card__footer", e), this.el.appendChild(this.footerEl)) : this.setSectionContent(this.footerEl, e);
	}
	destroy() {
		this.clickHandler !== void 0 && this.el.removeEventListener("click", this.clickHandler), this.keydownHandler !== null && this.el.removeEventListener("keydown", this.keydownHandler), this.el.remove();
	}
	buildClassName(e) {
		let t = ["cmm-card"];
		return e.hoverable === !0 && t.push("cmm-card--hoverable"), e.bordered === !1 && t.push("cmm-card--no-border"), e.padding === !1 && t.push("cmm-card--no-padding"), e.className && t.push(e.className), t.join(" ");
	}
	createSection(e, t) {
		let n = document.createElement("div");
		return n.className = e, this.setSectionContent(n, t), n;
	}
	setSectionContent(e, t) {
		e.textContent = "", typeof t == "string" ? e.textContent = t : e.appendChild(t);
	}
};
//#endregion
export { n as Card };

//# sourceMappingURL=index.js.map