import { format } from 'date-fns'; import type { CleanupEvent, EventStatus } from '@/types'; interface EventListProps { events: CleanupEvent[]; onEventClick: (event: CleanupEvent) => void; onRegister?: (eventId: string) => void; isLoading?: boolean; } export function EventList({ events, onEventClick, onRegister, isLoading = false }: EventListProps) { if (isLoading) { return (
{[1, 2, 3].map((i) => (
))}
); } if (events.length === 0) { return (

No events found

Try adjusting your filters or create a new cleanup event.

); } const getStatusBadge = (status: EventStatus) => { const styles = { upcoming: 'bg-blue-100 text-blue-800', completed: 'bg-green-100 text-green-800', cancelled: 'bg-red-100 text-red-800', }; const labels = { upcoming: 'Upcoming', completed: 'Completed', cancelled: 'Cancelled', }; return ( {labels[status]} ); }; const formatEventDate = (date: Date) => { return format(new Date(date), 'EEEE, MMMM d, yyyy'); }; const formatEventTime = (date: Date) => { return format(new Date(date), 'h:mm a'); }; const formatDuration = (minutes: number) => { if (minutes < 60) { return `${minutes} min`; } const hours = Math.floor(minutes / 60); const mins = minutes % 60; return mins > 0 ? `${hours}h ${mins}m` : `${hours}h`; }; return (
{events.map((event) => (
onEventClick(event)} >

{event.title}

{getStatusBadge(event.status)} {event.participantCount} {event.participantCount === 1 ? 'participant' : 'participants'}
{/* Date and Time */}
{formatEventDate(event.scheduledDate)} at {formatEventTime(event.scheduledDate)}
{/* Duration */}
{formatDuration(event.duration)}
{/* Location */}
{event.locationName}
{/* Description Preview */}

{event.description}

{/* Completed Event Info */} {event.status === 'completed' && event.litterCollected !== undefined && (
{event.litterCollected} kg of litter collected
)} {/* Action Button */} {event.status === 'upcoming' && onRegister && ( )}
))}
); }