<!DOCTYPE html>
<html lang="en">
<head>
    <title>My Webpage</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
          integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

</head>
<body>
<div class="container">
    <h1>
        Протокол тестування роботи {{ file_name }}
        <span class="badge bg-primary">{{total_score}} / {{max_score}}</span>
    </h1>
    {% for test in tests %}
    {% set tests_loop = loop %}
    <div class="card">
        <div class="card-header">
            Тест №{{ tests_loop.index }}
            <span class="badge bg-primary">{{details[tests_loop.index0].score}} / {{test.score}}</span>
        </div>
        <div class="card-body">
            <h5 class="card-title">Вхідні дані</h5>
            <div class="table-responsive" style="max-height: 300px;">
                <table class="table table-bordered">
                    <thead>
                    <tbody>
                    {% for query in test.inputs %}
                    <tr>
                        <td>{{ query }}</td>
                    </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
            <h5 class="card-title">Вихідні дані</h5>
            <h6>Виконувався запит</h6>
            <div class="alert alert-primary" role="alert">
                {{ test.query }}
            </div>
            <h6>Правильний результат</h6>
            <div class="table-responsive" style="max-height: 300px;">
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        {% for column in test.outputs %}
                        <th scope="col">{{ column }}</th>
                        {% endfor %}
                    </tr>
                    </thead>
                    <tbody>
                    {% for row in test.results[1] %}
                    <tr>
                        {% for field in test.outputs %}
                        <th scope="col">{{ row[field] }}</th>
                        {% endfor %}
                    </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
            <h6>Одержаний результат</h6>
            <div class="table-responsive" style="max-height: 300px;">
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        {% for column in test.outputs %}
                        <th scope="col">{{ column }}</th>
                        {% endfor %}
                    </tr>
                    </thead>
                    <tbody>
                    {% for row in details[tests_loop.index0].results[1] %}
                    {% set row_loop = loop %}
                    <tr>
                        {% for field in test.outputs %}
                        <th scope="col"
                            class="{% if (test.results[1]|length > row_loop.index0) and (test.results[1][row_loop.index0][field] == row[field]) %}table-success{% else %}table-danger{% endif %}">
                            {{ row[field] }}
                        </th>
                        {% endfor %}
                    </tr>
                    {% endfor %}
                    </tbody>
                </table>
                {% if details[tests_loop.index0].error %}
                <div class="alert alert-danger" role="alert">
                    Помилка під час виконання запиту: <b>{{ details[tests_loop.index0].error }}</b>
                </div>
                {% endif %}
            </div>
        </div>
    </div>
    {% endfor %}
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
        crossorigin="anonymous"></script>
</body>
</html>