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

/// Widget pour afficher un équipement dans la liste d'un container
class ContainerEquipmentTile extends StatelessWidget {
  final EquipmentModel equipment;
  final VoidCallback onView;
  final VoidCallback onRemove;

  const ContainerEquipmentTile({
    super.key,
    required this.equipment,
    required this.onView,
    required this.onRemove,
  });

  @override
  Widget build(BuildContext context) {
    return ListTile(
      contentPadding: const EdgeInsets.symmetric(vertical: 8),
      leading: CircleAvatar(
        backgroundColor: AppColors.rouge.withOpacity(0.1),
        child: const Icon(Icons.inventory_2, color: AppColors.rouge),
      ),
      title: Text(
        equipment.id,
        style: const TextStyle(fontWeight: FontWeight.bold),
      ),
      subtitle: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          if (equipment.brand != null || equipment.model != null)
            Text('${equipment.brand ?? ''} ${equipment.model ?? ''}'),
          const SizedBox(height: 4),
          Row(
            children: [
              _buildSmallBadge(
                _getCategoryLabel(equipment.category),
                Colors.blue,
              ),
              const SizedBox(width: 8),
              if (equipment.weight != null)
                _buildSmallBadge(
                  '${equipment.weight} kg',
                  Colors.grey,
                ),
            ],
          ),
        ],
      ),
      trailing: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          IconButton(
            icon: const Icon(Icons.visibility, size: 20),
            tooltip: 'Voir détails',
            onPressed: onView,
          ),
          IconButton(
            icon: const Icon(Icons.remove_circle, color: Colors.red, size: 20),
            tooltip: 'Retirer',
            onPressed: onRemove,
          ),
        ],
      ),
    );
  }

  Widget _buildSmallBadge(String label, Color color) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
      decoration: BoxDecoration(
        color: color.withOpacity(0.1),
        borderRadius: BorderRadius.circular(12),
        border: Border.all(color: color.withOpacity(0.3)),
      ),
      child: Text(
        label,
        style: TextStyle(
          fontSize: 11,
          color: color,
          fontWeight: FontWeight.bold,
        ),
      ),
    );
  }

  String _getCategoryLabel(EquipmentCategory category) {
    switch (category) {
      case EquipmentCategory.lighting:
        return 'Lumière';
      case EquipmentCategory.sound:
        return 'Son';
      case EquipmentCategory.video:
        return 'Vidéo';
      case EquipmentCategory.effect:
        return 'Effets';
      case EquipmentCategory.structure:
        return 'Structure';
      case EquipmentCategory.consumable:
        return 'Consommable';
      case EquipmentCategory.cable:
        return 'Câble';
      case EquipmentCategory.vehicle:
        return 'Véhicule';
      case EquipmentCategory.backline:
        return 'Régie / Backline';
      case EquipmentCategory.other:
        return 'Autre';
    }
  }
}

