import 'package:flutter/material.dart'; import '../../services/notification_service.dart'; class InvitationsPage extends StatefulWidget { @override _InvitationsPageState createState() => _InvitationsPageState(); } class _InvitationsPageState extends State { bool _isAccepted = false; bool _isLoading = false; Future _acceptCoffeeInvite() async { setState(() { _isLoading = true; }); try { final success = await NotificationService() .sendCoffeeInviteAcceptedNotification(); if (success) { setState(() { _isAccepted = true; _isLoading = false; }); ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( 'Coffee invite accepted! Notification sent to everyone.', ), backgroundColor: Colors.green, duration: Duration(seconds: 3), ), ); } else { setState(() { _isLoading = false; }); ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( 'Failed to send notification. Check Firebase service account configuration.', ), backgroundColor: Colors.orange, duration: Duration(seconds: 3), ), ); } } catch (e) { setState(() { _isLoading = false; }); ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Error: $e'), backgroundColor: Colors.red, duration: Duration(seconds: 3), ), ); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text( 'Invitations', style: TextStyle(fontWeight: FontWeight.w600), ), backgroundColor: Colors.white, foregroundColor: Color(0xFF6A4C93), elevation: 0, bottom: PreferredSize( preferredSize: Size.fromHeight(1), child: Container(height: 1, color: Colors.grey[200]), ), automaticallyImplyLeading: false, ), body: Padding( padding: EdgeInsets.all(16), child: Column( children: [ // Coffee Invitation Card Container( margin: EdgeInsets.only(bottom: 16), padding: EdgeInsets.all(20), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(12), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.08), blurRadius: 10, offset: Offset(0, 2), ), ], border: Border.all( color: Colors.grey.withOpacity(0.2), width: 1, ), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // Header with icon and title Row( children: [ Container( padding: EdgeInsets.all(8), decoration: BoxDecoration( color: Color(0xFF6A4C93).withOpacity(0.1), borderRadius: BorderRadius.circular(8), ), child: Icon( Icons.coffee, color: Color(0xFF6A4C93), size: 24, ), ), SizedBox(width: 12), Expanded( child: Text( 'Who\'s down for coffee?', style: TextStyle( fontSize: 18, fontWeight: FontWeight.w600, color: Colors.black87, ), ), ), ], ), SizedBox(height: 16), // Description Text( 'Quick coffee break at the campus café. Let\'s catch up!', style: TextStyle( fontSize: 14, color: Colors.grey[700], height: 1.4, ), ), SizedBox(height: 16), // Status indicator Row( children: [ Container( padding: EdgeInsets.symmetric( horizontal: 8, vertical: 4, ), decoration: BoxDecoration( color: _isAccepted ? Colors.green.withOpacity(0.1) : Colors.orange.withOpacity(0.1), borderRadius: BorderRadius.circular(12), ), child: Text( _isAccepted ? 'Accepted ✓' : '1 more person needed', style: TextStyle( fontSize: 12, fontWeight: FontWeight.w500, color: _isAccepted ? Colors.green[700] : Colors.orange[700], ), ), ), Spacer(), Text( '10 min ago', style: TextStyle(fontSize: 12, color: Colors.grey[500]), ), ], ), SizedBox(height: 16), // Accept button SizedBox( width: double.infinity, height: 44, child: ElevatedButton( onPressed: _isAccepted ? null : (_isLoading ? null : _acceptCoffeeInvite), style: ElevatedButton.styleFrom( backgroundColor: _isAccepted ? Colors.grey[300] : Color(0xFF6A4C93), foregroundColor: _isAccepted ? Colors.grey[600] : Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8), ), elevation: _isAccepted ? 0 : 2, ), child: _isLoading ? SizedBox( width: 20, height: 20, child: CircularProgressIndicator( valueColor: AlwaysStoppedAnimation( Colors.white, ), strokeWidth: 2, ), ) : Text( _isAccepted ? 'Accepted' : 'Accept Invite', style: TextStyle( fontSize: 16, fontWeight: FontWeight.w600, ), ), ), ), ], ), ), // Info text if (!_isAccepted) Container( padding: EdgeInsets.all(16), decoration: BoxDecoration( color: Colors.blue.withOpacity(0.05), borderRadius: BorderRadius.circular(8), border: Border.all(color: Colors.blue.withOpacity(0.2)), ), child: Row( children: [ Icon(Icons.info_outline, color: Colors.blue[600], size: 20), SizedBox(width: 8), Expanded( child: Text( 'This is a test invitation :)', style: TextStyle(fontSize: 13, color: Colors.blue[700]), ), ), ], ), ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: () { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Create invitation functionality coming soon!'), ), ); }, backgroundColor: Color(0xFF6A4C93), child: Icon(Icons.person_add, color: Colors.white), ), ); } }