// "use client"; // import { Button } from "@/components/ui/button"; // import { ChevronLeft, ChevronRight } from "lucide-react"; // import Link from "next/link"; // export default function Pagination({ currentPage, totalPages, basePath }) { // const createPageLink = (page) => `${basePath}?page=${page}`; // if (totalPages <= 1) return null; // const pagesToShow = 5; // const start = Math.max(0, currentPage - Math.floor(pagesToShow / 2)); // const end = Math.min(start + pagesToShow - 1, totalPages - 1); // const pageNumbers = []; // for (let i = start; i <= end; i++) { // pageNumbers.push(i); // } // return ( //
// {currentPage > 0 ? ( // // // // ) : ( // // )} // {pageNumbers.map((page) => ( // // // // ))} // {currentPage < totalPages - 1 ? ( // // // // ) : ( // // )} //
// ); // } "use client"; import { Button } from "@/components/ui/button"; import { ChevronLeft, ChevronRight } from "lucide-react"; import Link from "next/link"; export default function Pagination({ currentPage, totalPages, basePath, onPageChange }) { if (totalPages <= 1) return null; const pagesToShow = 5; const start = Math.max(0, currentPage - Math.floor(pagesToShow / 2)); const end = Math.min(start + pagesToShow - 1, totalPages - 1); const pageNumbers = []; for (let i = start; i <= end; i++) { pageNumbers.push(i); } const goToPage = (page) => { if (onPageChange) { onPageChange(page); } }; const renderButton = (page, label = null) => { const content = ( ); return basePath && !onPageChange ? ( {content} ) : ( {content} ); }; return (
{/* Previous */} {currentPage > 0 ? ( basePath && !onPageChange ? ( ) : ( ) ) : ( )} {/* Pages */} {pageNumbers.map((page) => renderButton(page))} {/* Next */} {currentPage < totalPages - 1 ? ( basePath && !onPageChange ? ( ) : ( ) ) : ( )}
); }