'use client'; import { usePathname } from 'next/navigation'; import { Button } from "@/components/ui/button" import { Separator } from "@/components/ui/separator" import { SidebarTrigger } from "@/components/ui/sidebar" import Link from 'next/link'; import { ChevronRight } from 'lucide-react'; function getBreadcrumbs(pathname: string) { // Map routes to breadcrumb labels const routeMap: Record = { '/dashboard': [{ label: 'Dashboard', href: '/dashboard' }], '/dashboard/liked-videos': [ { label: 'Dashboard', href: '/dashboard' }, { label: 'Liked Videos', href: '/dashboard/liked-videos' } ], '/dashboard/watch-history': [ { label: 'Dashboard', href: '/dashboard' }, { label: 'Watch History', href: '/dashboard/watch-history' } ], '/videoplayer': [ { label: 'Dashboard', href: '/dashboard' }, { label: 'Video Player', href: '/videoplayer' } ], '/admin': [{ label: 'Admin Panel', href: '/admin' }], '/admin/users': [ { label: 'Admin Panel', href: '/admin' }, { label: 'Users', href: '/admin/users' } ], '/admin/courses': [ { label: 'Admin Panel', href: '/admin' }, { label: 'Courses', href: '/admin/courses' } ], '/admin/playlists': [ { label: 'Admin Panel', href: '/admin' }, { label: 'Playlists', href: '/admin/playlists' } ], '/admin/videos': [ { label: 'Admin Panel', href: '/admin' }, { label: 'Videos', href: '/admin/videos' } ], '/admin/enrollments': [ { label: 'Admin Panel', href: '/admin' }, { label: 'Enrollments', href: '/admin/enrollments' } ], '/login': [{ label: 'Login', href: '/login' }], }; // Check for exact match first if (routeMap[pathname]) { return routeMap[pathname]; } // Check for prefix matches (like /admin/users/[userId]) for (const [route, breadcrumbs] of Object.entries(routeMap)) { if (pathname.startsWith(route + '/')) { // For dynamic routes like /admin/users/[userId]/... if (route === '/admin/users' && pathname.match(/^\/admin\/users\/[^/]+/)) { return [ { label: 'Admin Panel', href: '/admin' }, { label: 'Users', href: '/admin/users' }, { label: 'User Details', href: pathname.split('/').slice(0, 4).join('/') } ]; } if (route === '/admin/videos' && pathname.match(/^\/admin\/videos\/[^/]+/)) { return [ { label: 'Admin Panel', href: '/admin' }, { label: 'Videos', href: '/admin/videos' }, { label: 'Edit Video', href: pathname.split('/').slice(0, 4).join('/') } ]; } } } // Default fallback return [{ label: 'Library', href: '/' }]; } export function SiteHeader() { const pathname = usePathname(); const breadcrumbs = getBreadcrumbs(pathname); return (
) }