/** * Sidebar section registry and order vocabulary. Pure module (no React, no * Payload import) so both the sidebar client component and server actions can * use it. Modeled on src/lib/dashboard/layout.ts. */ export const SIDEBAR_SECTION_IDS = [ "platform", "map", "intelligence", "operations", "infrastructure", "chronicle", "surveys", "helpdesk", "commerce", "personal", ] as const; export type SidebarSectionId = (typeof SIDEBAR_SECTION_IDS)[number]; export const DEFAULT_SIDEBAR_ORDER: readonly SidebarSectionId[] = [...SIDEBAR_SECTION_IDS]; export const SIDEBAR_SECTION_LABELS: Record = { platform: "Platform", map: "Map", intelligence: "Intelligence", operations: "Operations", infrastructure: "Infrastructure", chronicle: "Chronicle", surveys: "Surveys", helpdesk: "Helpdesk", commerce: "Commerce", personal: "Personal", }; export function isSidebarSectionId(value: unknown): value is SidebarSectionId { return ( typeof value === "string" && (SIDEBAR_SECTION_IDS as readonly string[]).includes(value) ); } /** * Sanitizes an arbitrary stored order into a valid full section list: drops * unknown/duplicate ids, keeps known ones in the user's order, and appends any * missing sections at the end in default order. Non-array input falls back to * the default order. */ export function normalizeSidebarOrder(raw: unknown): SidebarSectionId[] { if (!Array.isArray(raw)) { return [...DEFAULT_SIDEBAR_ORDER]; } const seen = new Set(); const ordered: SidebarSectionId[] = []; for (const entry of raw) { if (isSidebarSectionId(entry) && !seen.has(entry)) { seen.add(entry); ordered.push(entry); } } for (const id of DEFAULT_SIDEBAR_ORDER) { if (!seen.has(id)) { ordered.push(id); } } return ordered; }