import 'dart:async'; import 'package:flutter/material.dart'; import 'package:farolero/l10n/generated/app_localizations.dart'; import 'package:provider/provider.dart'; import '../estado/estado_juego.dart'; import '../tema/componentes_farolero.dart'; import 'pantalla_notas.dart'; import 'pantalla_votacion.dart'; class PantallaDebate extends StatefulWidget { const PantallaDebate({super.key}); @override State createState() => _PantallaDebateState(); } class _PantallaDebateState extends State { Timer? _timer; int _segundosRestantes = 0; bool _tiempoAgotado = false; @override void initState() { super.initState(); final estado = context.read(); final tiempo = estado.partida?.config.tiempoDebateSegundos; if (tiempo != null) { _segundosRestantes = tiempo; _timer = Timer.periodic(const Duration(seconds: 1), (timer) { if (_segundosRestantes > 0) { setState(() => _segundosRestantes--); } else { timer.cancel(); setState(() => _tiempoAgotado = true); } }); } } @override void dispose() { _timer?.cancel(); super.dispose(); } String _formatearTiempo(int segundos) { final min = segundos ~/ 60; final seg = segundos % 60; return "${min.toString().padLeft(2, '0')}:${seg.toString().padLeft(2, '0')}"; } void _irAVotacion() { final estado = context.read(); estado.iniciarVotacion(); Navigator.pushReplacement( context, MaterialPageRoute(builder: (_) => const PantallaVotacion()), ); } @override Widget build(BuildContext context) { final l10n = AppLocalizations.of(context)!; final estado = context.watch(); final partida = estado.partida; if (partida == null) return const SizedBox.shrink(); final tieneTemporizador = partida.config.tiempoDebateSegundos != null; return Scaffold( appBar: AppBar( title: Text(l10n.debateRound(partida.rondaActual)), automaticallyImplyLeading: false, ), body: FondoFarolero( intenso: true, child: SafeArea( child: Padding( padding: const EdgeInsets.all(16), child: Column( children: [ const ArteGameplayFarolero.fase(height: 110), const SizedBox(height: 10), if (tieneTemporizador) ...[ TemporizadorFarolero( etiqueta: _tiempoAgotado ? l10n.timeUp : l10n.timeRemaining, tiempo: _formatearTiempo(_segundosRestantes), agotado: _tiempoAgotado, ), const SizedBox(height: 16), ], Expanded( child: TarjetaFaseFarolero( icono: Icons.forum, titulo: l10n.playersInDebate, subtitulo: l10n.activePlayersInfo( partida.jugadoresActivos.length, partida.impostoresActivos.length, ), child: Expanded( child: ListView.separated( itemCount: partida.jugadores.length, separatorBuilder: (context, index) => const SizedBox(height: 8), itemBuilder: (context, index) { final jugador = partida.jugadores[index]; return EstadoJugadorFarolero( nombre: '${index + 1}. ${jugador.nombre}', subtitulo: jugador.eliminado ? l10n.eliminated : null, icono: jugador.eliminado ? Icons.person_off : Icons.record_voice_over, destacado: !jugador.eliminado, completado: !jugador.eliminado, ); }, ), ), ), ), const SizedBox(height: 16), Row( children: [ Expanded( child: BotonFarolero.oscuro( texto: l10n.notes, icono: Icons.edit_note, assetIconPath: 'assets/ui/generated/actions/action_notes_quill.webp', onPressed: () { Navigator.push( context, MaterialPageRoute(builder: (_) => const PantallaNotas()), ); }, ), ), const SizedBox(width: 12), Expanded( flex: 2, child: BotonFarolero( texto: l10n.goToVoting, icono: Icons.how_to_vote, assetIconPath: 'assets/ui/generated/actions/action_vote_mask.webp', onPressed: _irAVotacion, ), ), ], ), ], ), ), ), ), ); } }