import 'package:wanisdriver/Provider/utils_singleton.dart'; import 'package:wanisdriver/utils/colors.dart'; import 'package:flutter/material.dart'; import '../Screen/ride_details_screen.dart'; import '../models/Ride.dart'; import 'custom_text.dart'; class PickupCard extends StatelessWidget { final Ride details; final bool myPickUp; final bool? isLoadingAccept; final bool? isLoadingDecline; final VoidCallback onAddToPickups; final VoidCallback onDecline; const PickupCard({ Key? key, required this.details, required this.onAddToPickups, required this.onDecline, required this.myPickUp, this.isLoadingAccept, this.isLoadingDecline, }) : super(key: key); @override Widget build(BuildContext context) { print( "************************************************************************* ${details.totalPrice}"); print( "************************************************************************* ${details.rideStatus}"); final isCorporate = (details.rideclienttype ?? '').toUpperCase() == 'CORPORATE'; return InkWell( onTap: () { myPickUp ? Navigator.push( context, MaterialPageRoute( builder: (context) => RideDetailScreen( ride: details, ))) : null; }, child: Container( margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), child: Card( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16.0), side: BorderSide( color: isCorporate ? const Color(0xFFD4A017) : Colors.transparent, width: isCorporate ? 1.8 : 0, ), ), color: isCorporate ? const Color(0xFFFFF8E1) : null, elevation: 2, child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ // Header Section with Date and Time Container( padding: const EdgeInsets.symmetric( horizontal: 16.0, vertical: 12.0), decoration: BoxDecoration( color: details.rideStatus == "CANCELLED" ? AppColors.secondaryColor : Theme.of(context).brightness == Brightness.dark ?AppColors.darkPrimaryColor:AppColors.primaryColor, // Purple color borderRadius: BorderRadius.vertical(top: Radius.circular(16.0)), ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ const Icon(Icons.calendar_today, color: Colors.white, size: 14), const SizedBox(width: 8.0), Text( _formatDateTime(details.rideStartTime!), style: const TextStyle( color: Colors.white, fontWeight: FontWeight.w500, fontSize: 12, ), overflow: TextOverflow.ellipsis, ), const SizedBox(width: 8.0), ], ), if (details.rideStatus == "CANCELLED") const Txt( text: "Cancelled", style: TextStyle( color: Colors.white, fontWeight: FontWeight.w500, fontSize: 13, ), overflow: TextOverflow.ellipsis, ), ], ), ), // Content Section Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ // Locations column (left) Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // Start Location Row( children: [ Container( width: 8, height: 8, decoration: const BoxDecoration( color: Colors.green, shape: BoxShape.circle, ), ), const SizedBox(width: 8.0), Flexible( child: Text( details.startLocationName ?? 'Unknown Location', style: const TextStyle( overflow: TextOverflow.ellipsis, fontWeight: FontWeight.w600, fontSize: 14, ), ), ), ], ), const SizedBox(height: 12.0), // End Location Row( children: [ Container( width: 8, height: 8, decoration: const BoxDecoration( color: AppColors.secondaryColor, shape: BoxShape.circle, ), ), const SizedBox(width: 8.0), Flexible( child: Text( details.endLocationName ?? 'Unknown Location', style: const TextStyle( overflow: TextOverflow.ellipsis, fontWeight: FontWeight.w600, fontSize: 14, ), ), ), ], ), ], ), ), // Business badge + Program ID (right) Column( crossAxisAlignment: CrossAxisAlignment.end, mainAxisSize: MainAxisSize.min, children: [ if (isCorporate) Container( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5), decoration: BoxDecoration( color: const Color(0xFFFFF3CD), borderRadius: BorderRadius.circular(10), ), child: const Row( mainAxisSize: MainAxisSize.min, children: [ Icon(Icons.business_center, size: 14, color: Color(0xFFB8860B)), SizedBox(width: 5), Text( 'Business', style: TextStyle( fontSize: 12, color: Color(0xFFB8860B), fontWeight: FontWeight.w600, ), ), ], ), ), if (isCorporate && details.programid != null) const SizedBox(height: 6), if (details.programid != null) Container( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5), decoration: BoxDecoration( color: const Color(0xFFE8F0FE), borderRadius: BorderRadius.circular(10), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ const Icon(Icons.tag, size: 14, color: Color(0xFF1A73E8)), const SizedBox(width: 5), Text( '${details.programid}', style: const TextStyle( fontSize: 12, color: Color(0xFF1A73E8), fontWeight: FontWeight.w600, ), ), ], ), ), ], ), ], ), const SizedBox(height: 14.0), // Details Cards Row LayoutBuilder( builder: (context, constraints) { double cardWidth = (constraints.maxWidth) / 2.7; return Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ if (!isCorporate) Expanded( child: _buildDetailCard( 'TND', details.totalPrice != null ? details.totalPrice!.toStringAsFixed(2) : "0.0", Colors.orange, cardWidth, ), ), Expanded( child: _buildDetailCard('⏱️', '${details.durationInMinutes?.toStringAsFixed(0) ?? '0'} min', Colors.orange, cardWidth), ), Expanded( child: _buildDetailCard('📍', '${details.distancekm.toStringAsFixed(0) ?? '0'} km', Colors.orange, cardWidth), ), ], ); }, ), SizedBox(height: myPickUp ? 12.0 : 20.0), // Action Buttons myPickUp || details.rideStatus == "CANCELLED"|| details.driverId == utils.user?.driver?.id ? const SizedBox() : Container( margin: const EdgeInsets.only(top: 8.0), child: Row( children: [ Expanded( child: ElevatedButton( onPressed: (isLoadingAccept ?? false) ? null : onAddToPickups, style: ElevatedButton.styleFrom( backgroundColor: Theme.of(context).brightness == Brightness.dark ?AppColors.darkPrimaryColor:AppColors.primaryColor, foregroundColor: Colors.white, disabledBackgroundColor: AppColors .primaryColor .withOpacity(0.7), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(25.0), ), padding: const EdgeInsets.symmetric( vertical: 14.0), elevation: 0, ), child: (isLoadingAccept ?? false) ? const SizedBox( height: 20, width: 20, child: CircularProgressIndicator( color: Colors.white, strokeWidth: 2, ), ) : const Txt( text: 'Add to my pickups', style: TextStyle( fontWeight: FontWeight.w500, fontSize: 14, ), ), ), ), const SizedBox(width: 12.0), // Expanded( // child: OutlinedButton( // onPressed: (isLoadingDecline ?? false) // ? null // : onDecline, // style: OutlinedButton.styleFrom( // side: BorderSide( // color: (isLoadingDecline ?? false) // ? Colors.orange.withOpacity(0.5) // : Colors.orange, // width: 1.5), // foregroundColor: Colors.orange, // disabledForegroundColor: // Colors.orange.withOpacity(0.5), // shape: RoundedRectangleBorder( // borderRadius: // BorderRadius.circular(25.0), // ), // padding: const EdgeInsets.symmetric( // vertical: 14.0), // ), // child: (isLoadingDecline ?? false) // ? const SizedBox( // height: 20, // width: 20, // child: CircularProgressIndicator( // color: Colors.orange, // strokeWidth: 2, // ), // ) // : const Txt( // text: 'Decline', // style: TextStyle( // fontWeight: FontWeight.w500, // fontSize: 14, // ), // ), // ), // ), ], ), ), ], ), ), ], ), ), ), ); } Widget _buildDetailCard( String icon, String value, Color iconColor, double cardWidth) { return SizedBox( width: cardWidth.clamp(60.0, 100.0), // Responsive with min/max constraints child: Column( mainAxisSize: MainAxisSize.min, children: [ Container( width: 48, height: 48, decoration: BoxDecoration( color: Colors.grey[50], borderRadius: BorderRadius.circular(12.0), border: Border.all(color: Colors.grey[200]!, width: 1), ), child: Center( child: icon.contains('TND') ? Text( icon, style: TextStyle( color: iconColor, fontWeight: FontWeight.bold, fontSize: 12, ), ) : Text( icon, style: const TextStyle(fontSize: 20), ), ), ), const SizedBox(height: 6.0), icon.contains('TND') ? Row( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start, children: [ Flexible( child: Txt( text: "$value D ", style: const TextStyle( fontWeight: FontWeight.w600, fontSize: 10, ), textAlign: TextAlign.center, maxLines: 2, overflow: TextOverflow.ellipsis, ), ), const Flexible( child: Txt( text: "+ tarif compteur", style: TextStyle( fontWeight: FontWeight.w600, fontSize: 10, ), textAlign: TextAlign.center, maxLines: 2, overflow: TextOverflow.ellipsis, ), ), ], ) : Txt( text: value, style: const TextStyle( fontWeight: FontWeight.w600, fontSize: 10, ), textAlign: TextAlign.center, maxLines: 2, overflow: TextOverflow.ellipsis, ), ], ), ); } String _formatDateTime(DateTime dateTime) { final days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; final months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]; final dayName = days[dateTime.weekday - 1]; final day = dateTime.day; final month = months[dateTime.month - 1]; final year = dateTime.year; final hour = dateTime.hour.toString().padLeft(2, '0'); final minute = dateTime.minute.toString().padLeft(2, '0'); return '$dayName $day $month $year - $hour:$minute'; } }