{% if submission.contest_or_none %}
    {% set prefix_length = submission.contest_or_none.problem.output_prefix_override %}
{% else %}
    {% set prefix_length = None %}
{% endif %}
{% set is_pretest = submission.is_pretested %}

{% if submission.status != 'IE' %}
    {% if submission.status == 'QU' %}
        <h4>{{ _('We are waiting for a suitable judge to process your submission...') }}</h4>
    {% elif submission.status == 'P' %}
        <h4>{{ _('Your submission is being processed...') }}</h4>
    {% elif submission.status == 'CE' %}
        <h3>{{ _('Compilation Error') }}</h3>
        <pre>{{ submission.error|ansi2html }}</pre>
    {% else %}
        {% if submission.error %}
            <h3>{{ _('Compilation Warnings') }}</h3>
            <pre>{{ submission.error|ansi2html }}</pre>
            <hr><br>
        {% endif %}
        {% if is_pretest %}
            <h3>{{ _('Pretest Execution Results') }}</h3>
        {% else %}
            <h3>{{ _('Execution Results') }}</h3>
        {% endif %}
        <br>
        {% set test_case_id = counter() %}
        {% for batch in batches %}
            {% if batch.id %}
                <b>{{ _('Batch ') }}#{{ test_case_id() }}</b>
                ({{ _('%(points)s/%(total)s points', points=batch.points|floatformat(0), total=batch.total|floatformat(0)) }})
                <br>
                <div class="batch-cases">
            {% endif %}
        <table id="testcases-table">
            {% if submission.is_graded %}
            {% if submission.result != 'AB' %}
            <thead>
                
            <tr id="overall-row" class="case-row  overall-result-{{submission.result}}">
                
                <td><span class="col-title">{{_('Overall: ')}}</span>
                {% if request.in_contest and submission.contest_or_none %}
                    {% with contest=submission.contest_or_none %}
                        ({{ _('%(points)s/%(total)s points', points=contest.points|roundfloat(3),
                              total=contest.problem.points|floatformat(-1)) }})
                    {% endwith %}
                {% else %}
                    {{ _('%(points)s/%(total)s', points=submission.points|roundfloat(3),
                          total=submission.problem.points|floatformat(-1)) }}
                {% endif %}
                </td>
                
                <td><span class="case-{{submission.result}}">{{submission.long_status}}</span></td>
                
                <td><span class="col-title">{{_('Point: ')}}</span> 
                    {{ submission.case_points|floatformat(1) }}/{{ submission.case_total|floatformat(0) }}
                    
                </td>
                
                <td><span class="col-title">{{_('Time: ')}}</span> 
                {% if submission.result == "TLE" %}
                    <span>---</span>
                {% else %}
                    <span title="{{ submission.time }}s">{{ (submission.time * 1000)|floatformat(0) }} ms</span>
                {% endif %}

                </td>
                
                <td><span class="col-title">{{_('Memory: ')}}</span>{{ submission.memory|kbdetailformat }}</td>
            </tr>
            </thead>
            {% endif %}
            {% endif %}

            {% for case in batch.cases %}
            <tr id="{{ case.id }}" class="case-row toggle closed">
                <td>
                    {%- if ((prefix_length is none or prefix_length > 0) or (request.user.is_superuser)) -%}
                        <i class="fa fa-chevron-right fa-fw"></i>
                    {%- endif -%}
                    {%- if batch.id -%}
                        <b>{{ _('Case') }} #{{ loop.index }}:</b>
                    {%- elif is_pretest -%}
                        <b>{{ _('Pretest') }} #{{ test_case_id() }}:</b>
                    {%- else -%}
                        <b>{{ _('Test case') }} #{{ test_case_id() }}:</b>
                    {%- endif -%}
                </td>

                <td>
                    <span title="{{ case.long_status }}" class="case-{{ case.status }}">
                        {%- if case.status == 'SC' %}&mdash;{% else %}{{ case.long_status }}{% endif -%}
                    </span>
                </td>

                {% if not batch.id %}
                    <td><span class="col-title">{{_('Point')}}: </span> {{ case.points|floatformat }}/{{ case.total|floatformat(0) }}</td>
                {% endif %}

                <td>
                    {%- if case.status != 'SC' -%}
                        {%- if case.status == 'TLE' -%}
                            <span><span class="col-title">{{_('Time')}}: &gt;</span>{{ (time_limit * 1000)|floatformat(0) }} ms</span>
                        {%- else -%}
                            <span title="{{ case.time }}s"><span class="col-title">{{_('Time')}}: </span>{{ (case.time * 1000)|floatformat(0) }} ms</span>
                        {%- endif -%}
                    {%- endif -%}
                </td>

                <td>{% if case.status != 'SC' %}<span class="col-title">{{_('Memory')}}: </span> {{ case.memory|kbdetailformat }}{% endif %}</td>
            </tr>

            {% if ((prefix_length is none or prefix_length > 0) or (request.user.is_superuser)) %}
                <tr id="{{ case.id }}-output" style="display:none" class="case-feedback toggled">
                    <td colspan="5">
                        <div class="case-info">
                            {% set curr_data = cases_data[case.case] %}
                            {% if curr_data != null %}
                            <strong>{{ _('Input:') }}</strong>
                            <pre class="case-output">{{ curr_data['input']|linebreaksbr }}</pre>
                            {% endif %}
                            
                            <strong>{{ _('Output:') }}</strong>
                            <pre class="case-output">{{ case.output|linebreaksbr }}</pre>

                            {% if curr_data != null %}
                            <strong>{{ _('Answer:') }}</strong>
                            <pre class="case-output">{{ curr_data['answer']|linebreaksbr }}</pre>
                            {% endif %}

                            {% if case.extended_feedback or case.feedback %}
                            <strong>{{ _('Judge feedback:') }}</strong>
                                {% if case.feedback %}
                                <pre class="case-output">{{ case.feedback|linebreaksbr }}</pre>    
                                {% endif %}
                                {% if case.extended_feedback %}
                                <pre class="case-output">{{ case.extended_feedback|linebreaksbr }}</pre>
                                {% endif %}
                            {% endif %}
                        </div>
                    </td>
                </tr>
            {% endif %}
        {% endfor %}
        </table>

        {% if batch.id %}</div>{% endif %}
            <br>
        {% endfor %}
        {% if submission.is_graded %}
            <br>
            {% if submission.result != "AB" %}
                {% if is_pretest and submission.result == "AC" %}
                    <br>
                    <i>{{ _('Passing pretests does not guarantee a full score on system tests.') }}</i>
                {% endif %}
            {% else %}
                <b>{{ _('Submission aborted!') }}</b>
            {% endif %}
            <br>
        {% endif %}
    {% endif %}
{% else %}
    {% include "submission/internal-error-message.html" %}
{% endif %}