{% extends "admin/base_site.html" %}
{% comment %}Admin tool displaying logs statistics{% endcomment %}
{% load i18n aircox %}


{% block content %}{{ block.super }}
<div id="app">

{# TODO: date subtitle #}
<nav class="navbar" role="menu">
    {% with "admin:tools-stats" as url_name %}
    {% include "aircox/widgets/dates_menu.html" %}
    {% endwith %}
</nav>

<a-statistics class="column">
<template v-slot="{counts}">
    <table class="table is-hoverable is-fullwidth">
        <thead>
            <tr>
                <th>{% translate "Time" %}</th>
                <th>{% translate "Episode" %}</th>
                <th>{% translate "Track" %}</th>
                <th>{% translate "Tags" %}</th>
            </tr>
        </thead>
        <tbody>
        {% for object in object_list %}
        {% with object|get_tracks as tracks %}
        {% for track in tracks %}
        <tr>
            {% if forloop.first %}
            <td rowspan="{{ tracks|length }}">{{ object.start|time:"H:i" }} {% if object|is_diffusion %} - {{ object.end|time:"H:i" }}{% endif %}</td>
            <td rowspan="{{ tracks|length }}">{{ object.episode|default:"" }}</td>
            {% endif %}

            {% with track as object %}
            <td>{% include "aircox/widgets/track_item.html" %}</td>
            {% endwith %}
            {% with track.tags.all|join:', ' as tags %}
            <td>
                {% if tags %}
                <label class="checkbox">
                    <input type="checkbox" checked value="{{ tags|escape }}" name="data">
                    {{ tags }}
                </label>
                {% endif %}
            </td>
            {% endwith %}
        </tr>
        {% empty %}
        {% if object|is_diffusion %}
        <tr>
            <td>{{ object.start|time:"H:i" }} - {{ object.end|time:"H:i" }}</td>
            <td>{{ object.episode|default:"" }}</td>
            <td></td>
            <td></td>
        </tr>
        {% endif %}
        {% endfor %}
        {% endwith %}
        {% endfor %}
        </tbody>
        <tfoot>
            <tr>
                <td class="is-size-6">{% translate "Total" %}</td>
                <td colspan="100">
                    <div class="columns is-size-6">
                        <span v-for="(count, tag) in counts" class="column">
                            <b>[[ tag ]]</b>
                            [[ count ]]
                        </span>
                    </div>
                </td>
            </tr>
        </tfoot>
    </table>
</template>
</a-statistics>

</div>
{% endblock %}
