import React from 'react'; interface PaginationProps { currentPage: number; totalPages: number; onPageChange: (page: number) => void; } const Pagination: React.FC = ({ currentPage, totalPages, onPageChange }) => { // Generate page buttons const getPageButtons = () => { const buttons = []; const maxDisplayedPages = 5; // Maximum number of page buttons to display // Always display first page buttons.push( ); // Start range const startPage = Math.max(2, currentPage - Math.floor(maxDisplayedPages / 2)); // If we're showing ellipsis after first page if (startPage > 2) { buttons.push( ... ); } // Middle pages for (let i = startPage; i <= Math.min(totalPages - 1, startPage + maxDisplayedPages - 3); i++) { buttons.push( ); } // If we're showing ellipsis before last page if (startPage + maxDisplayedPages - 3 < totalPages - 1) { buttons.push( ... ); } // Always display last page if there's more than one page if (totalPages > 1) { buttons.push( ); } return buttons; }; // If there's only one page, don't render pagination if (totalPages <= 1) { return null; } return (
{getPageButtons()}
); }; export default Pagination;