'use client'; import { HugeiconsIcon } from '@hugeicons/react'; import { ChevronLeftIcon, ChevronRightIcon } from '@hugeicons/core-free-icons'; import { Button } from '@/components/ui/button'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; interface TablePaginationProps { page: number; pageSize: number; totalRecords: number; pageSizeOptions?: number[]; onPageChange: (page: number) => void; onPageSizeChange: (size: number) => void; } function buildPageNumbers(page: number, totalPages: number): (number | '...')[] { if (totalPages <= 7) return Array.from({ length: totalPages }, (_, i) => i + 1); const pages: (number | '...')[] = [1]; if (page > 3) pages.push('...'); for (let i = Math.max(2, page - 1); i <= Math.min(totalPages - 1, page + 1); i++) { pages.push(i); } if (page < totalPages - 2) pages.push('...'); pages.push(totalPages); return pages; } export function TablePagination({ page, pageSize, totalRecords, pageSizeOptions = [10, 25, 50, 100], onPageChange, onPageSizeChange, }: TablePaginationProps) { const totalPages = Math.max(1, Math.ceil(totalRecords / pageSize)); const from = Math.min((page - 1) * pageSize + 1, totalRecords); const to = Math.min(page * pageSize, totalRecords); const pages = buildPageNumbers(page, totalPages); return (
Rows per page: {totalRecords === 0 ? '0 records' : `${from}–${to} of ${totalRecords} records`}
{pages.map((p, i) => p === '...' ? ( … ) : ( ) )}
); }