import React from 'react'; import { Button, Container } from '@ifrc-go/ui'; import { ChevronLeftLineIcon, ChevronRightLineIcon } from '@ifrc-go/icons'; import styles from './Paginator.module.css'; interface PaginatorProps { currentPage: number; totalPages: number; totalItems: number; itemsPerPage: number; onPageChange: (page: number) => void; className?: string; } export default function Paginator({ currentPage, totalPages, totalItems, itemsPerPage, onPageChange, className = '' }: PaginatorProps) { const startIndex = (currentPage - 1) * itemsPerPage; const endIndex = Math.min(startIndex + itemsPerPage, totalItems); // Don't render if only one page if (totalPages <= 1) { return null; } // Generate page numbers to display const getPageNumbers = () => { const pages = []; const maxVisiblePages = 5; if (totalPages <= maxVisiblePages) { // Show all pages if total is small for (let i = 1; i <= totalPages; i++) { pages.push(i); } } else { // Show smart range of pages let start = Math.max(1, currentPage - 2); let end = Math.min(totalPages, start + maxVisiblePages - 1); // Adjust start if we're near the end if (end === totalPages) { start = Math.max(1, end - maxVisiblePages + 1); } for (let i = start; i <= end; i++) { pages.push(i); } } return pages; }; const pageNumbers = getPageNumbers(); return (