{% extends 'portal/base.html' %}

{% block dashboard %}
<a href="{% url 'dashboard' %}" class="button--menu button--menu--secondary button--menu--enabled button--menu--teacher--active">School / Club</a>
{% endblock dashboard %}

{% block content %}

<div id="move_students_disambiguate_page"></div>

<section class="background col-sm-6 col-center">
    <h2>Move students from class {{ old_class.name }} ({{ old_class.access_code }})</h2>
    <h4>Move students to another class.</h4>
</section>

<div class="background background--quaternary">
    <div class="col-sm-6 col-center">
        <h3>Students currently in destination class</h3>

        {% if new_class_students %}
            <p>The following students are in class {{ new_class.name }} ({{ new_class.access_code }}) into which you
                are about to move students from class {{ old_class.name }} ({{ old_class.access_code }}).</p>
            <table class="student-table table--move header-secondary">
                <tr>
                    <th><p>Student Name</p></th>
                </tr>
                {% for student in new_class_students %}
                <tr>
                    <td><p><small>{{ student.new_user.first_name }}</small></p></td>
                </tr>
                {% endfor %}
            </table>
        {% else %}
            <p>There are no students in the class {{ new_class.name }} ({{ new_class.access_code }}).</p>
        {% endif %}

        <h3>Students to transfer</h3>

        <p>Please confirm the names of the following students being moved to class {{ new_class.name }} ({{ new_class.access_code }})
            from class {{ old_class.name }} ({{ old_class.access_code }}). Their names will be used in their new login details, so please ensure it is
            different from any other existing students in the class.</p>

        <form method="POST">

            {% csrf_token %}

            {{ formset.management_form }}

            <table class="student-table table--move header-secondary">
                <tr>
                    <th><p>Original Student Name</p></th>
                    <th><p>New Student Name</p></th>
                </tr>
                {{ formset.non_form_errors }}
                {% for dict in formset.errors %}
                {% for error in dict.values %}
                {{ error }}
                {% endfor %}
                {% endfor %}
                {% for form in formset %}
                <tr>
                    <td>{{ form.orig_name.value }}{{ form.orig_name }}</td>
                    <td>{{ form.name }}</td>
                </tr>
                {% endfor %}
            </table>

            <section class="background button-group">
                <input type="hidden" name="new_class" value="{{ new_class.id }}"/>
                <button id="move_button" name="submit_disambiguation" type="submit" class="button--regular button--primary--navigation">Save</button>
                <a id="cancel_button" class="button button--regular button--secondary button--secondary--dark" href="{% url 'view_class' old_class.access_code %}">Cancel</a>
            </section>

        </form>
    </div>
</div>

<div class="background col-sm-6 col-center">
    <p><a href="{% url 'view_class' old_class.access_code %}">&#10229; Back to Class</a></p>
</div>
{% endblock %}
