import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import '../../../core/api/api_client_provider.dart'; class SessionActiveScreen extends ConsumerWidget { final String sessionId; final String mitraName; const SessionActiveScreen({ super.key, required this.sessionId, required this.mitraName, }); @override Widget build(BuildContext context, WidgetRef ref) { return Scaffold( appBar: AppBar( title: const Text('Sesi Aktif'), automaticallyImplyLeading: false, ), body: Center( child: Padding( padding: const EdgeInsets.all(32), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const Icon(Icons.chat_bubble, size: 80, color: Colors.blue), const SizedBox(height: 24), Text( 'Terhubung dengan $mitraName', style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), textAlign: TextAlign.center, ), const SizedBox(height: 8), const Text( 'Sesi chat akan tersedia di fase berikutnya.', textAlign: TextAlign.center, style: TextStyle(fontSize: 14, color: Colors.grey), ), const SizedBox(height: 48), ElevatedButton( style: ElevatedButton.styleFrom(backgroundColor: Colors.red), onPressed: () => _endSession(context, ref), child: const Text('Akhiri Sesi', style: TextStyle(color: Colors.white)), ), ], ), ), ), ); } Future _endSession(BuildContext context, WidgetRef ref) async { final confirmed = await showDialog( context: context, builder: (ctx) => AlertDialog( title: const Text('Akhiri Sesi?'), content: const Text('Apakah kamu yakin ingin mengakhiri sesi ini?'), actions: [ TextButton(onPressed: () => Navigator.of(ctx).pop(false), child: const Text('Batal')), TextButton(onPressed: () => Navigator.of(ctx).pop(true), child: const Text('Ya, Akhiri')), ], ), ); if (confirmed == true && context.mounted) { try { final apiClient = ref.read(apiClientProvider); await apiClient.post('/api/client/chat/session/$sessionId/end'); if (context.mounted) context.go('/home'); } catch (_) { if (context.mounted) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Gagal mengakhiri sesi. Coba lagi.')), ); } } } } }