import { useRouter, useSearch } from '@tanstack/react-router' import { ChevronLeft, ChevronRight } from 'lucide-react' interface PaginationProps { pageCount: number className?: string } export function Pagination({ pageCount, className = '' }: PaginationProps) { const router = useRouter() const search = useSearch({ strict: false }) const currentPage = Number((search as any)?.page) || 1 const handlePageChange = (page: number) => { router.navigate({ to: '.', search: (prev) => ({ ...prev, page }), replace: true, }) } // Generate page numbers to display const getPageNumbers = () => { const pages: Array = [] const showEllipsis = pageCount > 7 if (showEllipsis) { pages.push(1) if (currentPage > 3) { pages.push('ellipsis') } const start = Math.max(2, currentPage - 1) const end = Math.min(pageCount - 1, currentPage + 1) for (let i = start; i <= end; i++) { pages.push(i) } if (currentPage < pageCount - 2) { pages.push('ellipsis') } if (pageCount > 1) { pages.push(pageCount) } } else { for (let i = 1; i <= pageCount; i++) { pages.push(i) } } return pages } const pageNumbers = getPageNumbers() if (pageCount <= 1) return null return ( ) }