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 Padding(
      padding: const EdgeInsets.only(top: 24.0),
      child: Wrap(
        alignment: WrapAlignment.spaceBetween,
        crossAxisAlignment: WrapCrossAlignment.center,
        spacing: 16,
        runSpacing: 16,
        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(),

          // Boutons Annuler, Enregistrer/Créer et Valider
          Wrap(
            spacing: 8,
            runSpacing: 8,
            alignment: WrapAlignment.end,
            crossAxisAlignment: WrapCrossAlignment.center,
            children: [
              TextButton(
                onPressed: isLoading ? null : onCancel,
                child: const Text('Annuler'),
              ),
              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)
                ElevatedButton.icon(
                  icon: const Icon(Icons.check_circle, color: Colors.white),
                  label: const Text('Créer et valider'),
                  style: ElevatedButton.styleFrom(
                    backgroundColor: Colors.green,
                    foregroundColor: Colors.white,
                  ),
                  onPressed: isLoading ? null : onSetConfirmed,
                ),
            ],
          ),
        ],
      ),
    );
  }
}
