{% extends 'longs/exams.html' %}
{% load crispy_forms_tags %}

{% block content %}
    <a href="{% url 'longs:exam_question_detail' exam.id question_details.current %}" title="View the Question">View</a>
    <a href="{% url 'longs:long_update' question.id %}" title="Edit the Question">Edit</a>
    {% if request.user.is_superuser %}
        <a href="{% url 'admin:longs_long_change' question.id %}" title="Edit the Question using the admin interface">Admin
            Edit</a> <a href="{% url 'admin:longs_useranswer_change' answer.id %}"
                title="Edit the user answer using the admin interface">Admin
                Edit (user answer)</a>
    {% endif %}
    <h2>Marking question <a href="{% url 'longs:mark' exam.id question_details.current|add:'-1' %}"
        title="View question answers">{{question_details.current}}</a> of {{question_details.total}}</h2>

    {% if discrepancy_form %}
        <div class="alert alert-info sticky-alert" role="alert">
        <details open>
            <summary><h3>This answer has discrepant scores</h3></summary>
            You can set the overall score here.<br/>

            <form method="POST" class="post-form">{% csrf_token %}
                <input type="hidden" name="form_id" value="discrepancy_form">
                {{ discrepancy_form.as_p }}
                <button type="submit" name="save" class="" title="Save score">Save Score</button>
            </form>

            <h4>Marker scores and reason</h4>
            <ul>
                {% for mark_object in answer.mark.all %}
                    <li>{{mark_object.marker}}: {{mark_object.score}}<br/>
                        {{mark_object.mark_reason}}
                    </li>
                {% endfor %}
            </ul>
        </details>
        </div>
    {% endif %}

    {% if not next_unmarked_id and not unmarked %}
        <div class="alert alert-info sticky-alert" role="alert">Success! Marking question complete. <br />

        
        {% if exam.double_mark %}
            <a href="{% url 'longs:mark_answer_override' exam_id=exam.pk question_number=question_details.current|add:'-1' answer_id=answer.id %}">Set final score</a><br/>
        {% endif %}
            
        Return to <a class="marking-link" href="{% url 'longs:mark' exam.id question_details.current|add:'-1' %}">question
            overview</a>, <a class="marking-link" href="{% url 'longs:mark_overview' pk=exam.pk %}">marking
                overview</a><br />
            {% if previous_answer_id %}
                <a href="{% url 'longs:mark_answer' exam_id=exam.pk question_number=question_details.current|add:'-1' answer_id=previous_answer_id %}">Previous
                    candidate</a>
            {% endif %}
            {% if next_answer_id %}
                <a href="{% url 'longs:mark_answer' exam_id=exam.pk question_number=question_details.current|add:'-1' answer_id=next_answer_id %}">Next
                    candidate</a>
            {% endif %}
        </div>
    {% endif %}

    <span>Marking Candidate: {{answer.get_candidate_masked}} ({{unmarked|length}} answer(s) left to mark)</span>
    <details closed>
        <summary title="click to view/hide the question details">Question Details</summary>
        <p class="pre-whitespace"><b>Description:</b> {{ question.description }}</p>

        <p class="pre-whitespace"><b>History:</b> {{ question.history }}</p>

        <div class="pre-whitespace multi-image-block"><b>Series:</b>
            {% for series in question.series.all %}
                <span class="series-block">
                    <span>
                        Series {{ forloop.counter }}:
                        <a href="{% url 'longs:series_detail' pk=series.pk %}">
                            {{series.get_block}}
                        </a>

                        <a href="#"
                            onclick="return window.create_popup_window('/longs/series/{{series.pk}}', 'Series')">Popup</a>
                    </span>
                </span>
            {% endfor %}
        </div>
    </details>
    <div class="marking-block">
        <details open>
            <summary title="click to view/hide the mark scheme">Mark Scheme</summary>
            {{ question.mark_scheme | safe}}
        </details>
        <details open>
            <summary title="click to view/hide user answers">User answers</summary>
            <div>
                <div class="long-answer">
                    <span class="answer-heading">User observations:</span>
                    <pre>{{answer.answer_observations}}</pre>
                </div>
                <div class="long-answer">
                    <span class="answer-heading">User interpretation:</span>
                    <pre>{{answer.answer_interpretation}}</pre>
                </div>
                <div class="long-answer">
                    <span class="answer-heading">User principle diagnosis:</span>
                    <pre>{{answer.answer_principle_diagnosis}}</pre>
                </div>
                <div class="long-answer">
                    <span class="answer-heading">User differential diagnosis:</span>
                    <pre>{{answer.answer_differential_diagnosis}}</pre>
                </div>
                <div class="long-answer">
                    <span class="answer-heading">User management:</span>
                    <pre>{{answer.answer_management}}</pre>
                </div>

            </div>
        </details>
    </div>
    <div class="marking">
        <form method="POST" class="post-form">{% csrf_token %}
            <input type="hidden" name="form_id" value="mark_form">
            {{ form|crispy }}
            <button type="submit" name="save" class="save btn btn-default" title="Save answer">Save</button>
            {% if next_unmarked_id %}
                <button type="submit" name="next" class="save btn btn-default"
                    title="Save answer and move to next question">Next answer</button>
                <!-- <button type="submit" name="skip" class="save btn btn-default">Skip</button> -->
            {% else %}
                {% if not unmarked %}
                    Success! Marking question complete. <a href="{% url 'longs:mark_overview' pk=exam.pk %}">Return to marking
                        overview</a>
                {% endif %}
            {% endif %}
        </form>
    </div>
    {% if previous_answer_id %}
        <a href="{% url 'longs:mark_answer' exam_id=exam.pk question_number=question_details.current|add:'-1' answer_id=previous_answer_id %}">Previous
            candidate</a>
    {% endif %}
    {% if next_answer_id %}
        <a href="{% url 'longs:mark_answer' exam_id=exam.pk question_number=question_details.current|add:'-1' answer_id=next_answer_id %}">Next candidate</a>
    {% endif %}
{% endblock %}
