import React from 'react'; import Image from "next/image"; interface PaginationProps { totalItems: number; itemsPerPage: number; currentPage: number; onPageChange: (page: number) => void; } const Pagination: React.FC = ({ totalItems, itemsPerPage, currentPage, onPageChange, }) => { const totalPages = Math.ceil(totalItems / itemsPerPage); const getPaginationArray = () => { const pages: (number | string)[] = []; if (totalPages <= 5) { for (let i = 1; i <= totalPages; i++) { pages.push(i); } } else { pages.push(1); if (currentPage > 3) { pages.push('...'); } for (let i = Math.max(2, currentPage - 1); i <= Math.min(currentPage + 1, totalPages - 1); i++) { pages.push(i); } if (currentPage < totalPages - 2) { pages.push('...'); } pages.push(totalPages); } return pages; }; const handlePageChange = (page: number) => { if (page !== currentPage) { onPageChange(page); } }; const paginationArray = getPaginationArray(); return (
{paginationArray.map((page, index) => ( typeof page === 'number' ? ( ) : ( {page} // Отображаем многоточие ) ))}
); }; export default Pagination;