<div class="row">
<div class="col-md-8 col-12">
<h4 class="mb-3">{{ 'Candidates'|trans }}</h4>
<table class="table table-hover mb-3">
    <thead>
        <tr>
            <th scope="col">{{ 'Name'|trans }}</th>
            <th scope="col">{{ 'Quiz Status'|trans }}</th>
            <th scope="col">{{ 'Candidate Status'|trans }}</th>
            <th scope="col">{{ 'Actions'|trans }}</th>
        </tr>
    </thead>
    <tbody>
        {% for data in candidateData %}
            {% set candidate = data.candidate %}
            {% set quizCandidate = data.quizCandidate %}
            {% set givenAnswersCount = data.givenAnswersCount %}

            <tr>
                <td>{{ candidate.name }}</td>
                <td>
                    {% if quizCandidate and quizCandidate.started %}
                        {% if givenAnswersCount >= quiz.questions|length %}
                            <span class="badge text-bg-success">{{ 'Completed'|trans }}</span>
                        {% else %}
                            <span class="badge text-bg-warning">{{ 'In Progress'|trans }} ({{ givenAnswersCount }}/{{ quiz.questions|length }})</span>
                        {% endif %}
                    {% else %}
                        <span class="badge text-bg-secondary">{{ 'Not Started'|trans }}</span>
                    {% endif %}
                </td>
                <td>
                    {% if quizCandidate == null or quizCandidate.active %}
                        <span class="badge text-bg-success">{{ 'Active'|trans }}</span>
                    {% else %}
                        <span class="badge text-bg-secondary">{{ 'Inactive'|trans }}</span>
                    {% endif %}
                </td>
                <td>
                    <form action="{{ path('tvdt_backoffice_toggle_candidate', {quiz: quiz.id, candidate: candidate.id}) }}" method="POST" class="d-inline">
                        <input type="hidden" name="_token" value="{{ csrf_token('toggle_candidate') }}">
                        <button type="submit" class="btn btn-sm btn-outline-secondary">
                            {% if quizCandidate == null or quizCandidate.active %}
                                {{ 'Deactivate'|trans }}
                            {% else %}
                                {{ 'Activate'|trans }}
                            {% endif %}
                        </button>
                    </form>
                    {% if quizCandidate and quizCandidate.started %}
                        <form action="{{ path('tvdt_backoffice_reset_candidate_progress', {quiz: quiz.id, candidate: candidate.id}) }}" method="POST" class="d-inline" onsubmit="return confirm('{{ 'Are you sure you want to reset progress for this candidate? Their given answers for this quiz will be deleted.'|trans|e('js') }}');">
                            <input type="hidden" name="_token" value="{{ csrf_token('reset_candidate_progress') }}">
                            <button type="submit" class="btn btn-sm btn-outline-danger">{{ 'Reset progress'|trans }}</button>
                        </form>
                    {% endif %}
                </td>
            </tr>
        {% endfor %}
    </tbody>
</table>
</div>
<div class="col-md-4 col-12">
    {{ include('backoffice/help/quiz_candidates.html.twig') }}
</div>
</div>
