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

/// Widget optimisé pour une card d'équipement qui ne rebuild que si nécessaire
class OptimizedEquipmentCard extends StatefulWidget {
  final EquipmentModel equipment;
  final bool isSelected;
  final int? selectedQuantity;
  final bool hasConflict;
  final String? conflictMessage;
  final int? availableQuantity;
  final VoidCallback onTap;
  final Function(int)? onQuantityChanged;

  const OptimizedEquipmentCard({
    super.key,
    required this.equipment,
    required this.isSelected,
    this.selectedQuantity,
    required this.hasConflict,
    this.conflictMessage,
    this.availableQuantity,
    required this.onTap,
    this.onQuantityChanged,
  });

  @override
  State<OptimizedEquipmentCard> createState() => _OptimizedEquipmentCardState();
}

class _OptimizedEquipmentCardState extends State<OptimizedEquipmentCard> {
  @override
  Widget build(BuildContext context) {
    // Le contenu de la card sera ici
    // Pour l'instant, retournons juste un placeholder
    return Card(
      key: ValueKey('equipment_${widget.equipment.id}'),
      child: ListTile(
        title: Text(widget.equipment.id),
        subtitle: Text('${widget.equipment.brand} - ${widget.equipment.model}'),
        trailing: widget.isSelected ? Icon(Icons.check_circle, color: Colors.green) : null,
        onTap: widget.onTap,
      ),
    );
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is OptimizedEquipmentCard &&
          runtimeType == other.runtimeType &&
          widget.equipment.id == other.equipment.id &&
          widget.isSelected == other.isSelected &&
          widget.selectedQuantity == other.selectedQuantity &&
          widget.hasConflict == other.hasConflict;

  @override
  int get hashCode =>
      widget.equipment.id.hashCode ^
      widget.isSelected.hashCode ^
      widget.selectedQuantity.hashCode ^
      widget.hasConflict.hashCode;
}

