import 'package:flutter/material.dart';

class EventFormActions extends StatelessWidget {
  final bool isLoading;
  final bool isEditMode;
  final VoidCallback onCancel;
  final VoidCallback onSubmit;
  final VoidCallback? onSetConfirmed;
  final VoidCallback? onDelete; // Nouveau paramètre pour la suppression

  const EventFormActions({
    super.key,
    required this.isLoading,
    required this.isEditMode,
    required this.onCancel,
    required this.onSubmit,
    this.onSetConfirmed,
    this.onDelete, // Paramètre optionnel pour la suppression
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        const SizedBox(height: 24),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            // Bouton de suppression en mode édition
            if (isEditMode && onDelete != null)
              ElevatedButton.icon(
                icon: const Icon(Icons.delete, color: Colors.white),
                label: const Text('Supprimer'),
                style: ElevatedButton.styleFrom(
                  backgroundColor: Colors.red,
                  foregroundColor: Colors.white,
                ),
                onPressed: isLoading ? null : onDelete,
              )
            else
              const SizedBox.shrink(), // Espace vide si pas en mode édition

            // Boutons Annuler et Enregistrer/Créer
            Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                TextButton(
                  onPressed: isLoading ? null : onCancel,
                  child: const Text('Annuler'),
                ),
                const SizedBox(width: 8),
                ElevatedButton.icon(
                  icon: const Icon(Icons.check),
                  onPressed: isLoading ? null : onSubmit,
                  label: isLoading
                      ? const SizedBox(
                          width: 20,
                          height: 20,
                          child: CircularProgressIndicator(strokeWidth: 2),
                        )
                      : Text(isEditMode ? 'Enregistrer' : 'Créer'),
                ),
              ],
            ),
          ],
        ),
        if (!isEditMode && onSetConfirmed != null)
          Center(
            child: Padding(
              padding: const EdgeInsets.only(top: 16.0),
              child: ElevatedButton.icon(
                icon: const Icon(Icons.check_circle, color: Colors.white),
                label: const Text('Définir cet événement comme confirmé'),
                style: ElevatedButton.styleFrom(
                  backgroundColor: Colors.green,
                  foregroundColor: Colors.white,
                  textStyle: const TextStyle(fontWeight: FontWeight.bold),
                ),
                onPressed: onSetConfirmed,
              ),
            ),
          ),
      ],
    );
  }
}
