import React from "react"; import { Button } from "../ui/button"; import { __ } from "../../lib/i18n"; interface PaginationProps { currentPage: number; totalPages: number; totalItems: number; itemsPerPage: number; onPageChange: (page: number) => void; itemName?: string; // e.g., 'activities', 'destinations' } export const Pagination: React.FC = ({ currentPage, totalPages, totalItems, itemsPerPage, onPageChange, itemName = "items", }) => { // Generate page numbers with ellipsis const generatePageNumbers = () => { const pages = []; const maxVisiblePages = 5; let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2)); let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1); // Adjust start if we're near the end if (endPage - startPage + 1 < maxVisiblePages) { startPage = Math.max(1, endPage - maxVisiblePages + 1); } // First page + ellipsis if (startPage > 1) { pages.push( , ); if (startPage > 2) { pages.push( ... , ); } } // Visible page range for (let i = startPage; i <= endPage; i++) { pages.push( , ); } // Ellipsis + last page if (endPage < totalPages) { if (endPage < totalPages - 1) { pages.push( ... , ); } pages.push( , ); } return pages; }; return (
{__("Showing", "yatra")}{" "} {(currentPage - 1) * itemsPerPage + 1} {" "} -{" "} {Math.min(currentPage * itemsPerPage, totalItems)} {" "} {__("of", "yatra")}{" "} {totalItems} {" "} {itemName}
{/* Previous Button */} {/* Page Numbers */} {generatePageNumbers()} {/* Next Button */}
); };