import { t as e } from "../../sanitize-CDxuPfMB.js";
//#region src/components/detail-header/index.ts
function t(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 n(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 r = class {
	containerEl;
	rootEl;
	titleEl;
	subtitleEl;
	statusEl;
	actionsEl;
	breadcrumbEl;
	destroyed = !1;
	constructor(e) {
		this.containerEl = t(e.container), this.rootEl = document.createElement("div"), this.rootEl.className = "cmm-detail-header", e.breadcrumbs && e.breadcrumbs.length > 0 ? (this.breadcrumbEl = document.createElement("nav"), this.breadcrumbEl.className = "cmm-detail-header__breadcrumb", this.renderBreadcrumbs(e.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 = e.title, n.appendChild(this.titleEl), this.subtitleEl = document.createElement("div"), this.subtitleEl.className = "cmm-detail-header__subtitle", e.subtitle && (this.subtitleEl.textContent = e.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", e.actions && this.renderActions(e.actions), r.appendChild(this.actionsEl), this.statusEl = document.createElement("span"), this.statusEl.className = "cmm-detail-header__status", e.status && this.renderStatus(e.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.innerHTML = "";
	}
	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 t = 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, t.appendChild(e);
			} else if (i.href && n(i.href)) {
				let e = document.createElement("a");
				e.className = "cmm-detail-header__breadcrumb-link", e.textContent = i.label, e.setAttribute("href", i.href), t.appendChild(e);
			} else {
				let e = document.createElement("span");
				e.textContent = i.label, t.appendChild(e);
			}
			if (!a) {
				let e = document.createElement("span");
				e.className = "cmm-detail-header__breadcrumb-sep", e.textContent = "/", t.appendChild(e);
			}
		}
		this.breadcrumbEl.replaceChildren(t);
	}
	renderStatus(t) {
		let n = t.variant ?? "default", r = t.dot === !1 ? "" : `<span class="cmm-detail-header__status-dot cmm-detail-header__status-dot--${n}"></span>`;
		this.statusEl.className = `cmm-detail-header__status cmm-detail-header__status--${n}`, this.statusEl.innerHTML = `${r}${e(t.label)}`;
	}
	renderActions(e) {
		this.actionsEl.innerHTML = "";
		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 { r as DetailHeader };

//# sourceMappingURL=index.js.map