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

/// Widget pour afficher la quantité disponible/totale d'un équipement consommable
class QuantityDisplay extends StatelessWidget {
  final EquipmentModel equipment;

  const QuantityDisplay({
    super.key,
    required this.equipment,
  });

  @override
  Widget build(BuildContext context) {
    final availableQty = equipment.availableQuantity ?? 0;
    final totalQty = equipment.totalQuantity ?? 0;
    final criticalThreshold = equipment.criticalThreshold ?? 0;
    final isCritical =
        criticalThreshold > 0 && availableQty <= criticalThreshold;

    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
      decoration: BoxDecoration(
        color: isCritical
            ? Colors.red.withOpacity(0.15)
            : Colors.grey.withOpacity(0.1),
        borderRadius: BorderRadius.circular(8),
        border: Border.all(
          color: isCritical ? Colors.red : Colors.grey.shade400,
          width: isCritical ? 2 : 1,
        ),
      ),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Icon(
            isCritical ? Icons.warning : Icons.inventory,
            size: 16,
            color: isCritical ? Colors.red : Colors.grey[700],
          ),
          const SizedBox(width: 6),
          Text(
            'Disponible: $availableQty / $totalQty',
            style: TextStyle(
              fontSize: 13,
              fontWeight: isCritical ? FontWeight.bold : FontWeight.normal,
              color: isCritical ? Colors.red : Colors.grey[700],
            ),
          ),
          if (isCritical) ...[
            const SizedBox(width: 6),
            Container(
              padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
              decoration: BoxDecoration(
                color: Colors.red,
                borderRadius: BorderRadius.circular(10),
              ),
              child: const Text(
                'CRITIQUE',
                style: TextStyle(
                  fontSize: 10,
                  fontWeight: FontWeight.bold,
                  color: Colors.white,
                ),
              ),
            ),
          ],
        ],
      ),
    );
  }
}

