import 'package:flutter/material.dart';
import 'package:em2rp/utils/colors.dart';

/// Widget réutilisable pour un AppBar en mode sélection
class SelectionAppBar extends StatelessWidget implements PreferredSizeWidget {
  final int selectedCount;
  final VoidCallback onClose;
  final VoidCallback? onDelete;
  final VoidCallback? onGenerateQR;
  final List<Widget>? additionalActions;

  const SelectionAppBar({
    super.key,
    required this.selectedCount,
    required this.onClose,
    this.onDelete,
    this.onGenerateQR,
    this.additionalActions,
  });

  @override
  Size get preferredSize => const Size.fromHeight(kToolbarHeight);

  @override
  Widget build(BuildContext context) {
    final hasSelection = selectedCount > 0;

    return AppBar(
      backgroundColor: AppColors.rouge,
      leading: IconButton(
        icon: const Icon(Icons.close, color: Colors.white),
        onPressed: onClose,
      ),
      title: Text(
        '$selectedCount sélectionné(s)',
        style: const TextStyle(color: Colors.white),
      ),
      actions: [
        if (hasSelection) ...[
          if (onGenerateQR != null)
            IconButton(
              icon: const Icon(Icons.qr_code, color: Colors.white),
              tooltip: 'Générer QR Codes',
              onPressed: onGenerateQR,
            ),
          if (onDelete != null)
            IconButton(
              icon: const Icon(Icons.delete, color: Colors.white),
              tooltip: 'Supprimer',
              onPressed: onDelete,
            ),
          if (additionalActions != null) ...additionalActions!,
        ],
      ],
    );
  }
}

