"use client"; import { useRouter, usePathname, useSearchParams } from "next/navigation"; import { Download } from "lucide-react"; import { cn } from "@/lib/utils"; import { fyLabel, SCOPE_LABELS, type Granularity, type ScopeMode } from "@/lib/reports"; interface Props { fys: number[]; fy: number; gran: Granularity; /** Pass a scope to render the Top/Bottom-N "Show" control (index pages only). */ scope?: ScopeMode; exportHref: string; } // Pinned filter toolbar shared by the report index pages. Each control writes its // value into the URL query string (preserving the rest) so the server component // re-renders the report for the new filters — no client-side data fetching. export function ReportsToolbar({ fys, fy, gran, scope, exportHref }: Props) { const router = useRouter(); const pathname = usePathname(); const sp = useSearchParams(); function update(patch: Record) { const q = new URLSearchParams(sp.toString()); for (const [k, v] of Object.entries(patch)) { if (v === null || v === "") q.delete(k); else q.set(k, v); } const qs = q.toString(); router.push(qs ? `${pathname}?${qs}` : pathname); } const yearly = gran === "yearly"; return (
Granularity
{(["monthly", "yearly"] as Granularity[]).map((g) => ( ))}
{!yearly && ( )} {scope && ( )} Export
); }