import type { FolderTreeNode } from "@/lib/sidebar-nav-maps" import { findFolderPath } from "@/lib/sidebar-nav-folder-ids" import { getMailNavFolderLabel } from "@/lib/sidebar-nav-data" export const INBOX_CATEGORY_TAB_LABELS: Record = { primary: "Principale", promotions: "Promotions", social: "Réseaux sociaux", updates: "Notifications", forums: "Forums", } /** Clé stable pour historique navigation (dossier + onglet boîte de réception). */ export function mailNavVisitKey(folderId: string, inboxTab?: string): string { if (folderId === "inbox" && inboxTab && inboxTab !== "primary") { return `inbox::${inboxTab}` } return folderId } export function parseMailNavVisitKey(key: string): { folderId: string inboxTab?: string } { if (key.startsWith("inbox::")) { return { folderId: "inbox", inboxTab: key.slice("inbox::".length) } } return { folderId: key } } export function getMailNavFolderBreadcrumbSegments( folderId: string, folderTree: FolderTreeNode[], folderIdToLabel?: Record, inboxCategoryLabel?: string | null ): string[] { if (folderId === "inbox") { const base = getMailNavFolderLabel(folderId, folderIdToLabel) if ( inboxCategoryLabel && inboxCategoryLabel !== INBOX_CATEGORY_TAB_LABELS.primary ) { return [base, inboxCategoryLabel] } return [base] } const path = findFolderPath(folderTree, folderId) if (path?.length) { return path.map((n) => n.label) } return [getMailNavFolderLabel(folderId, folderIdToLabel)] } export function breadcrumbSegmentsForVisitKey( key: string, folderTree: FolderTreeNode[], folderIdToLabel?: Record ): string[] { const { folderId, inboxTab } = parseMailNavVisitKey(key) const cat = folderId === "inbox" && inboxTab ? INBOX_CATEGORY_TAB_LABELS[inboxTab] ?? inboxTab : null return getMailNavFolderBreadcrumbSegments( folderId, folderTree, folderIdToLabel, cat ) } export function breadcrumbForVisitKey( key: string, folderTree: FolderTreeNode[], folderIdToLabel?: Record ): string { return breadcrumbSegmentsForVisitKey(key, folderTree, folderIdToLabel).join( " · " ) }