/* ═══════════════════════════════════════════════════════════════ NAV SECTIONS: the sections listed under each page in the header's dropdowns, the mobile menu and the footer's site map Every page's list comes from the page itself, so adding, moving or renaming a section changes the menus too: the site pages' sections (Pages → each page, GET /site-pages), and the front page's bands it is showing, in the admin's order, each under its heading (Front page → Sections). ═══════════════════════════════════════════════════════════════ */ import { useCallback } from 'react' import { useSitePageHeadings } from './useSitePages.ts' import { useFrontPage } from './useFrontPage.ts' import { FRONT_PAGE_BANDS, bandShows } from './frontPageBands.ts' export type NavSection = { label: string; hash: string } export function useNavSections(): (path: string) => NavSection[] { const { data: page } = useFrontPage() const { data: sitePages } = useSitePageHeadings() return useCallback( (path: string) => { if (path !== '/') { return (sitePages?.[path.slice(1)] ?? []).map((section) => ({ label: section.title, hash: `#${section.anchor}`, })) } if (!page) return [] return page.sections.flatMap((section) => { const band = FRONT_PAGE_BANDS[section.section] if (!band?.id || !bandShows(page, section.section)) return [] return [{ label: section.title || band.title, hash: `#${band.id}` }] }) }, [page, sitePages], ) }