"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; /** Weekly mode: the selected FY-month index + the 12 month options. */ month?: number; monthOptions?: { value: number; label: string }[]; exportHref: string; } const GRANS: Granularity[] = ["weekly", "monthly", "yearly"]; // Pinned filter toolbar shared by the report 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, month, monthOptions, 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"; const weekly = gran === "weekly"; return (
Granularity
{GRANS.map((g) => ( ))}
{!yearly && ( )} {weekly && monthOptions && ( )} {scope && ( )} Export
); }