export interface BreadcrumbCrumb { label: string href: string } const routeTitles: Record = { '/': 'Панель управления', '/domains': 'Домены', '/groups': 'Группы доменов', '/services': 'Сервисы', '/certificates': 'Сертификаты', } const SETTINGS_SECTIONS: Record = { '/settings/appearance': 'Внешний вид', '/settings/health': 'Health-check', '/settings/integrations': 'Интеграции', } /** Drop consecutive repeats so «Настройки» does not stack after tab switches. */ export function dedupeBreadcrumbs(crumbs: BreadcrumbCrumb[]): BreadcrumbCrumb[] { const out: BreadcrumbCrumb[] = [] for (const crumb of crumbs) { const prev = out.at(-1) if (prev && prev.label === crumb.label) continue out.push(crumb) } return out } export function getBreadcrumbs( pathname: string, dynamicLabels: Record = {}, ): BreadcrumbCrumb[] { const path = pathname.replace(/\/+$/, '') || '/' if (path === '/') { return [{ label: 'Панель управления', href: '/' }] } if (path.match(/^\/services\/\d+$/)) { return [ { label: 'Сервисы', href: '/services' }, { label: dynamicLabels[path] ?? 'Сервис', href: path }, ] } if (path.match(/^\/groups\/\d+$/)) { return [ { label: 'Группы доменов', href: '/groups' }, { label: dynamicLabels[path] ?? 'Группа', href: path }, ] } if (path.match(/^\/domains\/\d+\/dns$/)) { const domainId = path.split('/')[2] const domainPath = `/domains/${domainId}` return [ { label: 'Домены', href: '/domains' }, { label: dynamicLabels[domainPath] ?? 'Домен', href: domainPath }, { label: 'DNS', href: path }, ] } if (path.match(/^\/domains\/\d+$/)) { return [ { label: 'Домены', href: '/domains' }, { label: dynamicLabels[path] ?? 'Обзор домена', href: path }, ] } if (path === '/settings' || path.startsWith('/settings/')) { const section = SETTINGS_SECTIONS[path] return dedupeBreadcrumbs([ { label: 'Настройки', href: '/settings' }, ...(section ? [{ label: section, href: path }] : []), ]) } const title = routeTitles[path] if (title) { return [{ label: title, href: path }] } return [{ label: 'Панель управления', href: '/' }] }