'use client'; import { ChevronDown } from 'lucide-react'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { useEffect, useState } from 'react'; import { cn } from '@/lib/utils'; import { getVisibleExtras, getVisibleGroups, type AppRole, type NavGroup } from './nav-items'; function isActive(pathname: string, href: string) { if (href === '/') return pathname === '/'; return pathname === href || pathname.startsWith(`${href}/`); } function groupIsActive(pathname: string, group: NavGroup) { if (group.href && isActive(pathname, group.href)) return true; return Boolean(group.children?.some((c) => isActive(pathname, c.href))); } function NavGroupBlock({ group, pathname }: { group: NavGroup; pathname: string }) { const active = groupIsActive(pathname, group); const [open, setOpen] = useState(active); // Başka bir sayfaya geçildiğinde ilgili grup kendiliğinden açılsın. useEffect(() => { if (active) setOpen(true); }, [active]); const Icon = group.icon; if (!group.children) { return ( {group.title} ); } return (
{open ? (
{group.children.map((child) => ( {child.title} ))}
) : null}
); } export function Sidebar({ role }: { role: AppRole }) { const pathname = usePathname(); const groups = getVisibleGroups(role); const extras = getVisibleExtras(role); return ( ); }