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

/// Widget réutilisable pour afficher un chip de filtre
class FilterChip extends StatelessWidget {
  final String label;
  final bool isSelected;
  final VoidCallback onTap;

  const FilterChip({
    super.key,
    required this.label,
    required this.isSelected,
    required this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
        decoration: BoxDecoration(
          color: isSelected ? AppColors.rouge : Colors.white,
          borderRadius: BorderRadius.circular(20),
          border: Border.all(
            color: isSelected ? AppColors.rouge : Colors.grey.shade300,
            width: isSelected ? 2 : 1,
          ),
        ),
        child: Text(
          label,
          style: TextStyle(
            color: isSelected ? Colors.white : AppColors.noir,
            fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
          ),
        ),
      ),
    );
  }
}

/// Widget réutilisable pour une barre de filtres horizontale
class ManagementFilterBar extends StatelessWidget {
  final List<FilterChipData> filters;

  const ManagementFilterBar({
    super.key,
    required this.filters,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(vertical: 8),
      color: Colors.grey.shade50,
      child: SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        padding: const EdgeInsets.symmetric(horizontal: 16),
        child: Row(
          children: filters.map((filter) {
            return Padding(
              padding: const EdgeInsets.only(right: 8),
              child: FilterChip(
                label: filter.label,
                isSelected: filter.isSelected,
                onTap: filter.onTap,
              ),
            );
          }).toList(),
        ),
      ),
    );
  }
}

/// Données pour un chip de filtre
class FilterChipData {
  final String label;
  final bool isSelected;
  final VoidCallback onTap;

  const FilterChipData({
    required this.label,
    required this.isSelected,
    required this.onTap,
  });
}

