import { t as e } from "../component-D5sRm1fq.js";
//#region src/sidebar/index.ts
var t = {
	storageKey: "sidebar-collapsed",
	mobileBreakpoint: 900,
	collapsedClass: "sidebar--collapsed",
	productVariants: [
		"app",
		"cm",
		"threat-library"
	],
	activeFromLocation: !0,
	closeOnNavigate: !0
}, n = { ...t }, r = "data-sidebar-initialized";
function i(e) {
	n = {
		...t,
		...e
	};
}
function a() {
	return window.innerWidth <= n.mobileBreakpoint;
}
function o(e) {
	return localStorage.getItem(`${n.storageKey}-${e}`) === "true";
}
function s(e, t) {
	localStorage.setItem(`${n.storageKey}-${e}`, String(t));
}
function c(e, t) {
	e.setAttribute("data-open", "false"), t && t.setAttribute("data-visible", "false");
}
function l(e, t) {
	let n = e.getAttribute("data-open") === "true";
	e.setAttribute("data-open", String(!n)), t && t.setAttribute("data-visible", String(!n));
}
function u(e) {
	return e === "/" ? e : e.replace(/\/+$/, "");
}
function d(e, t) {
	try {
		let n = u(new URL(t, window.location.href).pathname), r = u(e);
		return n === "/" ? r === "/" : r === n || r.startsWith(`${n}/`);
	} catch {
		return !1;
	}
}
function f(e) {
	let t = Array.from(e.querySelectorAll("a.sidebar__item[href], a.sidebar__nav-link[href], a[data-nav-item][href]")), n = null, r = -1;
	for (let e of t) {
		let t = e.getAttribute("href");
		if (!(t === null || !d(window.location.pathname, t))) try {
			let i = u(new URL(t, window.location.href).pathname);
			i.length > r && (n = e, r = i.length);
		} catch {}
	}
	return n;
}
function p(e) {
	if (n.activeFromLocation !== !0 || typeof window > "u") return;
	let t = f(e);
	t !== null && (e.querySelectorAll(".sidebar__item--active").forEach((e) => {
		e.classList.remove("sidebar__item--active"), e.removeAttribute("aria-current");
	}), t.classList.add("sidebar__item--active"), t.setAttribute("aria-current", "page"));
}
function m(e, t) {
	(e.hasAttribute("data-sidebar-product") || e.classList.contains("sidebar--cm") || n.productVariants.includes(t)) && e.classList.add("sidebar--product"), e.querySelectorAll(".sidebar__item, .sidebar__nav-link").forEach((e) => {
		e.hasAttribute("data-nav-item") || e.setAttribute("data-nav-item", "");
	}), p(e);
}
function h(e) {
	e.addEventListener("keydown", (t) => {
		if (t.key !== "ArrowDown" && t.key !== "ArrowUp") return;
		let n = Array.from(e.querySelectorAll("[data-nav-item]:not([aria-disabled=\"true\"])")).filter((e) => !e.hidden && e.offsetParent !== null);
		if (n.length === 0) return;
		let r = n.indexOf(document.activeElement);
		r !== -1 && (t.preventDefault(), n[t.key === "ArrowDown" ? (r + 1) % n.length : (r - 1 + n.length) % n.length]?.focus());
	});
}
function g({ sidebar: e, toggle: t, mobileToggles: i, backdrop: u, collapsedClass: d, key: f }) {
	!a() && o(f) && e.classList.add(d), t && t.addEventListener("click", () => {
		s(f, e.classList.toggle(d));
	}), i.forEach((t) => {
		t.addEventListener("click", () => {
			l(e, u);
		});
	}), u && u.addEventListener("click", () => {
		c(e, u);
	}), n.closeOnNavigate === !0 && e.addEventListener("click", (t) => {
		let n = t.target;
		(n instanceof Element ? n.closest("a.sidebar__item[href], a.sidebar__nav-link[href], a[data-nav-item][href]") : null) !== null && e.getAttribute("data-open") === "true" && c(e, u);
	}), window.addEventListener("resize", () => {
		a() && c(e, u);
	}), document.addEventListener("keydown", (t) => {
		t.key === "Escape" && e.getAttribute("data-open") === "true" && c(e, u);
	}), h(e), e.setAttribute(r, "true");
}
function _(e) {
	let t = e.getAttribute("data-sidebar");
	t === null || t === "" || (m(e, t), e.getAttribute(r) !== "true" && g({
		sidebar: e,
		toggle: e.querySelector("[data-sidebar-toggle]"),
		mobileToggles: Array.from(document.querySelectorAll("[data-sidebar-mobile-toggle]")),
		backdrop: document.querySelector(`[data-sidebar-backdrop="${t}"]`),
		collapsedClass: n.collapsedClass,
		key: t
	}));
}
function v(e) {
	let t = document.querySelector(e.sidebar);
	t && (t.hasAttribute("data-sidebar") || g({
		sidebar: t,
		toggle: document.querySelector(e.toggle),
		mobileToggles: Array.from(document.querySelectorAll(e.mobileToggle)),
		backdrop: document.querySelector(e.backdrop),
		collapsedClass: e.collapsedClass,
		key: e.sidebar.replace(/[^a-z]/g, "")
	}));
}
var y = [
	{
		sidebar: ".page__sidebar",
		toggle: "[data-page-sidebar-toggle]",
		mobileToggle: "[data-page-mobile-toggle]",
		backdrop: ".sidebar-backdrop",
		collapsedClass: "page__sidebar--collapsed"
	},
	{
		sidebar: ".chat-sidebar",
		toggle: "[data-chat-sidebar-toggle]",
		mobileToggle: ".chat-header__menu-toggle",
		backdrop: ".chat-sidebar-backdrop",
		collapsedClass: "chat-sidebar--collapsed"
	},
	{
		sidebar: ".files-sidebar",
		toggle: "[data-files-sidebar-toggle]",
		mobileToggle: "[data-files-mobile-toggle]",
		backdrop: ".files-sidebar-backdrop",
		collapsedClass: "files-sidebar--collapsed"
	},
	{
		sidebar: ".storage-sidebar",
		toggle: "[data-storage-sidebar-toggle]",
		mobileToggle: "[data-storage-mobile-toggle]",
		backdrop: ".storage-sidebar-backdrop",
		collapsedClass: "storage-sidebar--collapsed"
	}
];
function b(e, t = y) {
	e && i(e), document.querySelectorAll("[data-sidebar]").forEach(_), t.forEach(v);
}
//#endregion
export { e as SidebarComponent, i as configureSidebar, y as defaultLegacyConfigs, o as getStoredState, b as initSidebar, a as isMobile, s as saveState };

//# sourceMappingURL=index.js.map