import Link from "next/link"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { fmtInt } from "@/lib/format"; import { cn } from "./cn"; export interface PaginationProps { page: number; perPage: number; total: number; /** returns href for a page number */ hrefFor: (page: number) => string; className?: string; label?: string; } /** Compact pager: "1–50 of 1,234" + prev/next + a few numbered links on ≥ sm. */ export function Pagination({ page, perPage, total, hrefFor, className, label = "results" }: PaginationProps) { const pages = Math.max(1, Math.ceil(total / Math.max(1, perPage))); if (total <= 0) return null; const from = (page - 1) * perPage + 1; const to = Math.min(total, page * perPage); const nums = new Set([1, pages, page, page - 1, page + 1, page - 2, page + 2].filter((n) => n >= 1 && n <= pages)); const list = Array.from(nums).sort((a, b) => a - b); return ( ); } function PageLink({ href, label, children }: { href: string | null; label: string; children: React.ReactNode }) { const cls = "inline-flex size-10 items-center justify-center rounded-sm border border-hair text-ink-2 sm:size-9"; if (!href) return {children}; return ( {children} ); }