'use client' import React from 'react' import { ChevronLeft, ChevronRight, RotateCcw, Home } from 'lucide-react' import { cn } from '../../utils/cn' import { Button } from './button' export interface CursorPaginationProps { hasNextPage: boolean hasPreviousPage?: boolean isFirstPage?: boolean startCursor?: string | null endCursor?: string | null currentCount?: number totalCount?: number | null itemName?: string loading?: boolean onNext?: (cursor: string) => void onPrevious?: (cursor: string) => void onReset?: () => void className?: string showInfo?: boolean compact?: boolean resetButtonLabel?: string resetButtonIcon?: 'home' | 'rotate' } export function CursorPagination({ hasNextPage, hasPreviousPage, isFirstPage = true, startCursor, endCursor, currentCount, totalCount, itemName = 'items', loading = false, onNext, onPrevious, onReset, className, showInfo = true, compact = false, resetButtonLabel = 'First', resetButtonIcon = 'home' }: CursorPaginationProps) { const handleNext = () => { if (hasNextPage && endCursor && onNext) { onNext(endCursor) } } const handlePrevious = () => { if (hasPreviousPage && startCursor && onPrevious) { onPrevious(startCursor) } } const handleReset = () => { if (onReset) { onReset() } } const ResetIcon = resetButtonIcon === 'rotate' ? RotateCcw : Home const getDisplayText = () => { if (!showInfo || !currentCount) return null if (totalCount) { return `Showing ${currentCount} of ${totalCount} ${itemName}` } else if (hasNextPage) { return `Showing ${currentCount}+ ${itemName}` } else { return `Showing ${currentCount} ${itemName}` } } const displayText = getDisplayText() return (