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

/// Widget pour afficher les prix
class EquipmentPriceSection extends StatelessWidget {
  final EquipmentModel equipment;

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

  @override
  Widget build(BuildContext context) {
    final hasPrices = equipment.purchasePrice != null || equipment.rentalPrice != null;

    if (!hasPrices) return const SizedBox.shrink();

    return Card(
      elevation: 2,
      child: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                const Icon(Icons.euro, color: AppColors.rouge),
                const SizedBox(width: 8),
                Text(
                  'Prix',
                  style: Theme.of(context).textTheme.titleLarge?.copyWith(
                        fontWeight: FontWeight.bold,
                      ),
                ),
              ],
            ),
            const Divider(height: 24),
            if (equipment.purchasePrice != null)
              _buildInfoRow(
                'Prix d\'achat',
                '${equipment.purchasePrice!.toStringAsFixed(2)} €',
              ),
            if (equipment.rentalPrice != null)
              _buildInfoRow(
                'Prix de location',
                '${equipment.rentalPrice!.toStringAsFixed(2)} €/jour',
              ),
          ],
        ),
      ),
    );
  }

  Widget _buildInfoRow(String label, String value) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 8.0),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SizedBox(
            width: 120,
            child: Text(
              label,
              style: TextStyle(
                fontWeight: FontWeight.w500,
                color: Colors.grey[700],
              ),
            ),
          ),
          Expanded(
            child: Text(
              value,
              style: const TextStyle(
                fontWeight: FontWeight.w600,
              ),
            ),
          ),
        ],
      ),
    );
  }
}

