"use client"; import Link from "next/link"; import { ChevronLeft, ChevronRight } from "lucide-react"; interface PaginationProps { total: number; page: number; size: number; basePath: string; query?: Record; onChange?: (page: number) => void; } export default function Pagination({ total, page, size, basePath, query = {}, onChange }: PaginationProps) { const totalPages = Math.max(1, Math.ceil(total / size)); if (totalPages <= 1) return null; const buildHref = (p: number) => { const params = new URLSearchParams(query); params.set("page", String(p)); return `${basePath}?${params.toString()}`; }; const handleClick = (p: number, e: React.MouseEvent) => { if (onChange) { e.preventDefault(); onChange(p); } }; const pages: (number | "...")[] = []; const add = (p: number | "...") => pages.push(p); if (totalPages <= 7) { for (let i = 1; i <= totalPages; i++) add(i); } else { add(1); if (page > 4) add("..."); const start = Math.max(2, page - 1); const end = Math.min(totalPages - 1, page + 1); for (let i = start; i <= end; i++) add(i); if (page < totalPages - 3) add("..."); add(totalPages); } const cls = "pager-btn min-w-[38px] h-9 px-1 flex items-center justify-center font-semibold text-[13px] rounded-full border transition-colors duration-150"; return ( ); }