//#region src/components/detail-header/index.ts
function e(e) {
	if (typeof e == "string") {
		let t = document.querySelector(e);
		if (!t) throw Error(`DetailHeader: container not found for selector "${e}"`);
		return t;
	}
	return e;
}
function t(e) {
	if (e.startsWith("/") || e.startsWith("./") || e.startsWith("../") || e.startsWith("?") || e.startsWith("#")) return !e.startsWith("//");
	try {
		let t = new URL(e);
		return t.protocol === "http:" || t.protocol === "https:";
	} catch {
		return !1;
	}
}
var n = class {
	containerEl;
	rootEl;
	titleEl;
	subtitleEl;
	statusEl;
	actionsEl;
	breadcrumbEl;
	destroyed = !1;
	constructor(t) {
		this.containerEl = e(t.container), this.rootEl = document.createElement("div"), this.rootEl.className = "cmm-detail-header", t.breadcrumbs && t.breadcrumbs.length > 0 ? (this.breadcrumbEl = document.createElement("nav"), this.breadcrumbEl.className = "cmm-detail-header__breadcrumb", this.renderBreadcrumbs(t.breadcrumbs), this.containerEl.appendChild(this.breadcrumbEl)) : this.breadcrumbEl = null;
		let n = document.createElement("div");
		n.className = "cmm-detail-header__left", this.titleEl = document.createElement("h2"), this.titleEl.className = "cmm-detail-header__title", this.titleEl.textContent = t.title, n.appendChild(this.titleEl), this.subtitleEl = document.createElement("div"), this.subtitleEl.className = "cmm-detail-header__subtitle", t.subtitle && (this.subtitleEl.textContent = t.subtitle), n.appendChild(this.subtitleEl), this.rootEl.appendChild(n);
		let r = document.createElement("div");
		r.className = "cmm-detail-header__right", this.actionsEl = document.createElement("div"), this.actionsEl.className = "cmm-detail-header__actions", t.actions && this.renderActions(t.actions), r.appendChild(this.actionsEl), this.statusEl = document.createElement("span"), this.statusEl.className = "cmm-detail-header__status", t.status && this.renderStatus(t.status), r.appendChild(this.statusEl), this.rootEl.appendChild(r), this.containerEl.appendChild(this.rootEl);
	}
	setTitle(e) {
		this.titleEl.textContent = e;
	}
	setSubtitle(e) {
		this.subtitleEl.textContent = e;
	}
	setStatus(e) {
		e ? this.renderStatus(e) : this.statusEl.replaceChildren();
	}
	setActions(e) {
		this.renderActions(e);
	}
	destroy() {
		this.destroyed || (this.destroyed = !0, this.breadcrumbEl?.parentNode && this.breadcrumbEl.parentNode.removeChild(this.breadcrumbEl), this.rootEl.parentNode && this.rootEl.parentNode.removeChild(this.rootEl));
	}
	renderBreadcrumbs(e) {
		if (!this.breadcrumbEl) return;
		let n = document.createDocumentFragment();
		for (let [r, i] of e.entries()) {
			let a = r === e.length - 1;
			if (a) {
				let e = document.createElement("span");
				e.className = "cmm-detail-header__breadcrumb-current", e.textContent = i.label, n.appendChild(e);
			} else if (i.href && t(i.href)) {
				let e = document.createElement("a");
				e.className = "cmm-detail-header__breadcrumb-link", e.textContent = i.label, e.setAttribute("href", i.href), n.appendChild(e);
			} else {
				let e = document.createElement("span");
				e.textContent = i.label, n.appendChild(e);
			}
			if (!a) {
				let e = document.createElement("span");
				e.className = "cmm-detail-header__breadcrumb-sep", e.textContent = "/", n.appendChild(e);
			}
		}
		this.breadcrumbEl.replaceChildren(n);
	}
	renderStatus(e) {
		let t = e.variant ?? "default";
		this.statusEl.className = `cmm-detail-header__status cmm-detail-header__status--${t}`;
		let n = [];
		if (e.dot !== !1) {
			let e = document.createElement("span");
			e.className = `cmm-detail-header__status-dot cmm-detail-header__status-dot--${t}`, n.push(e);
		}
		n.push(document.createTextNode(e.label)), this.statusEl.replaceChildren(...n);
	}
	renderActions(e) {
		this.actionsEl.replaceChildren();
		for (let t of e) {
			let e = document.createElement("button");
			e.className = `cmm-detail-header__action-btn cmm-detail-header__action-btn--${t.variant ?? "ghost"}`, e.textContent = t.label, t.disabled && (e.disabled = !0), e.addEventListener("click", t.onClick), this.actionsEl.appendChild(e);
		}
	}
};
//#endregion
export { n as DetailHeader };

//# sourceMappingURL=index.js.map