'use client'; import { Fragment } from 'react'; import { usePathname } from 'next/navigation'; import { Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbSeparator, } from '../shadcn/breadcrumb'; import { If } from './if'; import { Trans } from './trans'; const unslugify = (slug: string) => slug.replace(/-/g, ' '); export function AppBreadcrumbs(props: { values?: Record; maxDepth?: number; }) { const pathName = usePathname(); const splitPath = pathName.split('/').filter(Boolean); const values = props.values ?? {}; const maxDepth = props.maxDepth ?? 6; const Ellipsis = ( ); const showEllipsis = splitPath.length > maxDepth; const visiblePaths = showEllipsis ? ([splitPath[0], ...splitPath.slice(-maxDepth + 1)] as string[]) : splitPath; return ( {visiblePaths.map((path, index) => { const label = path in values ? ( values[path] ) : ( ); return ( {label} {index === 0 && showEllipsis && ( <> {Ellipsis} )} ); })} ); }