import { i as e, t } from "../sanitize-CDxuPfMB.js";
//#region src/app-switcher/index.ts
var n = null, r = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 66.55 94.52\" width=\"24\" height=\"34\"><rect class=\"cm-logo__diamond--primary\" x=\"5.31\" y=\"33.28\" width=\"27.97\" height=\"27.97\" rx=\"1.17\" transform=\"translate(-27.77 27.48) rotate(-45)\"/><rect class=\"cm-logo__diamond--muted\" x=\"33.28\" y=\"61.24\" width=\"27.97\" height=\"27.97\" rx=\"1.17\" transform=\"translate(-39.35 55.45) rotate(-45)\"/><rect class=\"cm-logo__diamond--accent\" x=\"33.28\" y=\"5.31\" width=\"27.97\" height=\"27.97\" rx=\"1.17\" transform=\"translate(0.2 39.07) rotate(-45)\"/></svg>";
function i(e, n) {
	return e.trimStart().startsWith("<") ? e : `<svg xmlns="http://www.w3.org/2000/svg" width="${String(n)}" height="${String(n)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="${t(e)}"/></svg>`;
}
function a(t, n) {
	if (!t) return;
	let a = n?.icon;
	typeof a == "string" && a.length > 0 ? (e(t, i(a, 20)), t.classList.remove("app-switcher__logo-mark")) : (e(t, r), t.classList.add("app-switcher__logo-mark"));
}
function o(e, t, r) {
	e.classList.add("app-switcher--open"), t.setAttribute("aria-expanded", "true"), n = e, r.querySelector(".app-switcher__item:not(.app-switcher__item--disabled)")?.focus();
}
function s(e) {
	let t = e.querySelector(".app-switcher__trigger");
	e.classList.remove("app-switcher--open"), t?.setAttribute("aria-expanded", "false"), t?.focus(), n === e && (n = null);
}
function c(e, t, r) {
	e.classList.contains("app-switcher--open") ? s(e) : (n && n !== e && s(n), o(e, t, r));
}
function l(t, n, r, o) {
	let l = t.querySelector("[data-app-switcher-grid]"), u = t.querySelector("[data-app-switcher-current]"), d = t.querySelector("[data-app-switcher-icon]"), f = t.querySelector(".app-switcher__trigger"), p = t.querySelector(".app-switcher__panel");
	if (!l || !f || !p) return;
	t.hidden = !1, t.classList.remove("app-switcher--single", "app-switcher--empty"), l.innerHTML = "";
	let m = r?.name ?? "Apps";
	if (a(d, r), f.setAttribute("title", m), n.length === 0) {
		t.classList.add("app-switcher--empty"), u && (u.textContent = m);
		return;
	}
	if (n.length === 1) {
		t.classList.add("app-switcher--single"), u && n[0] && (u.textContent = n[0].name);
		return;
	}
	let h = document.createElement("div");
	h.className = "app-switcher__backdrop", t.appendChild(h), f.addEventListener("click", (e) => {
		e.preventDefault(), e.stopPropagation(), c(t, f, p);
	}), h.addEventListener("click", () => {
		s(t);
	}), p.addEventListener("click", (e) => {
		e.target.closest(".app-switcher__item:not(.app-switcher__item--disabled)") && s(t);
	}), n.forEach((t) => {
		let n = t.status ?? "active", r = n === "coming_soon", a = o.startsWith(t.href), s = document.createElement(r ? "div" : "a");
		if (s.className = "app-switcher__item", s.setAttribute("role", "menuitem"), s.setAttribute("title", t.name), a && s.classList.add("app-switcher__item--active"), r ? (s.classList.add("app-switcher__item--disabled"), s.setAttribute("aria-disabled", "true")) : s.href = t.href, typeof t.icon == "string" && t.icon.length > 0) {
			let n = document.createElement("span");
			n.className = "app-switcher__icon", n.setAttribute("aria-hidden", "true"), e(n, i(t.icon, 18)), s.appendChild(n);
		}
		let c = document.createElement("span");
		c.className = "app-switcher__content";
		let u = document.createElement("span");
		if (u.className = "app-switcher__title", u.textContent = t.name, c.appendChild(u), typeof t.description == "string" && t.description.length > 0) {
			let e = document.createElement("span");
			e.className = "app-switcher__desc", e.textContent = t.description, c.appendChild(e);
		}
		if (s.appendChild(c), n !== "active") {
			let e = document.createElement("span");
			e.className = "app-switcher__badge", e.textContent = n === "preview" ? "Preview" : "Coming soon", s.appendChild(e);
		}
		l.appendChild(s);
	}), u && (u.textContent = m);
}
function u(e) {
	let t = document.querySelectorAll("[data-app-switcher]");
	if (t.length === 0) return;
	let r = [];
	if (e?.apps) r = e.apps;
	else if (e?.getApps) r = e.getApps();
	else {
		let e = document.getElementById("web-config")?.textContent;
		if (typeof e == "string" && e.length > 0) try {
			r = JSON.parse(e).apps ?? [];
		} catch {}
	}
	let i = window.location.pathname, a = null;
	for (let e of r) if (i.startsWith(e.href)) {
		a = e;
		break;
	}
	t.forEach((e) => {
		l(e, r, a, i);
	}), document.addEventListener("keydown", (e) => {
		e.key === "Escape" && n && s(n);
	});
}
function d() {
	return n;
}
function f() {
	n && s(n);
}
//#endregion
export { f as closeAnyOpenAppSwitcher, d as getCurrentOpenInstance, u as initAppSwitcher };

//# sourceMappingURL=index.js.map