{% from "macros.html" import excel_button %}
<div class="d-flex justify-content-between">
    {{ excel_button('', 'excel_select') }}
    <div>
        <input type="checkbox" id="compare" name="compare" {% if config["COMPARE"] %}{{ "checked" }}{% endif %}>
        <span class="badge bg-info bg-small" onclick="$('#compare').click()">Comparing with best results</span>
    </div>
</div>
<table id="file-table"
       class="table table-striped table-hover table-bordered bg-light"
       data-toggle="table"
       data-sticky-header="true"
       data-sticky-header-offset-y="65"
       data-sortable="true"
       data-show-multi-sort="true"
       data-sort-priority='[{"sortName": "date", "sortOrder": "desc"},{"sortName": "time", "sortOrder": "desc"}]'
       data-search="true">
    <thead>
        <tr class="bg-primary text-white">
            <th data-field="model" data-sortable="true">Model</th>
            <th data-field="metric" data-sortable="true">Metric</th>
            <th data-field="platform" data-sortable="true">Platform</th>
            <th data-field="date" data-sortable="true">Date</th>
            <th data-field="time" data-sortable="true">Time</th>
            <th data-field="stratified" data-sortable="true">Stratified</th>
            <th data-field="title" data-sortable="true">Title</th>
            <th data-field="score" data-sortable="true">Score</th>
            <th>
                <button class="btn btn-primary btn-small btn-danger"
                        onclick="setCheckBoxes(false)">
                    <i class="mdi mdi-checkbox-multiple-blank"></i>
                </button>
                <button class="btn btn-primary btn-small btn-success"
                        onclick="setCheckBoxes(true)">
                    <i class="mdi mdi-checkbox-multiple-marked"></i>
                </button>
            </th>
        </tr>
    </thead>
    <tbody>
        {% for file, data in files.items() %}
            {% set parts = file.split('_') %}
            {% set stratified = parts[6].split('.')[0] %}
            <tr id="{{ file }}">
                <td>{{ parts[2] }}</td>
                <td>{{ parts[1] }}</td>
                <td>{{ parts[3] }}</td>
                <td class="text-center">{{ parts[4] }}</td>
                <td class="text-center">{{ parts[5] }}</td>
                <td class="text-center">{{ 'True' if stratified =='1' else 'False' }}</td>
                <td>{{ "%s" % data["title"] }}</td>
                <td class="text-end">{{ "%.6f" % data["score"] }}</td>
                <td>
                    {% set file_best = "best_results_" ~ parts[1] ~ "_" ~ parts[2] ~ ".json" %}
                    <button class="btn btn-primary btn-small"
                            onclick='location.href="{{ url_for("results.report", file_name=file) }}"'>
                        <i class="mdi mdi-table-eye"></i>
                    </button>
                    <button class="btn btn-primary btn-small"
                            onclick='location.href="{{ url_for("results.best", file_name=file_best) }}"'
                            hidden="true"
                            name="best_buttons">
                        <i class="mdi mdi-star-circle-outline"></i>
                    </button>
                    <input type="checkbox" name="selected_files" value="{{ file }}" />
                </td>
            </tr>
        {% endfor %}
    </tbody>
</table>
