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

{% block subNav %}
    {% include "portal/partials/teacher_non_dashboard_subnav.html" %}
{% endblock subNav %}

{% block content %}
<div id="move_students_disambiguate_page"></div>

<section class="background container">
    <h4>Move students from class {{ old_class.name }} ({{ old_class.access_code }})</h4>
</section>

<div class="background">
    <div class="container">
        <p><a href="{% url 'view_class' old_class.access_code %}" class="button--menu button--menu--enabled">&lt; Back to Edit class</a></p>
        <p>Choose a class from the drop down menu below to move the student</p>
        <h5>Students currently in destination class</h5>

        {% 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>
            <div class="d-flex">
                <table class="header-primary data-primary col-sm-6">
                    <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>
            </div>
        {% else %}
            <p>There are no students in the class {{ new_class.name }} ({{ new_class.access_code }}).</p>
        {% endif %}

        <h5>Students to transfer</h5>

        <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="header-primary data-primary">
                <tr>
                    <th class="col-sm-6"><p>Existing name</p></th>
                    <th class="col-sm-6"><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 d-flex flex-row justify-content-end align-items-end">
                <a id="cancel_button" class="button button--secondary button--secondary--dark" href="{% url 'view_class' old_class.access_code %}">Cancel</a>
                <button id="move_button" name="submit_disambiguation" type="submit" class="button button--primary">Save</button>
            </section>
            <input type="hidden" name="new_class" value="{{ new_class.id }}"/>

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

{% endblock %}
