"use client"; import { useMemo } from "react"; import { Button } from "@/components/ui/button"; import { ChevronLeft, ChevronRight } from "lucide-react"; interface PaginationProps { page: number; total: number; limit: number; onPageChange: (page: number) => void; } function getPageNumbers(currentPage: number, totalPages: number): (number | "...")[] { if (totalPages <= 7) { return Array.from({ length: totalPages }, (_, i) => i + 1); } const pages: (number | "...")[] = [1]; if (currentPage > 3) pages.push("..."); const start = Math.max(2, currentPage - 1); const end = Math.min(totalPages - 1, currentPage + 1); for (let i = start; i <= end; i++) pages.push(i); if (currentPage < totalPages - 2) pages.push("..."); pages.push(totalPages); return pages; } export function Pagination({ page, total, limit, onPageChange }: PaginationProps) { const totalPages = useMemo(() => Math.max(1, Math.ceil(total / limit)), [total, limit]); const rangeStart = total === 0 ? 0 : (page - 1) * limit + 1; const rangeEnd = Math.min(page * limit, total); const pageNumbers = useMemo(() => getPageNumbers(page, totalPages), [page, totalPages]); if (total <= 0) return null; return (

Showing {rangeStart}\u2013{rangeEnd} of {total}

{pageNumbers.map((p, i) => p === "..." ? ( ) : ( ) )}
); }