{# Partial: aggregated response summary for a question within an exam. HTMX-loadable. #}
<div id="response-summary-content">
    {% if exam_response_total %}
        <div class="small text-muted mb-2">Total responses: {{ exam_response_total }}</div>
        <div class="row mb-2">
            <div class="col-auto">Correct:</div>
            <div class="col">
                {% if exam_response_correct_count is not None %}
                    <strong>{{ exam_response_correct_count }}</strong>
                    {% if exam_response_correct_pct is not None %}
                        <span class="text-muted">({{ exam_response_correct_pct }}%)</span>
                    {% endif %}
                {% else %}
                    <span class="text-muted">N/A</span>
                {% endif %}
            </div>
        </div>
        <div class="list-group">
            {# Choice A #}
            <div class="list-group-item">
                <div class="d-flex w-100 justify-content-between align-items-center">
                    <div class="d-flex align-items-center">
                        <div class="fw-bold me-3">A</div>
                        {% if exam_response_texts.a %}
                            <div class="small text-muted text-wrap">{{ exam_response_texts.a|safe }}</div>
                        {% endif %}
                    </div>
                    <div class="text-end">
                        <span class="me-2">{{ exam_response_counts.a|default:0 }}</span>
                        <small class="text-muted">{{ exam_response_pcts.a|default:0 }}%</small>
                    </div>
                </div>
                <div class="progress mt-2" style="height:12px;">
                    <div class="progress-bar {% if question.best_answer == 'a' %}bg-success{% else %}bg-danger{% endif %}" role="progressbar"
                         style="width: {{ exam_response_pcts.a|default:0 }}%;"
                         aria-valuenow="{{ exam_response_pcts.a|default:0 }}" aria-valuemin="0" aria-valuemax="100"></div>
                </div>
            </div>

            {# Choice B #}
            <div class="list-group-item">
                <div class="d-flex w-100 justify-content-between align-items-center">
                    <div class="d-flex align-items-center">
                        <div class="fw-bold me-3">B</div>
                        {% if exam_response_texts.b %}
                            <div class="small text-muted text-wrap">{{ exam_response_texts.b|safe }}</div>
                        {% endif %}
                    </div>
                    <div class="text-end">
                        <span class="me-2">{{ exam_response_counts.b|default:0 }}</span>
                        <small class="text-muted">{{ exam_response_pcts.b|default:0 }}%</small>
                    </div>
                </div>
                <div class="progress mt-2" style="height:12px;">
                    <div class="progress-bar {% if question.best_answer == 'b' %}bg-success{% else %}bg-danger{% endif %}" role="progressbar"
                         style="width: {{ exam_response_pcts.b|default:0 }}%;"
                         aria-valuenow="{{ exam_response_pcts.b|default:0 }}" aria-valuemin="0" aria-valuemax="100"></div>
                </div>
            </div>

            {# Choice C #}
            <div class="list-group-item">
                <div class="d-flex w-100 justify-content-between align-items-center">
                    <div class="d-flex align-items-center">
                        <div class="fw-bold me-3">C</div>
                        {% if exam_response_texts.c %}
                            <div class="small text-muted text-wrap">{{ exam_response_texts.c|safe }}</div>
                        {% endif %}
                    </div>
                    <div class="text-end">
                        <span class="me-2">{{ exam_response_counts.c|default:0 }}</span>
                        <small class="text-muted">{{ exam_response_pcts.c|default:0 }}%</small>
                    </div>
                </div>
                <div class="progress mt-2" style="height:12px;">
                    <div class="progress-bar {% if question.best_answer == 'c' %}bg-success{% else %}bg-danger{% endif %}" role="progressbar"
                         style="width: {{ exam_response_pcts.c|default:0 }}%;"
                         aria-valuenow="{{ exam_response_pcts.c|default:0 }}" aria-valuemin="0" aria-valuemax="100"></div>
                </div>
            </div>

            {# Choice D #}
            <div class="list-group-item">
                <div class="d-flex w-100 justify-content-between align-items-center">
                    <div class="d-flex align-items-center">
                        <div class="fw-bold me-3">D</div>
                        {% if exam_response_texts.d %}
                            <div class="small text-muted text-wrap">{{ exam_response_texts.d|safe }}</div>
                        {% endif %}
                    </div>
                    <div class="text-end">
                        <span class="me-2">{{ exam_response_counts.d|default:0 }}</span>
                        <small class="text-muted">{{ exam_response_pcts.d|default:0 }}%</small>
                    </div>
                </div>
                <div class="progress mt-2" style="height:12px;">
                    <div class="progress-bar {% if question.best_answer == 'd' %}bg-success{% else %}bg-danger{% endif %}" role="progressbar"
                         style="width: {{ exam_response_pcts.d|default:0 }}%;"
                         aria-valuenow="{{ exam_response_pcts.d|default:0 }}" aria-valuemin="0" aria-valuemax="100"></div>
                </div>
            </div>

            {# Choice E #}
            <div class="list-group-item">
                <div class="d-flex w-100 justify-content-between align-items-center">
                    <div class="d-flex align-items-center">
                        <div class="fw-bold me-3">E</div>
                        {% if exam_response_texts.e %}
                            <div class="small text-muted text-wrap">{{ exam_response_texts.e|safe }}</div>
                        {% endif %}
                    </div>
                    <div class="text-end">
                        <span class="me-2">{{ exam_response_counts.e|default:0 }}</span>
                        <small class="text-muted">{{ exam_response_pcts.e|default:0 }}%</small>
                    </div>
                </div>
                <div class="progress mt-2" style="height:12px;">
                    <div class="progress-bar {% if question.best_answer == 'e' %}bg-success{% else %}bg-danger{% endif %}" role="progressbar"
                         style="width: {{ exam_response_pcts.e|default:0 }}%;"
                         aria-valuenow="{{ exam_response_pcts.e|default:0 }}" aria-valuemin="0" aria-valuemax="100"></div>
                </div>
            </div>
        </div>
        {# Unanswered / other responses (blank, None, or unexpected labels) #}
        {% if exam_response_counts.unanswered|default:0 %}
            <div class="list-group-item">
                <div class="d-flex w-100 justify-content-between align-items-center">
                    <div>No answer / Other</div>
                    <div class="text-end">
                        <span class="me-2">{{ exam_response_counts.unanswered|default:0 }}</span>
                        <small class="text-muted">{{ exam_response_pcts.unanswered|default:0 }}%</small>
                    </div>
                </div>
                <div class="progress mt-2" style="height:12px;">
                    <div class="progress-bar bg-secondary" role="progressbar"
                         style="width: {{ exam_response_pcts.unanswered|default:0 }}%;"
                         aria-valuenow="{{ exam_response_pcts.unanswered|default:0 }}" aria-valuemin="0" aria-valuemax="100"></div>
                </div>
            </div>
        {% endif %}
    {% else %}
        <div class="small text-muted">No responses recorded for this question in the exam yet.</div>
    {% endif %}
</div>
