import 'package:flutter/material.dart'; import '../../../data/models/event_model.dart'; import '../../widgets/event_header.dart'; import '../../widgets/event_image.dart'; import '../../widgets/event_interaction_row.dart'; import '../../widgets/event_status_badge.dart'; import '../../widgets/swipe_background.dart'; class EventCard extends StatelessWidget { final EventModel event; final String userId; final String userName; final String userLastName; final String status; final VoidCallback onReact; final VoidCallback onComment; final VoidCallback onShare; final VoidCallback onParticipate; final VoidCallback onCloseEvent; final VoidCallback onReopenEvent; final Function onRemoveEvent; const EventCard({ Key? key, required this.event, required this.userId, required this.userName, required this.userLastName, required this.status, required this.onReact, required this.onComment, required this.onShare, required this.onParticipate, required this.onCloseEvent, required this.onReopenEvent, required this.onRemoveEvent, }) : super(key: key); @override Widget build(BuildContext context) { final GlobalKey menuKey = GlobalKey(); return Dismissible( key: ValueKey(event.id), direction: event.status == 'fermé' ? DismissDirection.startToEnd : DismissDirection.endToStart, onDismissed: (direction) { if (event.status == 'fermé') { onReopenEvent(); } else { onCloseEvent(); onRemoveEvent(event.id); } }, background: SwipeBackground( color: event.status == 'fermé' ? Colors.green : Colors.red, icon: event.status == 'fermé' ? Icons.lock_open : Icons.lock, label: event.status == 'fermé' ? 'Rouvrir' : 'Fermer', ), child: Card( color: const Color(0xFF2C2C3E), margin: const EdgeInsets.symmetric(vertical: 10.0), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)), child: Padding( padding: const EdgeInsets.all(12.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ EventHeader( userName: userName, userLastName: userLastName, eventDate: event.startDate, imageUrl: event.imageUrl, menuKey: menuKey, menuContext: context, location: event.location, onClose: () { }, ), const Divider(color: Colors.white24), Row( children: [ const Spacer(), // Pusher le badge statut à la droite. EventStatusBadge(status: status), ], ), Text( event.title, style: const TextStyle( color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold), ), const SizedBox(height: 5), Text( event.description, style: const TextStyle(color: Colors.white70, fontSize: 14), maxLines: 3, overflow: TextOverflow.ellipsis, ), const SizedBox(height: 10), EventImage(imageUrl: event.imageUrl), const Divider(color: Colors.white24), EventInteractionRow( onReact: onReact, onComment: onComment, onShare: onShare, reactionsCount: event.reactionsCount, commentsCount: event.commentsCount, sharesCount: event.sharesCount, ), ], ), ), ), ); } }