'use client' import { ChevronLeft, ChevronRight } from 'lucide-react' import { useState, useMemo, type ReactNode } from 'react' interface PaginatedCardListProps { items: T[] renderItem: (item: T, index: number) => ReactNode itemsPerPage: number title: string icon?: ReactNode subtitle?: string /** Function to extract unique key from item */ getItemKey?: (item: T, index: number) => string | number } export default function PaginatedCardList({ items, renderItem, itemsPerPage, title, icon, subtitle, getItemKey }: PaginatedCardListProps) { const [currentPage, setCurrentPage] = useState(1) const { totalPages, currentItems, startIndex } = useMemo(() => { const totalPages = Math.ceil(items.length / itemsPerPage) const startIndex = (currentPage - 1) * itemsPerPage const endIndex = startIndex + itemsPerPage const currentItems = items.slice(startIndex, endIndex) return { totalPages, currentItems, startIndex } }, [items, itemsPerPage, currentPage]) const goToNextPage = () => { if (currentPage < totalPages) { setCurrentPage(currentPage + 1) } } const goToPreviousPage = () => { if (currentPage > 1) { setCurrentPage(currentPage - 1) } } return (

{icon} {title}

{subtitle && (

{subtitle}

)}
{currentItems.map((item, index) => { const globalIndex = startIndex + index const key = getItemKey ? getItemKey(item, globalIndex) : globalIndex return
{renderItem(item, globalIndex)}
})}
{totalPages > 1 && (
Page {currentPage} of {totalPages}
)}
) }