import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, } from '@/components/ui/pagination' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select' interface AppPaginationProps { currentPage: number totalPages: number totalCount: number pageSize: number pageSizeOptions?: number[] onPageChange: (page: number) => void onPageSizeChange: (size: number) => void itemName?: string // e.g., "items", "extractions", "playlists" } export function AppPagination({ currentPage, totalPages, totalCount, pageSize, pageSizeOptions = [10, 20, 50, 100], onPageChange, onPageSizeChange, itemName = 'items', }: AppPaginationProps) { // Don't render if there are no items if (totalCount === 0) return null const getVisiblePages = () => { const delta = 2 const range = [] const rangeWithDots = [] for ( let i = Math.max(2, currentPage - delta); i <= Math.min(totalPages - 1, currentPage + delta); i++ ) { range.push(i) } if (currentPage - delta > 2) { rangeWithDots.push(1, '...') } else { rangeWithDots.push(1) } rangeWithDots.push(...range) if (currentPage + delta < totalPages - 1) { rangeWithDots.push('...', totalPages) } else if (totalPages > 1) { rangeWithDots.push(totalPages) } return rangeWithDots } const startItem = Math.min((currentPage - 1) * pageSize + 1, totalCount) const endItem = Math.min(currentPage * pageSize, totalCount) return (

Showing {startItem} to {endItem} of {totalCount} {itemName}

{ e.preventDefault() if (currentPage > 1) onPageChange(currentPage - 1) }} className={currentPage <= 1 ? 'pointer-events-none opacity-50' : ''} /> {getVisiblePages().map((page, index) => ( {page === '...' ? ( ) : ( { e.preventDefault() onPageChange(page as number) }} isActive={currentPage === page} > {page} )} ))} { e.preventDefault() if (currentPage < totalPages) onPageChange(currentPage + 1) }} className={currentPage >= totalPages ? 'pointer-events-none opacity-50' : ''} />
Show rows
) }