import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react" import { cn } from "../lib/utils" const DEFAULT_SIZES = [15, 30, 50] as const /** Номера страниц с многоточиями: 1 … 4 5 6 … 12 */ function pageList(current: number, pages: number): (number | "gap")[] { if (pages <= 7) return Array.from({ length: pages }, (_, i) => i) const set = new Set([0, pages - 1, current - 1, current, current + 1]) const sorted = [...set].filter((p) => p >= 0 && p < pages).sort((a, b) => a - b) return sorted.flatMap((p, i) => (i > 0 && p - sorted[i - 1] > 1 ? ["gap" as const, p] : [p])) } /** * Пагинация под таблицей: «1 – 15 из 42», страницы, размер страницы. * `page` — с нуля. */ export function Pagination({ total, page, size, onPageChange, onSizeChange, sizeOptions = DEFAULT_SIZES, className, }: { total: number page: number size: number onPageChange: (page: number) => void onSizeChange?: (size: number) => void sizeOptions?: readonly number[] className?: string }) { const pages = Math.max(1, Math.ceil(total / size)) const current = Math.min(page, pages - 1) const from = total ? current * size + 1 : 0 const to = Math.min((current + 1) * size, total) const pageButton = "grid h-7 min-w-7 place-items-center rounded-md px-1.5 text-xs font-medium tabular transition" return (
{from} – {to} из {total}
{pageList(current, pages).map((p, i) => p === "gap" ? ( … ) : ( ), )}
{onSizeChange ? (
{sizeOptions.map((s) => ( ))}
) : ( )}
) }