import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import '../data/app_data.dart'; import 'ticket_page.dart'; class MyBookingsPage extends StatelessWidget { final String username; const MyBookingsPage({super.key, required this.username}); @override Widget build(BuildContext context) { final userBookings = AppData.bookings .where((b) => b.user == username) .toList() .reversed .toList(); return Scaffold( appBar: AppBar( backgroundColor: Colors.black, title: const Text('Tiket Saya'), ), body: userBookings.isEmpty ? Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const Icon( Icons.confirmation_number_outlined, size: 100, color: Colors.grey, ), const SizedBox(height: 24), const Text( 'Belum ada tiket', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), const SizedBox(height: 8), const Text( 'Pesan tiket sekarang!', style: TextStyle(color: Colors.grey), ), const SizedBox(height: 24), ElevatedButton( onPressed: () => Navigator.pop(context), style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFFFBBF24), foregroundColor: Colors.black, padding: const EdgeInsets.symmetric( horizontal: 32, vertical: 16, ), ), child: const Text('Lihat Film'), ), ], ), ) : ListView.builder( padding: const EdgeInsets.all(24), itemCount: userBookings.length, itemBuilder: (context, index) { final booking = userBookings[index]; final bookingDate = DateTime.parse(booking.date); final isPast = bookingDate.isBefore(DateTime.now()); return Container( margin: const EdgeInsets.only(bottom: 16), decoration: BoxDecoration( color: const Color(0xFF1F2937), borderRadius: BorderRadius.circular(16), border: Border.all(color: const Color(0xFF374151)), ), child: Material( color: Colors.transparent, child: InkWell( onTap: () { Navigator.push( context, MaterialPageRoute( builder: (_) => TicketPage(booking: booking), ), ); }, borderRadius: BorderRadius.circular(16), child: Padding( padding: const EdgeInsets.all(20), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Container( padding: const EdgeInsets.symmetric( horizontal: 12, vertical: 6, ), decoration: BoxDecoration( color: isPast ? Colors.grey.shade800 : const Color( 0xFFFBBF24, ).withOpacity(0.2), borderRadius: BorderRadius.circular(8), border: Border.all( color: isPast ? Colors.grey : const Color(0xFFFBBF24), ), ), child: Text( isPast ? 'SELESAI' : 'AKTIF', style: TextStyle( fontSize: 11, fontWeight: FontWeight.bold, color: isPast ? Colors.grey : const Color(0xFFFBBF24), ), ), ), const Spacer(), Text( booking.code, style: const TextStyle( fontWeight: FontWeight.bold, color: Color(0xFFFBBF24), ), ), ], ), const SizedBox(height: 16), Text( booking.film, style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), const SizedBox(height: 12), Row( children: [ const Icon( Icons.calendar_today, size: 16, color: Colors.grey, ), const SizedBox(width: 8), Text( DateFormat( 'EEE, dd MMM yyyy', ).format(bookingDate), style: const TextStyle(color: Colors.grey), ), const SizedBox(width: 24), const Icon( Icons.access_time, size: 16, color: Colors.grey, ), const SizedBox(width: 8), Text( booking.schedule, style: const TextStyle(color: Colors.grey), ), ], ), const SizedBox(height: 8), Row( children: [ const Icon( Icons.location_on, size: 16, color: Colors.grey, ), const SizedBox(width: 8), Text( booking.cinema, style: const TextStyle(color: Colors.grey), ), ], ), const SizedBox(height: 8), Row( children: [ const Icon( Icons.event_seat, size: 16, color: Colors.grey, ), const SizedBox(width: 8), Text( booking.seats.join(', '), style: const TextStyle(color: Colors.grey), ), ], ), const SizedBox(height: 16), const Divider(color: Color(0xFF374151)), const SizedBox(height: 12), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ const Text( 'Total Pembayaran', style: TextStyle(fontWeight: FontWeight.w600), ), Text( 'Rp ${_formatPrice(booking.price)}', style: const TextStyle( fontSize: 18, fontWeight: FontWeight.bold, color: Color(0xFFFBBF24), ), ), ], ), ], ), ), ), ), ); }, ), ); } String _formatPrice(int price) { return price.toString().replaceAllMapped( RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'), (m) => '${m[1]}.', ); } }