"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { cn } from "@/lib/utils"; export interface AdminTab { href: string; label: string; /** Extra prefixes that count as active for this tab (detail routes). */ match?: string[]; } function matchLength(pathname: string, prefix: string): number { if (pathname === prefix) return prefix.length + 1; // prefer exact if (pathname.startsWith(`${prefix}/`)) return prefix.length; return -1; } export function AdminSectionTabs({ tabs }: { tabs: AdminTab[] }) { const pathname = usePathname() ?? ""; let bestIndex = -1; let bestScore = -1; tabs.forEach((tab, index) => { const prefixes = tab.match ?? [tab.href]; for (const prefix of prefixes) { const score = matchLength(pathname, prefix); if (score > bestScore) { bestScore = score; bestIndex = index; } } }); return ( ); }