---
import Sponsors from './Sponsors.astro';
import { SIDEBAR } from '../../config.ts';
import { getLanguageFromURL, removeLeadingSlash, removeTrailingSlash } from '../../util.ts';
import SidebarContent from './SidebarContent.astro';
import SidebarSectionToggle from './SidebarSectionToggle.tsx';
const { currentPage } = Astro.props;
// Get the slug w/o a leading or trailing slash
const currentPageMatch = removeLeadingSlash(removeTrailingSlash(currentPage));
const langCode = getLanguageFromURL(currentPage);
// SIDEBAR is a flat array. Group it by sections to properly render.
const sidebarSections = SIDEBAR[langCode].reduce((collection, item) => {
if (item.header) {
collection.push({ ...item, type: item.type, children: [] });
} else {
collection[collection.length - 1].children.push(item);
}
return collection;
}, []);
const learnSections = sidebarSections.filter((section) => section.type === 'learn');
const apiSections = sidebarSections.filter((section) => section.type === 'api');
let activeTab = 'learn';
for (const section of sidebarSections) {
if (section.children.some((item) => item.link === currentPageMatch)) {
activeTab = section.type;
}
}
---