import React from 'react'; const Pagination = ({ currentPage, totalPages, onPageChange }) => { const handlePageClick = (e, page) => { if (e) { e.preventDefault(); } if (page !== currentPage && page >= 1 && page <= totalPages) { onPageChange(page); // Scroll to top of blog section smoothly const blogSection = document.querySelector('.blog-section'); if (blogSection) { const offset = 100; // Offset from top const elementPosition = blogSection.getBoundingClientRect().top; const offsetPosition = elementPosition + window.pageYOffset - offset; window.scrollTo({ top: offsetPosition, behavior: 'smooth' }); } } }; const renderPageNumbers = () => { const pages = []; const maxVisiblePages = 5; let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2)); let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1); if (endPage - startPage < maxVisiblePages - 1) { startPage = Math.max(1, endPage - maxVisiblePages + 1); } for (let i = startPage; i <= endPage; i++) { pages.push( ); } return pages; }; return (