"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useState } from "react"; import { BookIcon, CodeIcon, GearIcon, IssueOpenedIcon, PackageIcon, PlayIcon, PullRequestIcon } from "./icons"; import { SlidingIndicator, thumbClass } from "./sliding-indicator"; /** * A repository's sections on the switcher track: they are pages, so they are links (not MetalUI Tabs), * with the switcher's raised thumb gliding under the current one. */ export function RepoTabs({ base, openIssues, openPulls, images, showWiki, showSettings, }: { base: string; openIssues: number; openPulls: number; images: number; showWiki: boolean; showSettings: boolean; }) { const pathname = usePathname(); const section = pathname.slice(base.length).split("/")[1] ?? ""; const tabs = [ { href: base, label: "Code", icon: CodeIcon, active: !["issues", "pulls", "compare", "actions", "packages", "wiki", "settings"].includes(section) }, { href: `${base}/issues`, label: "Issues", icon: IssueOpenedIcon, count: openIssues, active: section === "issues" }, { href: `${base}/pulls`, label: "Pull Requests", icon: PullRequestIcon, count: openPulls, active: section === "pulls" || section === "compare" }, { href: `${base}/actions`, label: "Actions", icon: PlayIcon, active: section === "actions" }, { href: `${base}/packages`, label: "Packages", icon: PackageIcon, count: images, active: section === "packages" }, ...(showWiki ? [{ href: `${base}/wiki`, label: "Wiki", icon: BookIcon, active: section === "wiki" }] : []), ...(showSettings ? [{ href: `${base}/settings`, label: "Settings", icon: GearIcon, active: section === "settings" }] : []), ]; // Move the thumb as soon as a tab is clicked instead of waiting for the next page; // the optimistic choice is dropped once the URL changes. const [clicked, setClicked] = useState<{ from: string; index: number } | null>(null); const activeIndex = clicked?.from === pathname ? clicked.index : tabs.findIndex((t) => t.active); return (