"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import type { ReactNode } from "react"; import { useAdminMobile } from "@/components/admin/admin-mobile-wrapper"; /** * Sidebar link that highlights when its route is active. * Optional matchPrefixes cover multi-page hubs (e.g. Settings → theme/vpn). */ export function AdminNavLink({ href, icon, matchPrefixes, children, }: { href: string; icon?: ReactNode; matchPrefixes?: string[]; children: ReactNode; }) { const pathname = usePathname() ?? ""; const { close } = useAdminMobile(); let active: boolean; if (href === "/admin") { active = pathname === "/admin"; } else if (matchPrefixes?.length) { active = matchPrefixes.some( (p) => pathname === p || pathname.startsWith(`${p}/`), ); } else { active = pathname === href || pathname.startsWith(`${href}/`); } return ( {icon ? ( {icon} ) : null} {children} ); }