import { getIconSvgInner as e } from "../icons/index.js";
import { o as t } from "../sanitize-uWpY18N9.js";
import { t as n } from "../utils-CSEWuKHo.js";
//#region src/layout/app-shell.ts
function r(n, r) {
	let i = "http://www.w3.org/2000/svg", a = document.createElementNS(i, "svg");
	a.setAttribute("xmlns", i), a.setAttribute("width", "16"), a.setAttribute("height", "16"), a.setAttribute("viewBox", "0 0 24 24"), a.setAttribute("fill", "none"), a.setAttribute("stroke", "currentColor"), a.setAttribute("stroke-width", "2"), a.setAttribute("stroke-linecap", "round"), a.setAttribute("stroke-linejoin", "round"), a.setAttribute("aria-hidden", "true");
	let o = e(n, r);
	return o && t(a, o), a;
}
function i(e) {
	let t = e.trim().split(/\s+/).filter(Boolean);
	return t.length >= 2 ? `${t[0]?.charAt(0) ?? ""}${t[t.length - 1]?.charAt(0) ?? ""}`.toUpperCase() : e.slice(0, 2).toUpperCase();
}
function a(e, t) {
	if (t === void 0) return;
	let n = Array.isArray(t) ? t : [t];
	for (let t of n) e.appendChild(t);
}
function o(e, t) {
	if (t !== void 0) for (let [n, r] of Object.entries(t)) r == null || r === !1 || e.setAttribute(n, r === !0 ? "" : String(r));
}
function s(e, t) {
	if (e instanceof HTMLElement) return e;
	let n = e.href === void 0 ? document.createElement("button") : document.createElement("a");
	if (n.classList.add("cmm-topbar__action"), e.className !== void 0 && n.classList.add(...e.className.split(/\s+/).filter(Boolean)), n.setAttribute("aria-label", e.label), n.setAttribute("title", e.label), n.setAttribute("data-action-id", e.id), o(n, e.attributes), n instanceof HTMLAnchorElement ? (n.href = e.href ?? "#", e.target !== void 0 && (n.target = e.target), e.target === "_blank" && (n.rel = "noreferrer noopener")) : n instanceof HTMLButtonElement && (n.type = "button"), e.onClick !== void 0 && n.addEventListener("click", e.onClick), e.icon !== void 0 && n.appendChild(r(t, e.icon)), e.showLabel === !0 || e.icon === void 0) {
		let t = document.createElement("span");
		t.classList.add("cmm-topbar__action-label"), t.textContent = e.label, n.appendChild(t);
	}
	if (e.badge !== void 0 && e.badge !== !1) {
		let t = document.createElement("span");
		t.classList.add("cmm-topbar__action-badge"), t.textContent = e.badge === !0 ? "" : String(e.badge), n.appendChild(t);
	}
	return n;
}
var c = class {
	el;
	cleanupFns = [];
	constructor(e = {}) {
		let t = e.iconSet ?? "lucide";
		this.el = document.createElement("header"), this.el.className = ["cmm-topbar", e.className].filter(Boolean).join(" ");
		let r = document.createElement("div");
		r.classList.add("cmm-topbar__breadcrumbs");
		let i = e.product ?? e.breadcrumbs?.[0]?.label;
		if (i !== void 0) {
			let e = document.createElement("span");
			e.classList.add("cmm-topbar__product"), e.textContent = i, r.appendChild(e);
		}
		let o = e.breadcrumbs ?? [], c = +(e.product === void 0 && i !== void 0);
		for (let e of o.slice(c)) {
			let t = document.createElement("span");
			t.classList.add("cmm-topbar__separator"), t.setAttribute("aria-hidden", "true"), t.textContent = "•", r.appendChild(t);
			let n = e.href === void 0 ? document.createElement("span") : document.createElement("a");
			n.classList.add("cmm-topbar__breadcrumb"), n.textContent = e.label, n instanceof HTMLAnchorElement && (n.href = e.href ?? "#"), r.appendChild(n);
		}
		if (e.current !== void 0) {
			let t = document.createElement("span");
			t.classList.add("cmm-topbar__separator"), t.setAttribute("aria-hidden", "true"), t.textContent = "•", r.appendChild(t);
			let n = document.createElement("span");
			n.classList.add("cmm-topbar__current"), n.textContent = e.current, r.appendChild(n);
		}
		let l = document.createElement("div");
		l.classList.add("cmm-topbar__actions"), a(l, e.beforeActions);
		for (let n of e.actions ?? []) l.appendChild(s(n, t));
		e.user !== void 0 && l.appendChild(this.createUserMenu(e.user, t)), a(l, e.afterActions), this.el.appendChild(r), this.el.appendChild(l), e.container !== void 0 && n(e.container).appendChild(this.el);
	}
	destroy() {
		for (let e of this.cleanupFns.splice(0)) e();
		this.el.remove();
	}
	createUserMenu(e, t) {
		let n = document.createElement("div");
		n.classList.add("cmm-topbar__user");
		let a = document.createElement("button");
		a.type = "button", a.classList.add("cmm-topbar__user-trigger"), a.setAttribute("aria-haspopup", "menu"), a.setAttribute("aria-expanded", "false"), a.setAttribute("aria-label", e.menuLabel ?? `User menu for ${e.name}`);
		let o = document.createElement("span");
		if (o.classList.add("cmm-topbar__avatar"), e.avatarUrl !== void 0) {
			let t = document.createElement("img");
			t.src = e.avatarUrl, t.alt = "", o.appendChild(t);
		} else o.textContent = e.initials ?? i(e.name);
		a.appendChild(o), a.appendChild(r(t, "chevron-down"));
		let c = document.createElement("div");
		c.classList.add("cmm-topbar__user-menu"), c.setAttribute("role", "menu"), c.hidden = !0;
		let l = document.createElement("div");
		l.classList.add("cmm-topbar__user-profile");
		let u = document.createElement("span");
		if (u.classList.add("cmm-topbar__user-name"), u.textContent = e.name, l.appendChild(u), e.detail !== void 0) {
			let t = document.createElement("span");
			t.classList.add("cmm-topbar__user-detail"), t.textContent = e.detail, l.appendChild(t);
		}
		c.appendChild(l);
		for (let n of e.actions ?? []) {
			let e = s(n, t);
			if (e.classList.remove("cmm-topbar__action"), e.classList.add("cmm-topbar__menu-item"), e.setAttribute("role", "menuitem"), e.querySelector(".cmm-topbar__action-label") === null) {
				let t = document.createElement("span");
				t.classList.add("cmm-topbar__action-label"), t.textContent = n.label, e.appendChild(t);
			}
			c.appendChild(e);
		}
		let d = (e) => {
			c.hidden = !e, a.setAttribute("aria-expanded", String(e));
		};
		a.addEventListener("click", () => {
			d(c.hidden === !0);
		});
		let f = (e) => {
			n.contains(e.target) || d(!1);
		}, p = (e) => {
			e.key === "Escape" && d(!1);
		};
		return document.addEventListener("pointerdown", f), document.addEventListener("keydown", p), this.cleanupFns.push(() => {
			document.removeEventListener("pointerdown", f), document.removeEventListener("keydown", p);
		}), n.appendChild(a), n.appendChild(c), n;
	}
}, l = class {
	el;
	mainEl;
	contentEl;
	constructor(e = {}) {
		if (this.el = document.createElement("div"), this.el.className = [
			"cmm-app-shell",
			e.variant === "product" && "cmm-app-shell--product",
			e.className
		].filter(Boolean).join(" "), this.el.setAttribute("data-shell-layout", ""), e.sidebarCollapsed !== void 0 && this.el.setAttribute("data-sidebar-collapsed", String(e.sidebarCollapsed)), e.sidebar !== void 0) {
			let t = document.createElement("aside");
			t.className = "cmm-app-shell__sidebar", t.setAttribute("data-shell-sidebar", ""), t.appendChild(e.sidebar), this.el.appendChild(t);
		}
		if (this.mainEl = document.createElement("div"), this.mainEl.className = "cmm-app-shell__main", e.topbar !== void 0) {
			let t = e.topbar instanceof HTMLElement ? e.topbar : new c(e.topbar).el;
			this.mainEl.appendChild(t);
		} else e.header !== void 0 && this.mainEl.appendChild(e.header);
		if (this.contentEl = document.createElement("main"), this.contentEl.className = "cmm-app-shell__content", e.metrics !== void 0) {
			let t = document.createElement("div");
			t.className = "cmm-app-shell__metric-strip", t.appendChild(e.metrics), this.contentEl.appendChild(t);
		}
		e.content !== void 0 && this.contentEl.appendChild(e.content), this.mainEl.appendChild(this.contentEl), this.el.appendChild(this.mainEl), e.container !== void 0 && n(e.container).appendChild(this.el);
	}
};
function u(e = {}) {
	return new l(e).el;
}
function d(e = {}) {
	return new c(e).el;
}
function f(e = {}) {
	return new l({
		...e,
		variant: "product"
	}).el;
}
//#endregion
export { l as AppShell, c as TopMenuBar, u as createAppShell, f as createProductShell, d as createTopMenuBar };

//# sourceMappingURL=app-shell.js.map