)}
);
}
function Pagination({ currentPage, totalPages, searchParams }:{ currentPage: number; totalPages: number, searchParams: URLSearchParams }) {
// Calculate the range of page numbers to show
let startPage: number;
let endPage: number;
if (totalPages <= 9) {
// If there are fewer than 9 pages, show all of them
startPage = 1;
endPage = totalPages;
} else {
// If we have more than 9 pages, calculate the window
if (currentPage <= 5) {
// When we're at the start, show pages 1-9
startPage = 1;
endPage = 9;
} else if (currentPage >= totalPages - 4) {
// When we're near the end, show the last 9 pages
startPage = totalPages - 8;
endPage = totalPages;
} else {
// Otherwise, center the window around the current page
startPage = currentPage - 4;
endPage = currentPage + 4;
}
}
const pages = Array.from({ length: endPage - startPage + 1 }, (_, i) => startPage + i);
let passThroughParams = ''
searchParams.forEach((val, key) => {
if(key != 'page')
passThroughParams += `&${key}=${val}`
})
return (
);
}