"use client"; import type { ReactNode } from "react"; import { Button } from "@/components/ui/button"; import type { Meta } from "./import-furni-types"; export function Pagination({ meta, loading, onPageChange, }: { meta: Meta | null; loading: boolean; onPageChange: (page: number) => void; }) { if (!meta || meta.lastPage <= 1) return null; const nodes: ReactNode[] = []; if (meta.currentPage > 1) { nodes.push( , ); } for (let p = 1; p <= meta.lastPage; p++) { if (p === meta.currentPage) { nodes.push( , ); } else if ( Math.abs(p - meta.currentPage) <= 2 || p === 1 || p === meta.lastPage ) { nodes.push( , ); } else if (Math.abs(p - meta.currentPage) === 3) { nodes.push( … , ); } } if (meta.currentPage < meta.lastPage) { nodes.push( , ); } return (
{nodes}
); }