'use client'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { useMemo } from 'react'; /** * Breadcrumb item type */ interface BreadcrumbItem { label: string; href?: string; } /** * Route label mappings * Maps route segments to human-readable labels */ const routeLabels: Record = { dashboard: 'Dashboard', beneficiaries: 'Loved Ones', sensors: 'Sensors', settings: 'Settings', profile: 'Profile', 'add-sensor': 'Add Sensor', subscription: 'Subscription', equipment: 'Equipment', share: 'Share Access', }; /** * Breadcrumbs Component * * Displays navigation breadcrumbs based on current route. * Automatically generates breadcrumb trail from pathname. * * Features: * - Auto-generated from URL path * - Clickable navigation links * - Current page highlighted * - Responsive (hidden on mobile) * * @example * ```tsx * * ``` * * Route examples: * - /dashboard -> Dashboard * - /beneficiaries/123 -> Loved Ones / John Doe * - /beneficiaries/123/sensors -> Loved Ones / John Doe / Sensors */ export function Breadcrumbs() { const pathname = usePathname(); const breadcrumbs = useMemo(() => { // Don't show breadcrumbs on auth pages if (pathname.startsWith('/login') || pathname.startsWith('/verify-otp')) { return []; } const segments = pathname.split('/').filter(Boolean); const items: BreadcrumbItem[] = []; // Build breadcrumb trail let currentPath = ''; segments.forEach((segment, index) => { currentPath += `/${segment}`; // Check if segment is a dynamic ID (numeric) const isId = /^\d+$/.test(segment); if (isId) { // For IDs, use a placeholder or fetch the actual name // In production, you would fetch the beneficiary name here items.push({ label: `#${segment}`, href: currentPath, }); } else { // Use mapped label or capitalize segment const label = routeLabels[segment] || segment.charAt(0).toUpperCase() + segment.slice(1); items.push({ label, href: currentPath, }); } }); return items; }, [pathname]); // Don't render if no breadcrumbs if (breadcrumbs.length === 0) { return null; } return ( ); }