import 'package:flutter/material.dart'; import '../classe/theme.dart'; import '../controllers/placar_controller.dart'; import 'package:playmaker/zone_map_dialog.dart'; // POP-UP DE ASSISTÊNCIA void showAssistDialog(BuildContext context, PlacarController controller, bool isOpponent, String scorerId, double sf) { final teamCourt = isOpponent ? controller.oppCourt : controller.myCourt; final prefix = isOpponent ? "player_opp_" : "player_my_"; final possibleAssistants = teamCourt.where((id) => id != scorerId && !id.startsWith("fake_")).toList(); if (possibleAssistants.isEmpty) return; showDialog( context: context, barrierDismissible: false, builder: (ctx) => AlertDialog( backgroundColor: Theme.of(context).colorScheme.surface, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15 * sf)), title: Text("Houve Assistência?", style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontWeight: FontWeight.bold, fontSize: 18 * sf)), content: SingleChildScrollView( child: Column( mainAxisSize: MainAxisSize.min, children: [ ...possibleAssistants.map((id) { final name = controller.playerNames[id] ?? "Desconhecido"; final number = controller.playerNumbers[id] ?? "0"; return ListTile( leading: CircleAvatar( backgroundColor: isOpponent ? AppTheme.oppTeamRed : AppTheme.myTeamBlue, child: Text(number, style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold)), ), title: Text(name, style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontWeight: FontWeight.bold)), onTap: () { Navigator.pop(ctx); controller.commitStat("add_ast", "$prefix$id"); ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Assistência: $name'), duration: const Duration(seconds: 1), backgroundColor: AppTheme.successGreen)); }, ); }), Divider(color: Colors.grey.withOpacity(0.3)), ListTile( leading: const CircleAvatar(backgroundColor: Colors.grey, child: Icon(Icons.person_off, color: Colors.white)), title: Text("Isolado (Sem assistência)", style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontStyle: FontStyle.italic)), onTap: () => Navigator.pop(ctx), ) ], ), ), ), ); } // 1. PLACAR SUPERIOR class TopScoreboard extends StatelessWidget { final PlacarController controller; final double sf; const TopScoreboard({super.key, required this.controller, required this.sf}); @override Widget build(BuildContext context) { return Container( padding: EdgeInsets.symmetric(vertical: 6 * sf, horizontal: 20 * sf), decoration: BoxDecoration( color: AppTheme.placarDarkSurface, borderRadius: BorderRadius.only(bottomLeft: Radius.circular(22 * sf), bottomRight: Radius.circular(22 * sf)), border: Border.all(color: Colors.white, width: 2.0 * sf), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ _buildTeamSection(controller.myTeam, controller.myScore, controller.myFouls, controller.myTimeoutsUsed, AppTheme.myTeamBlue, false, sf), SizedBox(width: 20 * sf), Column( mainAxisSize: MainAxisSize.min, children: [ Container( padding: EdgeInsets.symmetric(horizontal: 14 * sf, vertical: 4 * sf), decoration: BoxDecoration(color: AppTheme.placarTimerBg, borderRadius: BorderRadius.circular(9 * sf)), child: ValueListenableBuilder( valueListenable: controller.durationNotifier, builder: (context, duration, child) { String formatTime = "${duration.inMinutes.toString().padLeft(2, '0')}:${duration.inSeconds.remainder(60).toString().padLeft(2, '0')}"; return Text(formatTime, style: TextStyle(color: Colors.white, fontSize: 24 * sf, fontWeight: FontWeight.w900, fontFamily: 'monospace', letterSpacing: 1.5 * sf)); } ), ), SizedBox(height: 4 * sf), Text("PERÍODO ${controller.currentQuarter}", style: TextStyle(color: AppTheme.warningAmber, fontSize: 12 * sf, fontWeight: FontWeight.w900)), ], ), SizedBox(width: 20 * sf), _buildTeamSection(controller.opponentTeam, controller.opponentScore, controller.opponentFouls, controller.opponentTimeoutsUsed, AppTheme.oppTeamRed, true, sf), ], ), ); } Widget _buildTeamSection(String name, int score, int fouls, int timeouts, Color color, bool isOpp, double sf) { int displayFouls = fouls > 5 ? 5 : fouls; final timeoutIndicators = Row( mainAxisSize: MainAxisSize.min, children: List.generate(3, (index) => Container( margin: EdgeInsets.symmetric(horizontal: 2.5 * sf), width: 10 * sf, height: 10 * sf, decoration: BoxDecoration(shape: BoxShape.circle, color: index < timeouts ? AppTheme.warningAmber : Colors.grey.shade600, border: Border.all(color: Colors.white54, width: 1.0 * sf)), )), ); List content = [ Column(children: [_scoreBox(score, color, sf), SizedBox(height: 5 * sf), timeoutIndicators]), SizedBox(width: 12 * sf), Column( crossAxisAlignment: isOpp ? CrossAxisAlignment.start : CrossAxisAlignment.end, children: [ Text(name.toUpperCase(), style: TextStyle(color: Colors.white, fontSize: 16 * sf, fontWeight: FontWeight.w900, letterSpacing: 1.0 * sf)), SizedBox(height: 3 * sf), Text("FALTAS: $displayFouls", style: TextStyle(color: displayFouls >= 5 ? AppTheme.actionMiss : AppTheme.warningAmber, fontSize: 11 * sf, fontWeight: FontWeight.bold)), ], ) ]; return Row(crossAxisAlignment: CrossAxisAlignment.center, children: isOpp ? content : content.reversed.toList()); } Widget _scoreBox(int score, Color color, double sf) => Container( width: 45 * sf, height: 35 * sf, alignment: Alignment.center, decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(6 * sf)), child: Text(score.toString(), style: TextStyle(color: Colors.white, fontSize: 20 * sf, fontWeight: FontWeight.w900)), ); } // 2. BANCO DE SUPLENTES class BenchPlayersList extends StatelessWidget { final PlacarController controller; final bool isOpponent; final double sf; const BenchPlayersList({super.key, required this.controller, required this.isOpponent, required this.sf}); @override Widget build(BuildContext context) { final bench = isOpponent ? controller.oppBench : controller.myBench; final teamColor = isOpponent ? AppTheme.oppTeamRed : AppTheme.myTeamBlue; final prefix = isOpponent ? "bench_opp_" : "bench_my_"; return Column( mainAxisSize: MainAxisSize.min, children: bench.map((playerId) { final playerName = controller.playerNames[playerId] ?? "Erro"; final num = controller.playerNumbers[playerId] ?? "0"; final int fouls = controller.playerStats[playerId]?["fls"] ?? 0; final bool isFouledOut = fouls >= 5; String shortName = playerName.length > 8 ? "${playerName.substring(0, 7)}." : playerName; Widget avatarUI = Container( margin: EdgeInsets.only(bottom: 7 * sf), child: Column( mainAxisSize: MainAxisSize.min, children: [ Container( decoration: BoxDecoration( shape: BoxShape.circle, border: Border.all(color: Colors.white, width: 1.5 * sf), boxShadow: [BoxShadow(color: Colors.black45, blurRadius: 4 * sf, offset: Offset(0, 2.0 * sf))] ), child: CircleAvatar( radius: 18 * sf, backgroundColor: isFouledOut ? Colors.grey.shade800 : teamColor, child: Text(num, style: TextStyle(color: isFouledOut ? Colors.red.shade300 : Colors.white, fontSize: 14 * sf, fontWeight: FontWeight.bold, decoration: isFouledOut ? TextDecoration.lineThrough : TextDecoration.none)), ), ), SizedBox(height: 4 * sf), Text(shortName, style: TextStyle(color: Colors.white, fontSize: 10 * sf, fontWeight: FontWeight.bold), overflow: TextOverflow.ellipsis), ], ), ); if (isFouledOut) { return GestureDetector(onTap: () => ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('🛑 $playerName não pode voltar (Expulso).'), backgroundColor: AppTheme.actionMiss)), child: avatarUI); } return Draggable( data: "$prefix$playerId", feedback: Material(color: Colors.transparent, child: CircleAvatar(radius: 22 * sf, backgroundColor: teamColor, child: Text(num, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 16 * sf)))), childWhenDragging: Opacity(opacity: 0.5, child: SizedBox(width: 36 * sf, height: 36 * sf)), child: avatarUI, ); }).toList(), ); } } // 3. CARTÃO DO JOGADOR NO CAMPO class PlayerCourtCard extends StatelessWidget { final PlacarController controller; final String playerId; final bool isOpponent; final double sf; const PlayerCourtCard({super.key, required this.controller, required this.playerId, required this.isOpponent, required this.sf}); @override Widget build(BuildContext context) { final teamColor = isOpponent ? AppTheme.oppTeamRed : AppTheme.myTeamBlue; final realName = controller.playerNames[playerId] ?? "Erro"; final stats = controller.playerStats[playerId]!; final number = controller.playerNumbers[playerId]!; final prefix = isOpponent ? "player_opp_" : "player_my_"; return Draggable( data: "$prefix$playerId", feedback: Material( color: Colors.transparent, child: Container( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), decoration: BoxDecoration(color: teamColor.withOpacity(0.9), borderRadius: BorderRadius.circular(6)), child: Text(realName, style: const TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold)), ), ), childWhenDragging: Opacity(opacity: 0.5, child: _playerCardUI(number, realName, stats, teamColor, false, false, sf)), child: DragTarget( onAcceptWithDetails: (details) { final action = details.data; if (action == "add_pts_2" || action == "add_pts_3" || action == "miss_2" || action == "miss_3") { bool isMake = action.startsWith("add_"); bool is3Pt = action.endsWith("_3"); showDialog( context: context, builder: (ctx) => ZoneMapDialog( playerName: realName, isMake: isMake, is3PointAction: is3Pt, onZoneSelected: (zone, points, relX, relY) { Navigator.pop(ctx); controller.registerShotFromPopup(context, action, "$prefix$playerId", zone, points, relX, relY); if (isMake) showAssistDialog(context, controller, isOpponent, playerId, sf); }, ), ); } else if (action.startsWith("add_") || action.startsWith("sub_") || action.startsWith("miss_")) { controller.handleActionDrag(context, action, "$prefix$playerId"); } else if (action.startsWith("bench_")) { controller.handleSubbing(context, action, playerId, isOpponent); } }, builder: (context, candidateData, rejectedData) { bool isSubbing = candidateData.any((data) => data != null && (data.startsWith("bench_my_") || data.startsWith("bench_opp_"))); bool isActionHover = candidateData.any((data) => data != null && (data.startsWith("add_") || data.startsWith("sub_") || data.startsWith("miss_"))); return _playerCardUI(number, realName, stats, teamColor, isSubbing, isActionHover, sf); }, ), ); } Widget _playerCardUI(String number, String displayNameStr, Map stats, Color teamColor, bool isSubbing, bool isActionHover, double sf) { bool isFouledOut = stats["fls"]! >= 5; Color bgColor = isFouledOut ? Colors.red.shade100 : Colors.white; Color borderColor = isFouledOut ? AppTheme.actionMiss : Colors.transparent; if (isSubbing) { bgColor = Colors.blue.shade50; borderColor = AppTheme.myTeamBlue; } else if (isActionHover && !isFouledOut) { bgColor = Colors.orange.shade50; borderColor = AppTheme.actionPoints; } int fgm = stats["fgm"]!; int fga = stats["fga"]!; String fgPercent = fga > 0 ? ((fgm / fga) * 100).toStringAsFixed(0) : "0"; String displayName = displayNameStr.length > 12 ? "${displayNameStr.substring(0, 10)}..." : displayNameStr; return Container( padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 4), decoration: BoxDecoration(color: bgColor, borderRadius: BorderRadius.circular(8), border: Border.all(color: borderColor, width: 1.5), boxShadow: const [BoxShadow(color: Colors.black26, blurRadius: 4, offset: Offset(0, 2))]), child: ClipRRect( borderRadius: BorderRadius.circular(6 * sf), child: IntrinsicHeight( child: Row( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Container( padding: EdgeInsets.symmetric(horizontal: 10 * sf), color: isFouledOut ? Colors.grey[700] : teamColor, alignment: Alignment.center, child: Text(number, style: TextStyle(color: Colors.white, fontSize: 18 * sf, fontWeight: FontWeight.bold)), ), Padding( padding: EdgeInsets.symmetric(horizontal: 8 * sf, vertical: 4 * sf), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text(displayName, style: TextStyle(fontSize: 14 * sf, fontWeight: FontWeight.bold, color: isFouledOut ? AppTheme.actionMiss : Colors.black87, decoration: isFouledOut ? TextDecoration.lineThrough : TextDecoration.none)), SizedBox(height: 1.5 * sf), Text("${stats["pts"]} Pts | FG: $fgm/$fga ($fgPercent%)", style: TextStyle(fontSize: 10 * sf, color: isFouledOut ? AppTheme.actionMiss : Colors.grey[700], fontWeight: FontWeight.w600)), Text("${stats["ast"]} Ast | ${stats["orb"]! + stats["drb"]!} Rbs | ${stats["fls"]} Fls", style: TextStyle(fontSize: 10 * sf, color: isFouledOut ? AppTheme.actionMiss : Colors.grey[500], fontWeight: FontWeight.w600)), ], ), ), ], ), ), ), ); } } // 4. PAINEL DE BOTÕES DE AÇÃO class ActionButtonsPanel extends StatelessWidget { final PlacarController controller; final double sf; const ActionButtonsPanel({super.key, required this.controller, required this.sf}); @override Widget build(BuildContext context) { final double baseSize = 58 * sf; final double feedSize = 73 * sf; final double gap = 5 * sf; return Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.end, children: [ _columnBtn([ _dragAndTargetBtn("M1", AppTheme.actionMiss, "miss_1", baseSize, feedSize, sf), _dragAndTargetBtn("1", AppTheme.actionPoints, "add_pts_1", baseSize, feedSize, sf), _dragAndTargetBtn("1", AppTheme.actionPoints, "sub_pts_1", baseSize, feedSize, sf, isX: true), _dragAndTargetBtn("STL", AppTheme.actionSteal, "add_stl", baseSize, feedSize, sf), ], gap), SizedBox(width: gap * 1), _columnBtn([ _dragAndTargetBtn("M2", AppTheme.actionMiss, "miss_2", baseSize, feedSize, sf), _dragAndTargetBtn("2", AppTheme.actionPoints, "add_pts_2", baseSize, feedSize, sf), _dragAndTargetBtn("2", AppTheme.actionPoints, "sub_pts_2", baseSize, feedSize, sf, isX: true), _dragAndTargetBtn("AST", AppTheme.actionAssist, "add_ast", baseSize, feedSize, sf), ], gap), SizedBox(width: gap * 1), _columnBtn([ _dragAndTargetBtn("M3", AppTheme.actionMiss, "miss_3", baseSize, feedSize, sf), _dragAndTargetBtn("3", AppTheme.actionPoints, "add_pts_3", baseSize, feedSize, sf), _dragAndTargetBtn("3", AppTheme.actionPoints, "sub_pts_3", baseSize, feedSize, sf, isX: true), _dragAndTargetBtn("TOV", AppTheme.actionMiss, "add_tov", baseSize, feedSize, sf), ], gap), SizedBox(width: gap * 1), _columnBtn([ _dragAndTargetBtn("ORB", AppTheme.actionRebound, "add_orb", baseSize, feedSize, sf, icon: Icons.sports_basketball), _dragAndTargetBtn("DRB", AppTheme.actionRebound, "add_drb", baseSize, feedSize, sf, icon: Icons.sports_basketball), _dragAndTargetBtn("BLK", AppTheme.actionBlock, "add_blk", baseSize, feedSize, sf, icon: Icons.front_hand), ], gap), ], ); } Widget _columnBtn(List children, double gap) { return Column( mainAxisSize: MainAxisSize.min, children: children.map((c) => Padding(padding: EdgeInsets.only(bottom: gap), child: c)).toList() ); } Widget _dragAndTargetBtn(String label, Color color, String actionData, double baseSize, double feedSize, double sf, {IconData? icon, bool isX = false}) { return Draggable( data: actionData, feedback: _circle(label, color, icon, true, baseSize, feedSize, sf, isX: isX), childWhenDragging: Opacity( opacity: 0.5, child: _circle(label, color, icon, false, baseSize, feedSize, sf, isX: isX) ), child: DragTarget( onAcceptWithDetails: (details) {}, builder: (context, candidateData, rejectedData) { bool isHovered = candidateData.any((data) => data != null && data.startsWith("player_")); return Transform.scale( scale: isHovered ? 1.15 : 1.0, child: Container( decoration: isHovered ? BoxDecoration(shape: BoxShape.circle, boxShadow: [BoxShadow(color: Colors.white, blurRadius: 10 * sf, spreadRadius: 3 * sf)]) : null, child: _circle(label, color, icon, false, baseSize, feedSize, sf, isX: isX) ), ); } ), ); } Widget _circle(String label, Color color, IconData? icon, bool isFeed, double baseSize, double feedSize, double sf, {bool isX = false}) { double size = isFeed ? feedSize : baseSize; Widget content; bool isPointBtn = label == "1" || label == "2" || label == "3" || label == "M1" || label == "M2" || label == "M3"; bool isBlkBtn = label == "BLK"; if (isPointBtn) { content = Stack( alignment: Alignment.center, children: [ Container(width: size * 0.75, height: size * 0.75, decoration: const BoxDecoration(color: Colors.black, shape: BoxShape.circle)), Icon(Icons.sports_basketball, color: color, size: size * 0.9), Stack( children: [ Text(label, style: TextStyle(fontSize: size * 0.38, fontWeight: FontWeight.w900, foreground: Paint()..style = PaintingStyle.stroke..strokeWidth = size * 0.05..color = Colors.white, decoration: TextDecoration.none)), Text(label, style: TextStyle(fontSize: size * 0.38, fontWeight: FontWeight.w900, color: Colors.black, decoration: TextDecoration.none)), ], ), ], ); } else if (isBlkBtn) { content = Stack( alignment: Alignment.center, children: [ Icon(Icons.front_hand, color: const Color.fromARGB(207, 56, 52, 52), size: size * 0.75), Stack( alignment: Alignment.center, children: [ Text(label, style: TextStyle(fontSize: size * 0.28, fontWeight: FontWeight.w900, foreground: Paint()..style = PaintingStyle.stroke..strokeWidth = size * 0.05..color = Colors.black, decoration: TextDecoration.none)), Text(label, style: TextStyle(fontSize: size * 0.28, fontWeight: FontWeight.w900, color: Colors.white, decoration: TextDecoration.none)), ], ), ], ); } else if (icon != null) { content = Icon(icon, color: Colors.white, size: size * 0.5); } else { content = Text(label, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: size * 0.35, decoration: TextDecoration.none)); } return Stack( clipBehavior: Clip.none, alignment: Alignment.bottomRight, children: [ Container( width: size, height: size, decoration: (isPointBtn || isBlkBtn) ? const BoxDecoration(color: Colors.transparent) : BoxDecoration(gradient: RadialGradient(colors: [color.withOpacity(0.7), color], radius: 0.8), shape: BoxShape.circle, boxShadow: [BoxShadow(color: Colors.black38, blurRadius: 6 * sf, offset: Offset(0, 3 * sf))]), alignment: Alignment.center, child: content, ), if (isX) Positioned(top: 0, right: 0, child: Container(decoration: const BoxDecoration(color: Colors.white, shape: BoxShape.circle), child: Icon(Icons.cancel, color: Colors.red, size: size * 0.4))), ], ); } }