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

/// Widget réutilisable pour la barre de recherche dans les pages de gestion
class ManagementSearchBar extends StatelessWidget {
  final TextEditingController controller;
  final String hintText;
  final ValueChanged<String> onChanged;
  final VoidCallback? onSelectionModeToggle;
  final bool showSelectionModeButton;
  final List<Widget>? additionalActions;

  const ManagementSearchBar({
    super.key,
    required this.controller,
    required this.hintText,
    required this.onChanged,
    this.onSelectionModeToggle,
    this.showSelectionModeButton = true,
    this.additionalActions,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: Colors.white,
        boxShadow: [
          BoxShadow(
            color: Colors.grey.withOpacity(0.1),
            spreadRadius: 1,
            blurRadius: 3,
            offset: const Offset(0, 1),
          ),
        ],
      ),
      child: Row(
        children: [
          Expanded(
            child: TextField(
              controller: controller,
              decoration: InputDecoration(
                hintText: hintText,
                prefixIcon: const Icon(Icons.search, color: AppColors.rouge),
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(8),
                  borderSide: BorderSide(color: Colors.grey.shade300),
                ),
                contentPadding: const EdgeInsets.symmetric(
                  horizontal: 16,
                  vertical: 12,
                ),
              ),
              onChanged: onChanged,
            ),
          ),
          if (additionalActions != null) ...additionalActions!,
          if (showSelectionModeButton && onSelectionModeToggle != null) ...[
            const SizedBox(width: 12),
            IconButton(
              icon: const Icon(Icons.checklist, color: AppColors.rouge),
              tooltip: 'Mode sélection',
              onPressed: onSelectionModeToggle,
            ),
          ],
        ],
      ),
    );
  }
}

