"use client"; import { useCollection } from "@/hooks/useCollection"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Button } from "@/components/ui/button"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { useState } from "react"; interface CollectionTableProps> { collectionName: string; title: string; columns: Array<{ key: string; label: string; render?: (value: unknown, item: T) => React.ReactNode; }>; } export function CollectionTable>({ collectionName, title, columns }: CollectionTableProps) { const [page, setPage] = useState(1); const { data, loading, error, total, totalPages } = useCollection( collectionName, { page, limit: 20 } ); if (loading) { return ( {title}
{Array.from({ length: 5 }).map((_, i) => (
))}
); } if (error) { return ( {title}
Erreur: {error}
); } return ( {title} ({total} éléments) {columns.map((column) => ( {column.label} ))} {data.map((item, index) => ( {columns.map((column) => ( {column.render ? column.render(item[column.key], item) : String(item[column.key] || '-') } ))} ))}
{totalPages > 1 && (

Page {page} sur {totalPages}

)}
); }