export default function Pagination({ currentPage, totalPages, onPageChange }) {
if (totalPages <= 1) return null
const pages = []
const maxVisible = 5
let start = Math.max(1, currentPage - Math.floor(maxVisible / 2))
let end = Math.min(totalPages, start + maxVisible - 1)
if (end - start < maxVisible - 1) {
start = Math.max(1, end - maxVisible + 1)
}
for (let i = start; i <= end; i++) {
pages.push(i)
}
return (
{start > 1 && (
<>
{start > 2 && ...}
>
)}
{pages.map((page) => (
))}
{end < totalPages && (
<>
{end < totalPages - 1 && ...}
>
)}
)
}