import 'package:flutter/material.dart';

import '../../app/theme.dart';
import '../scoring/match_scoring_rules.dart';

Future<bool> showSetWonDialog(
  BuildContext context, {
  required ScoringSide winner,
  required String homeName,
  required String awayName,
  required int homePoints,
  required int awayPoints,
}) async {
  final winnerName = winner == ScoringSide.home ? homeName : awayName;
  final result = await showDialog<bool>(
    context: context,
    barrierDismissible: false,
    builder: (ctx) => AlertDialog(
      backgroundColor: AppTheme.surface,
      title: const Text('Set concluso'),
      content: Text(
        '$winnerName vince il set $homePoints-$awayPoints.\n\nChiudere il set e passare al successivo?',
      ),
      actions: [
        TextButton(
          onPressed: () => Navigator.pop(ctx, false),
          child: const Text('Continua a segnare'),
        ),
        FilledButton(
          onPressed: () => Navigator.pop(ctx, true),
          style: FilledButton.styleFrom(backgroundColor: AppTheme.accentYellow),
          child: const Text('Chiudi set', style: TextStyle(color: Colors.black)),
        ),
      ],
    ),
  );
  return result == true;
}

Future<bool> showCloseSetAnywayDialog(BuildContext context) async {
  final result = await showDialog<bool>(
    context: context,
    builder: (ctx) => AlertDialog(
      backgroundColor: AppTheme.surface,
      title: const Text('Chiudi set'),
      content: const Text(
        'Il punteggio non soddisfa ancora le regole del torneo. Chiudere il set comunque?',
      ),
      actions: [
        TextButton(
          onPressed: () => Navigator.pop(ctx, false),
          child: const Text('Annulla'),
        ),
        FilledButton(
          onPressed: () => Navigator.pop(ctx, true),
          child: const Text('Chiudi comunque'),
        ),
      ],
    ),
  );
  return result == true;
}

Future<bool> showMatchWonDialog(
  BuildContext context, {
  required ScoringSide winner,
  required String homeName,
  required String awayName,
  required int homeSets,
  required int awaySets,
}) async {
  final winnerName = winner == ScoringSide.home ? homeName : awayName;
  final result = await showDialog<bool>(
    context: context,
    barrierDismissible: false,
    builder: (ctx) => AlertDialog(
      backgroundColor: AppTheme.surface,
      title: const Text('Partita terminata'),
      content: Text(
        '$winnerName vince la partita ($homeSets-$awaySets set).\n\nChiudere definitivamente la diretta?',
      ),
      actions: [
        TextButton(
          onPressed: () => Navigator.pop(ctx, false),
          child: const Text('Continua in onda'),
        ),
        FilledButton(
          onPressed: () => Navigator.pop(ctx, true),
          style: FilledButton.styleFrom(backgroundColor: AppTheme.primaryRed),
          child: const Text('Chiudi diretta'),
        ),
      ],
    ),
  );
  return result == true;
}
