{% comment %} Partial: submitted candidates fragment for HTMX swap {% endcomment %}
{% if user_exam_data %}
    <div class="card">
        <div class="card-body">
            <div class="d-flex justify-content-between align-items-start mb-2">
                <div>
                    <h5 class="card-title mb-0">Submitted candidates</h5>
                    <div class="small text-muted">The following candidate submissions have been received. Candidates with submissions are highlighted above.</div>
                </div>
                <div class="d-flex align-items-center">
                    <div class="small text-muted">Count: <span class="fw-semibold">{{ user_exam_data|length }}</span></div>
                    {% if request.user.is_superuser or request.user.is_staff %}
                        <div class="ms-3">
                            <a class="btn btn-sm btn-outline-primary" href="{% url 'admin:generic_ciduserexam_changelist' %}" target="_blank" rel="noopener">View submissions (admin)</a>
                        </div>
                    {% endif %}
                </div>
            </div>

            <div class="table-responsive">
                <table class="table table-sm table-hover align-middle mb-0">
                    <thead class="table-light">
                        <tr>
                            <th scope="col">CID</th>
                            <th scope="col">User</th>
                            <th scope="col">Start</th>
                            <th scope="col">End</th>
                            <th scope="col" class="text-end">Actions</th>
                        </tr>
                    </thead>
                    <tbody id="submitted-candidates">
                        {% for user_data in user_exam_data %}
                            <tr data-cid="{{ user_data.cid_user }}" data-user="{{ user_data.user_user }}" data-first="{{ user_data.start_time|default_if_none:'' }}" data-last="{{ user_data.end_time|default_if_none:'' }}" {% if not user_data.in_exam %}class="table-warning"{% endif %}>
                                <td class="fw-bold">{{ user_data.cid_user }}{% if not user_data.in_exam %} <span class="badge bg-danger ms-2" title="Candidate/User not added to exam">Not added</span>{% endif %}</td>
                                <td>{{ user_data.user_user }}</td>
                                <td class="text-nowrap small {% if user_data.in_exam %}text-muted{% else %}text-dark{% endif %}">{{ user_data.start_time }}</td>
                                <td class="text-nowrap small {% if user_data.in_exam %}text-muted{% else %}text-dark{% endif %}">{{ user_data.end_time }}</td>
                                <td class="text-end">
                                    <div class="btn-group" role="group">
                                        {% if user_data.cid_user %}
                                            <button class="btn btn-sm btn-outline-secondary" title="View details" hx-get="{% url exam.get_app_name|add:':exam_user_status' exam.id %}?cid={{ user_data.cid_user.cid }}" hx-target="#history-modal .modal-body" data-bs-toggle="modal" data-bs-target="#history-modal"><i class="bi bi-eye"></i></button>
                                            <a class="btn btn-sm btn-outline-success" href="{% url exam.get_app_name|add:':exam_scores_cid_user_admin' exam.id user_data.cid_user.cid %}" target="_blank" rel="noopener" title="View candidate answers"><i class="bi bi-file-earmark-text"></i></a>
                                        {% else %}
                                            <button class="btn btn-sm btn-outline-secondary" title="View details" hx-get="{% url exam.get_app_name|add:':exam_user_status' exam.id %}?user_id={{ user_data.user_user.id }}" hx-target="#history-modal .modal-body" data-bs-toggle="modal" data-bs-target="#history-modal"><i class="bi bi-eye"></i></button>
                                            <a class="btn btn-sm btn-outline-success" href="{% url exam.get_app_name|add:':exam_scores_user_admin' exam.id user_data.user_user.id %}" target="_blank" rel="noopener" title="View candidate answers"><i class="bi bi-file-earmark-text"></i></a>
                                        {% endif %}
                                        {% if request.user.is_superuser or request.user.is_staff %}
                                            <a class="btn btn-sm btn-outline-primary" href="{% url 'admin:generic_ciduserexam_change' user_data.pk %}" target="_blank" rel="noopener" title="Edit submission in admin"><i class="bi bi-pencil-square"></i></a>
                                        {% endif %}
                                    </div>
                                </td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
{% else %}
    <div class="card">
        <div class="card-body">
            <p class="mb-0 small text-muted">No submissions yet.</p>
        </div>
    </div>
{% endif %}

