"use client"; import { useRouter, useSearchParams } from "next/navigation"; import { Button } from "@/components/ui/button"; import { ChevronLeft, ChevronRight } from "lucide-react"; interface PaginationProps { page: number; totalPages: number; total: number; } export function Pagination({ page, totalPages, total }: PaginationProps) { const router = useRouter(); const searchParams = useSearchParams(); if (totalPages <= 1) return null; const goToPage = (p: number) => { const params = new URLSearchParams(searchParams.toString()); params.set("page", String(p)); router.push(`?${params.toString()}`); }; // Show at most 5 page numbers const getPageNumbers = () => { const pages: number[] = []; const start = Math.max(1, page - 2); const end = Math.min(totalPages, start + 4); for (let i = start; i <= end; i++) pages.push(i); return pages; }; return (

Page {page} of {totalPages} ({total} posts)

{getPageNumbers().map((p) => ( ))}
); }