{% extends "base.html" %}

{% block content %}
    <h1>Edit Assessment</h1>
    <form method="POST">
        <div class="form-group">
            <label for="name">Assessment Name</label>
            <input type="text" class="form-control" id="name" name="name" value="{{ assessment.name }}" required>
        </div>
        <div class="form-group">
            <label for="description">Description</label>
            <textarea class="form-control" id="description" name="description" rows="3" required>{{ assessment.description }}</textarea>
        </div>
        <div class="form-group">
            <label for="assessment_type">Assessment Type</label>
            <select class="form-control" id="assessment_type" name="assessment_type">
                <option value="Mixed" {% if assessment.assessment_type == 'Mixed' %}selected{% endif %}>Mixed</option>
                <option value="Yes/No" {% if assessment.assessment_type == 'Yes/No' %}selected{% endif %}>Yes/No</option>
                <option value="Likert Scale" {% if assessment.assessment_type == 'Likert Scale' %}selected{% endif %}>Likert Scale</option>
                <!-- Add other types as needed -->
            </select>
        </div>
        <div class="form-group form-check">
            <input type="checkbox" class="form-check-input" id="is_free" name="is_free" {% if assessment.is_free %}checked{% endif %} onchange="togglePriceField()">
            <label class="form-check-label" for="is_free">Is Free</label>
        </div>
        <div class="form-group" id="price_field">
            <label for="price">Price per Unit (₹)</label>
            <input type="number" id="price" name="price" class="form-control" min="0" step="0.01" value="{{ assessment.price }}" required>
            <small class="form-text text-muted">Set the price per unit for this assessment. This will be used when consultants request this assessment.</small>
        </div>
        <div class="form-group" id="min_quantity_field">
            <label for="min_quantity">Minimum Quantity</label>
            <input type="number" id="min_quantity" name="min_quantity" class="form-control" min="1" step="1" value="{{ assessment.min_quantity or 1 }}" required>
            <small class="form-text text-muted">Set the minimum units that can be requested for this assessment.</small>
        </div>
        <div class="form-group form-check">
            <input type="checkbox" class="form-check-input" id="show_domain_wise" name="show_domain_wise" {% if assessment.show_domain_wise %}checked{% endif %}>
            <label class="form-check-label" for="show_domain_wise">Show Domain-wise Results</label>
        </div>
        <button type="submit" class="btn btn-primary">Update Assessment</button>
        <a href="{{ url_for('admin.manage_assessments') }}" class="btn btn-secondary">Cancel</a>
    </form>
{% endblock %}

{% block scripts %}
<script>
    function togglePriceField() {
        const isFreeCheckbox = document.getElementById('is_free');
        const priceField = document.getElementById('price_field');
        const priceInput = document.getElementById('price');
        const minQtyField = document.getElementById('min_quantity_field');
        const minQtyInput = document.getElementById('min_quantity');
        
        if (isFreeCheckbox.checked) {
            priceField.style.display = 'none';
            priceInput.required = false;
            priceInput.value = '0.0';
            minQtyField.style.display = 'none';
            minQtyInput.required = false;
        } else {
            priceField.style.display = 'block';
            priceInput.required = true;
            minQtyField.style.display = 'block';
            minQtyInput.required = true;
        }
    }
    
    // Initialize on page load
    document.addEventListener('DOMContentLoaded', function() {
        togglePriceField();
    });
</script>
{% endblock %}
