import { n as e } from "../sanitize-uWpY18N9.js";
import { t } from "../navigation-DihI8dfX.js";
import { AppShell as n, TopMenuBar as r, createAppShell as i, createProductShell as a, createTopMenuBar as o } from "./app-shell.js";
import { CORE_APP_ROUTE_LABELS as s, createCoreAppChromePreset as c, createCoreAppSidebarConfig as l, createCoreAppSidebarSections as u, createCoreAppTopbarActions as d, createCoreAppTopbarConfig as f, getCoreAppRouteLabel as p, mountCoreAppChrome as m, mountCoreAppChromeFromDom as h } from "./core-app-chrome.js";
import { PageHeader as g, createPageHeader as _ } from "./page-header.js";
//#region src/layout/index.ts
var v = () => {
	if (typeof window > "u") return null;
	try {
		return window.localStorage;
	} catch {
		return console.warn("Unable to access localStorage"), null;
	}
}, y = (e) => {
	try {
		return new URL(e, window.location.href).origin === window.location.origin;
	} catch {
		return !1;
	}
}, b = {
	storageKey: "cmm-sidebar-state",
	desktopBreakpoint: "(min-width: 1024px)",
	collapsedClass: "cmm-shell--sidebar-collapsed",
	openClass: "cmm-shell--sidebar-open"
};
function x(e = {}) {
	let t = {
		...b,
		...e
	}, n = document.querySelector("[data-shell-layout]"), r = document.querySelector("[data-shell-sidebar]");
	if (!n || !r) return () => {};
	let i = v(), a = window.matchMedia(t.desktopBreakpoint), o = Array.from(document.querySelectorAll("[data-sidebar-toggle]")), s = Array.from(document.querySelectorAll("[data-sidebar-dismiss]")), c = r.id || "shell-sidebar";
	r.id = c;
	let l = () => i?.getItem(t.storageKey) === "collapsed", u = () => {
		let e = a.matches ? !n.classList.contains(t.collapsedClass) : n.classList.contains(t.openClass);
		o.forEach((t) => {
			t.setAttribute("aria-expanded", e.toString()), t.setAttribute("aria-controls", c);
		});
	}, d = (e, r = !0) => {
		n.classList.toggle(t.collapsedClass, e), r && a.matches && i?.setItem(t.storageKey, e ? "collapsed" : "expanded"), u();
	}, f = (e) => {
		n.classList.toggle(t.openClass, e), u();
	}, p = () => {
		a.matches ? (f(!1), d(l(), !1)) : (f(!1), d(!1, !1));
	}, m = () => {
		a.matches ? d(!n.classList.contains(t.collapsedClass)) : f(!n.classList.contains(t.openClass));
	}, h = () => {
		f(!1);
	}, g = (e) => {
		e.key === "Escape" && !a.matches && f(!1);
	};
	return o.forEach((e) => {
		e.addEventListener("click", m);
	}), s.forEach((e) => {
		e.addEventListener("click", h);
	}), document.addEventListener("keydown", g), a.addEventListener("change", p), p(), () => {
		o.forEach((e) => {
			e.removeEventListener("click", m);
		}), s.forEach((e) => {
			e.removeEventListener("click", h);
		}), document.removeEventListener("keydown", g), a.removeEventListener("change", p);
	};
}
function S(e = {}) {
	let t = e.triggerSelector ?? "[data-user-trigger]", n = e.dropdownSelector ?? "[data-user-dropdown]", r = document.querySelector("[data-user-menu]"), i = document.querySelector(t), a = document.querySelector(n);
	if (!r || !i || !a) return () => {};
	let o = (e) => {
		i.setAttribute("aria-expanded", e.toString()), r.setAttribute("aria-expanded", e.toString());
	}, s = () => i.getAttribute("aria-expanded") === "true", c = (e) => {
		e.stopPropagation(), o(!s());
	}, l = (e) => {
		r.contains(e.target) || o(!1);
	}, u = (e) => {
		e.key === "Escape" && s() && (o(!1), i.focus());
	}, d = e.dropdownItemSelector ?? ".cmm-user-menu__dropdown-item", f = (e) => {
		let t = Array.from(a.querySelectorAll(d)), n = t.indexOf(document.activeElement);
		e.key === "ArrowDown" ? (e.preventDefault(), t[n < t.length - 1 ? n + 1 : 0]?.focus()) : e.key === "ArrowUp" ? (e.preventDefault(), t[n > 0 ? n - 1 : t.length - 1]?.focus()) : (e.key === "Tab" && !e.shiftKey && n === t.length - 1 || e.key === "Tab" && e.shiftKey && n === 0) && o(!1);
	}, p = (e) => {
		(e.key === "Enter" || e.key === " " || e.key === "ArrowDown") && !s() && (e.preventDefault(), o(!0), setTimeout(() => {
			a.querySelector(d)?.focus();
		}, 50));
	};
	return i.addEventListener("click", c), document.addEventListener("click", l), document.addEventListener("keydown", u), a.addEventListener("keydown", f), i.addEventListener("keydown", p), () => {
		i.removeEventListener("click", c), document.removeEventListener("click", l), document.removeEventListener("keydown", u), a.removeEventListener("keydown", f), i.removeEventListener("keydown", p);
	};
}
var C = (e) => e.dataset.collapsibleOpen === "true" || !e.classList.contains("hidden"), w = "cmm-collapsible--hidden", T = (e, t) => {
	e.classList.toggle("hidden", !t), e.classList.toggle(w, !t), e.dataset.collapsibleOpen = t.toString(), e.setAttribute("aria-hidden", t ? "false" : "true");
}, E = (e, t) => {
	document.querySelectorAll(`[data-toggle-target='${e}']`).forEach((e) => {
		e.setAttribute("aria-expanded", t.toString());
	});
};
function D(e = {}) {
	let { scrollIntoView: t = !0, scrollBehavior: n = "smooth", hiddenClass: r = "cmm-collapsible--hidden" } = e;
	w = r, document.querySelectorAll("[data-collapsible]").forEach((e) => {
		T(e, e.dataset.collapsibleOpen === "true" || !e.classList.contains("hidden"));
	});
	let i = [];
	document.querySelectorAll("[data-toggle-target]").forEach((e) => {
		let r = e.dataset.toggleTarget;
		if (!r) return;
		let a = document.querySelector(r);
		if (!a) return;
		let o = a.id || r.replace(/^#/, "");
		e.setAttribute("aria-controls", o), e.setAttribute("aria-expanded", C(a).toString());
		let s = (e) => {
			e.preventDefault();
			let i = !C(a);
			T(a, i), E(r, i), i && t && a.scrollIntoView({
				behavior: n,
				block: "start"
			});
		};
		e.addEventListener("click", s), i.push({
			element: e,
			handler: s
		});
	}), document.querySelectorAll("[data-collapse-target]").forEach((e) => {
		let t = e.dataset.collapseTarget;
		if (!t) return;
		let n = document.querySelector(t);
		if (!n) return;
		let r = (e) => {
			e.preventDefault(), T(n, !1), E(t, !1);
		};
		e.addEventListener("click", r), i.push({
			element: e,
			handler: r
		});
	});
	let a = window.location.hash;
	if (a) {
		let e = document.querySelector(a);
		e?.dataset.collapsible !== void 0 && (T(e, !0), E(a, !0));
	}
	return () => {
		i.forEach(({ element: e, handler: t }) => {
			e.removeEventListener("click", t);
		});
	};
}
var O = "\n  <div class=\"cmm-sheet__loading\">\n    <div class=\"cmm-spinner\"></div>\n  </div>\n", k = "\n  <div class=\"cmm-sheet__error\">\n    <p>Failed to load content. Please try the full page.</p>\n  </div>\n";
function A(t, n) {
	t.replaceChildren(e(n, { allowSvg: !0 }));
}
function j(e = {}) {
	let { openClass: n = "cmm-sheet--open", hiddenClass: r = "cmm-sheet--hidden", backdropVisibleClass: i = "cmm-sheet__backdrop--visible", backdropHiddenClass: a = "cmm-sheet__backdrop--hidden", spinnerHtml: o = O, errorHtml: s = k, allowCrossOriginFetch: c = !1 } = e, l = /* @__PURE__ */ new Map();
	if (document.querySelectorAll("[data-sheet]").forEach((e) => {
		let t = e.dataset.sheet;
		if (!t) return;
		let n = document.querySelector(`[data-sheet-backdrop='${t}']`), r = e.querySelector("[data-sheet-content]");
		!n || !r || l.set(t, {
			key: t,
			sheet: e,
			backdrop: n,
			content: r,
			fullPageLink: e.querySelector("[data-sheet-fullpage]"),
			expandLink: e.querySelector("[data-sheet-expand]"),
			focusSelector: e.dataset.sheetFocus
		});
	}), l.size === 0) return () => {};
	let u = null, d = (e, t) => {
		e.sheet.classList.toggle(n, t), e.sheet.classList.toggle(r, !t), e.backdrop.classList.toggle(i, t), e.backdrop.classList.toggle(a, !t), e.sheet.setAttribute("aria-hidden", t ? "false" : "true");
	}, f = (e) => {
		u?.key === e.key && (u = null), d(e, !1);
	}, p = async (e, n) => {
		u && u.key !== e.key && f(u), u = e, d(e, !0);
		let r = n?.dataset.sheetUrl ?? e.sheet.dataset.sheetUrl, i = n?.dataset.sheetFocus ?? e.focusSelector, a = n?.dataset.sheetFullpage ?? e.sheet.dataset.sheetFullpage, l = n?.dataset.sheetExpand ?? e.sheet.dataset.sheetExpand;
		if (e.fullPageLink && a && (e.fullPageLink.href = a), e.expandLink && l && (e.expandLink.href = l), !r || !c && !y(r)) {
			A(e.content, s);
			return;
		}
		A(e.content, o);
		try {
			let n = await fetch(r);
			if (n.ok) {
				let t = await n.text();
				A(e.content, t), i && e.content.querySelector(i)?.focus();
			} else a ? t(a) : A(e.content, s);
		} catch {
			a ? t(a) : A(e.content, s);
		}
	}, m = [];
	l.forEach((e) => {
		let t = (t) => {
			t.target.closest("[data-sheet-close]") && (t.preventDefault(), f(e));
		}, n = () => {
			f(e);
		}, r = () => {
			f(e);
		};
		e.sheet.addEventListener("click", t), e.backdrop.addEventListener("click", n), m.push({
			element: e.sheet,
			event: "click",
			handler: t
		}), m.push({
			element: e.backdrop,
			event: "click",
			handler: n
		}), e.expandLink && (e.expandLink.addEventListener("click", r), m.push({
			element: e.expandLink,
			event: "click",
			handler: r
		}));
	}), document.querySelectorAll("[data-sheet-trigger]").forEach((e) => {
		let t = e.dataset.sheetTrigger;
		if (!t) return;
		let n = l.get(t);
		if (!n) return;
		let r = (t) => {
			t.preventDefault(), p(n, e);
		};
		e.addEventListener("click", r), m.push({
			element: e,
			event: "click",
			handler: r
		});
	});
	let h = (e) => {
		e.key === "Escape" && u && f(u);
	};
	return document.addEventListener("keydown", h), () => {
		m.forEach(({ element: e, event: t, handler: n }) => {
			e.removeEventListener(t, n);
		}), document.removeEventListener("keydown", h);
	};
}
function M() {
	let e = document.querySelector("[data-nav-list]");
	if (!e) return () => {};
	let t = () => Array.from(e.querySelectorAll("[data-nav-item]")), n = (e) => {
		let n = t(), r = n.indexOf(document.activeElement);
		e.key === "ArrowDown" ? (e.preventDefault(), n[r < n.length - 1 ? r + 1 : 0]?.focus()) : e.key === "ArrowUp" ? (e.preventDefault(), n[r > 0 ? r - 1 : n.length - 1]?.focus()) : e.key === "Home" ? (e.preventDefault(), n[0]?.focus()) : e.key === "End" && (e.preventDefault(), n[n.length - 1]?.focus());
	};
	return e.addEventListener("keydown", n), () => {
		e.removeEventListener("keydown", n);
	};
}
function N(e = {}) {
	let t = [
		x(e.sidebar),
		S(e.userMenu),
		D(e.collapsibles),
		j(e.sheets),
		M()
	];
	return () => {
		t.forEach((e) => {
			e();
		});
	};
}
//#endregion
export { n as AppShell, s as CORE_APP_ROUTE_LABELS, g as PageHeader, r as TopMenuBar, i as createAppShell, c as createCoreAppChromePreset, l as createCoreAppSidebarConfig, u as createCoreAppSidebarSections, d as createCoreAppTopbarActions, f as createCoreAppTopbarConfig, _ as createPageHeader, a as createProductShell, o as createTopMenuBar, p as getCoreAppRouteLabel, N as initLayout, m as mountCoreAppChrome, h as mountCoreAppChromeFromDom, D as setupCollapsibles, M as setupNavKeyboard, j as setupSheets, x as setupSidebar, S as setupUserMenu };

//# sourceMappingURL=index.js.map