"use client" import Link from "next/link" import { usePathname } from "next/navigation" import { SidebarGroupLabel, SidebarGroup, SidebarGroupContent, SidebarMenu, SidebarMenuButton, SidebarMenuItem, } from "@/components/ui/sidebar" export function NavMain({ title, items, }: { title: string items: ReadonlyArray<{ title: string url: string icon?: React.ReactNode }> }) { const pathname = usePathname() const isActive = (itemUrl: string) => { const normalizePath = (path: string) => path !== "/" ? path.replace(/\/+$/, "") : path const currentPath = normalizePath(pathname) const targetPath = normalizePath(itemUrl) if (targetPath === "/" || targetPath === "/dashboard") { return currentPath === targetPath } return currentPath === targetPath || currentPath.startsWith(targetPath + "/") } return ( {title} {items.map((item) => ( } isActive={isActive(item.url)} > {item.icon} {item.title} ))} ) }