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

/// Widget pour afficher la carte d'en-tête d'un container
class ContainerHeaderCard extends StatelessWidget {
  final ContainerModel container;
  final List<EquipmentModel> equipmentList;

  const ContainerHeaderCard({
    super.key,
    required this.container,
    required this.equipmentList,
  });

  @override
  Widget build(BuildContext context) {
    return Card(
      elevation: 2,
      child: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                container.type.getIcon(
                  size: 60,
                  color: AppColors.rouge,
                ),
                const SizedBox(width: 20),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        container.id,
                        style: const TextStyle(
                          fontSize: 24,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      const SizedBox(height: 4),
                      Text(
                        container.name,
                        style: TextStyle(
                          fontSize: 16,
                          color: Colors.grey.shade700,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
            const Divider(height: 32),
            Row(
              children: [
                Expanded(
                  child: _buildInfoItem(
                    context,
                    'Type',
                    container.type.label,
                    Icons.category,
                  ),
                ),
                Expanded(
                  child: _buildInfoItem(
                    context,
                    'Statut',
                    container.status.label,
                    Icons.info,
                    statusColor: container.status.color,
                  ),
                ),
              ],
            ),
            const SizedBox(height: 12),
            Row(
              children: [
                Expanded(
                  child: _buildInfoItem(
                    context,
                    'Équipements',
                    '${container.itemCount}',
                    Icons.inventory,
                  ),
                ),
                Expanded(
                  child: _buildInfoItem(
                    context,
                    'Poids total',
                    _calculateTotalWeight(),
                    Icons.scale,
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildInfoItem(
    BuildContext context,
    String label,
    String value,
    IconData icon, {
    Color? statusColor,
  }) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            Icon(icon, size: 16, color: Colors.grey.shade600),
            const SizedBox(width: 6),
            Text(
              label,
              style: TextStyle(
                fontSize: 12,
                color: Colors.grey.shade600,
              ),
            ),
          ],
        ),
        const SizedBox(height: 4),
        Text(
          value,
          style: TextStyle(
            fontSize: 16,
            fontWeight: FontWeight.bold,
            color: statusColor,
          ),
        ),
      ],
    );
  }

  String _calculateTotalWeight() {
    if (equipmentList.isEmpty && container.weight == null) {
      return '-';
    }

    final totalWeight = container.calculateTotalWeight(equipmentList);
    return '${totalWeight.toStringAsFixed(1)} kg';
  }
}

