<!-- Widget IMC -->
<div class="card mb-0 border-0 shadow-none">
    <div class="card-body p-3">
        <form id="imcWidgetForm" class="mb-3">
            <div class="mb-3">
                <label for="widget-weight" class="form-label">Peso (kg)</label>
                <input type="number" class="form-control" id="widget-weight" name="weight" step="0.1" required>
            </div>
            <div class="mb-3">
                <label for="widget-height" class="form-label">Altura (cm)</label>
                <input type="number" class="form-control" id="widget-height" name="height" step="0.1" required>
            </div>
            <button type="submit" class="btn btn-primary w-100">
                <i class="fas fa-calculator me-2"></i>Calcular
            </button>
        </form>
        <div id="widget-imc-result" class="alert alert-info" style="display: none;">
            <p class="mb-0">Su IMC: <strong id="widget-imc-value"></strong></p>
            <p class="mb-0">Clasificación: <strong id="widget-imc-classification"></strong></p>
        </div>
        <div class="text-center mt-2">
            <a href="{{ route('utilities.imc') }}" class="btn btn-sm btn-outline-primary">Ver detalles completos</a>
        </div>
    </div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    const imcForm = document.getElementById('imcWidgetForm');
    const resultDiv = document.getElementById('widget-imc-result');
    const imcValue = document.getElementById('widget-imc-value');
    const imcClassification = document.getElementById('widget-imc-classification');

    imcForm.addEventListener('submit', function(e) {
        e.preventDefault();
        
        const weight = parseFloat(document.getElementById('widget-weight').value);
        const height = parseFloat(document.getElementById('widget-height').value) / 100; // cm a m
        
        if (weight > 0 && height > 0) {
            const imc = weight / (height * height);
            imcValue.textContent = imc.toFixed(2);
            
            let classification = '';
            if (imc < 18.5) {
                classification = 'Bajo peso';
            } else if (imc >= 18.5 && imc < 25) {
                classification = 'Peso normal';
            } else if (imc >= 25 && imc < 30) {
                classification = 'Sobrepeso';
            } else if (imc >= 30 && imc < 35) {
                classification = 'Obesidad grado I';
            } else if (imc >= 35 && imc < 40) {
                classification = 'Obesidad grado II';
            } else {
                classification = 'Obesidad grado III';
            }
            
            imcClassification.textContent = classification;
            resultDiv.style.display = 'block';
        }
    });
});
</script> 