import 'package:flutter/material.dart';

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

enum NewMatchChoice { schedule, quickStart }

Future<NewMatchChoice?> showNewMatchSheet(BuildContext context) {
  return showModalBottomSheet<NewMatchChoice>(
    context: context,
    backgroundColor: AppTheme.surface,
    shape: const RoundedRectangleBorder(
      borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
    ),
    builder: (ctx) {
      final theme = Theme.of(ctx);
      return Padding(
        padding: const EdgeInsets.fromLTRB(20, 12, 20, 28),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Center(
              child: Container(
                width: 40,
                height: 4,
                decoration: BoxDecoration(
                  color: AppTheme.textSecondary.withValues(alpha: 0.4),
                  borderRadius: BorderRadius.circular(2),
                ),
              ),
            ),
            const SizedBox(height: 16),
            Text('Nuova partita', style: theme.textTheme.titleLarge),
            const SizedBox(height: 6),
            Text(
              'Programma in anticipo o avvia la configurazione diretta subito.',
              style: theme.textTheme.bodyMedium,
            ),
            const SizedBox(height: 20),
            _OptionTile(
              icon: Icons.event_available,
              title: 'Programma partita',
              subtitle: 'Data, ora e avversario — visibile anche sul sito',
              onTap: () => Navigator.pop(ctx, NewMatchChoice.schedule),
            ),
            const SizedBox(height: 10),
            _OptionTile(
              icon: Icons.play_circle_outline,
              title: 'Avvia subito',
              subtitle: 'Crea la partita e passa al wizard senza orario',
              onTap: () => Navigator.pop(ctx, NewMatchChoice.quickStart),
            ),
          ],
        ),
      );
    },
  );
}

class _OptionTile extends StatelessWidget {
  const _OptionTile({
    required this.icon,
    required this.title,
    required this.subtitle,
    required this.onTap,
  });

  final IconData icon;
  final String title;
  final String subtitle;
  final VoidCallback onTap;

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    return Material(
      color: AppTheme.surfaceElevated,
      borderRadius: BorderRadius.circular(12),
      child: InkWell(
        onTap: onTap,
        borderRadius: BorderRadius.circular(12),
        child: Padding(
          padding: const EdgeInsets.all(16),
          child: Row(
            children: [
              Icon(icon, color: AppTheme.primaryRed, size: 28),
              const SizedBox(width: 14),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(title, style: theme.textTheme.titleMedium),
                    const SizedBox(height: 4),
                    Text(subtitle, style: theme.textTheme.bodySmall),
                  ],
                ),
              ),
              const Icon(Icons.chevron_right, color: AppTheme.textSecondary),
            ],
          ),
        ),
      ),
    );
  }
}
