{% extends "jury/base.html.twig" %}
{% import "jury/jury_macros.twig" as macros %}

{% block title %}Internal error e{{ internalError.errorid }} - {{ parent() }}{% endblock %}

{% block extrahead %}
    {{ parent() }}
    {{ macros.table_extrahead() }}
{% endblock %}

{% block content %}

    <h1>Internal error e{{ internalError.errorid }}</h1>

    <div class="row">
        <div class="col-lg-6">
            <table class="table table-sm table-striped">
                <tr>
                    <th>Description</th>
                    <td>
                        {% if internalError.description is empty %}
                            <span class="nodata">None</span>
                        {% else %}
                            {{ internalError.description }}
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <th>Time</th>
                    <td>{{ internalError.time | printtime('Y-m-d H:i:s') }}</td>
                </tr>
                <tr>
                    <th>Status</th>
                    <td>{{ internalError.status | capitalize }}</td>
                </tr>
                {% if internalError.judging is not null %}
                    <tr>
                        <th>Related judging</th>
                        <td>
                            <a href="{{ path('jury_submission_by_judging', {jid: internalError.judging.judgingid}) }}">
                                j{{ internalError.judging.judgingid }}
                            </a>
                        </td>
                    </tr>
                {% endif %}
                {% if internalError.judgingRun is not null %}
                    <tr>
                        <th>Related judging run / testcase</th>
                        <td>
                            {% set tc = internalError.judgingRun.testcase %}
                            <ul>
                                <li>
                                    <a href="{{ path('jury_submission_by_judging', {jid: internalError.judging.judgingid}) }}#run-{{ tc.rank }}">
                                        tc{{ tc.testcaseid }}
                                    </a>
                                </li>
                                <li>
                                    rank: {{ tc.rank }}
                                </li>
                                {% if tc.description is not empty %}
                                    <li>
                                        description: {{ tc.description }}
                                    </li>
                                {% endif %}
                                <li>
                                    original filename: <code>{{ tc.origInputFilename }}.in</code>
                                </li>
                                <li>
                                    testcase group: {{ (tc.sample) ? 'sample' : 'secret' }}
                                </li>
                            </ul>
                        </td>
                    </tr>
                {% endif %}
                {% if internalError.affectedJudgings is not null and internalError.affectedJudgings | length > 1 %}
                    <tr>
                        <th>All affected judgings</th>
                        <td>
                            <ul>
                            {%- for judging in internalError.affectedJudgings -%}
                                <li>
                                    <a href="{{ path('jury_submission_by_judging', {jid: judging.judgingid}) }}">
                                        j{{ judging.judgingid }}
                                    </a>
                                </li>
                            {%- endfor -%}
                            </ul>
                        </td>
                    </tr>
                {% endif %}
                {% if internalError.contest is not null %}
                    <tr>
                        <th>Related contest</th>
                        <td>
                            <a href="{{ path('jury_contest', {'contestId': internalError.contest.externalid}) }}">
                                {{ internalError.contest.externalid }}
                            </a>
                        </td>
                    </tr>
                {% endif %}
                {% if affectedText is not null %}
                    <tr>
                        <th>Affected {{ internalError.disabled.kind }}</th>
                        <td>
                            {% if affectedLink %}
                                <a href="{{ affectedLink }}">{{ affectedText }}</a>
                            {% else %}
                                {{ affectedText }}
                            {% endif %}
                        </td>
                    </tr>
                {% endif %}
                <tr>
                    <th>Judgehost log snippet</th>
                    <td>
                        <pre class="output_text">{{ internalError.judgehostlog | base64_decode | convertUnprintableChars }}</pre>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    {% if internalError.status == 'open' %}
        <form action="{{ path('jury_internal_error_handle', {errorId: internalError.errorid, action: 'ignore'}) }}"
              method="post" class="d-inline">
            <button type="submit" class="btn btn-danger">
                <i class="fas fa-times"></i> Ignore error
            </button>
        </form>

        <form action="{{ path('jury_internal_error_handle', {errorId: internalError.errorid, action: 'resolve'}) }}"
              method="post" class="d-inline">
            <button type="submit" class="btn btn-success">
                <i class="fas fa-check"></i> Mark as resolved and re-enable {{ internalError.disabled.kind }}
            </button>
        </form>
    {% endif %}

{% endblock %}
