{% extends "base.html" %}

{% block content %}
    <div class="row border-bottom mb-3">
        <div class="col">
            <form method="get">
                {{ date_form.non_field_errors }}
                <p class="lead">
                    Statistiques de l'année {{ date_form.year }}
                    <button type="submit" class="btn btn-sm btn-outline-primary">Mettre à jour</button>
                </p>
            </form>
        </div>
    </div>
    {% include "statistiques/stat-tabs.html" with active="prestations" %}

    <div class="row">
        <div class="col">
            <table class="table table-sm stat_table">
                <thead>
                    <tr>
                        <th></th>
                        {% for month in months %}
                        <th class="month">{{ month|date:"N" }}</th>
                        {% endfor %}
                        <th class="total num">Total</th>
                    </tr>
                </thead>
                <tbody>
                    <tr><td colspan="15" class="app_line">
                        <h3>Intervenant·e·s {{ unite|upper }}</h3><small>Heures prestées</small></td>
                    </tr>
                    {% for user, detail in intervenants.items %}
                    <tr>
                        <td class="m-0 p-1">{{ user|nom_prenom_abreg }}</td>
                        {% for h in detail.heures_prestees %}
                        <td class="m-0 p-1 num">{{ h|format_duree|default_if_zero }}</td>
                        {% endfor %}
                        <td class="m-0 p-1 num">{{ detail.tot_prestees|format_duree }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
                <!-- Résumé par type de prestation -->
                <thead class="table-light">
                    <tr>
                        <th></th>
                        {% for month in months %}
                        <th class="month">{{ month|date:"N" }}</th>
                        {% endfor %}
                        <th class="total">Total</th>
                    </tr>
                </thead>

                <tbody>
                    {% for libelle in libelles_prest %}
                    <tr {% if forloop.first %}class="first"{% endif %}>
                        <td class="m-0 p-1">{{ libelle.nom }}</td>
                        {% for month, data in totaux_prest_mensuels.items %}
                        <td class="m-0 p-1 num">{% if month.is_future %}-{% else %}{{ data|get_item:libelle.nom|format_duree }}{% endif %}</td>
                        {% endfor %}
                        <td class="m-0 p-1 num">{{ totaux_par_prest|get_item:libelle.nom|format_duree }}</td>
                    </tr>
                    {% endfor %}
                    <tr class="first">
                        <td class="m-0 p-1">Totaux</td>
                        {% for month, data in totaux_prest_mensuels.items %}
                        <td class="m-0 p-1 num">{{ data.total|format_duree }}</td>
                        {% endfor %}
                        <td class="m-0 p-1 num">{{ total_gen|format_duree }}</td>
                    </tr>
                </tbody>
            </table>
            <div class="text-end">
                <a href=".?{% param_replace %}&export=1"><img class="icon-ui" src="{% static 'ficons/xlsx.svg' %}"></a>
            </div>
        </div>
    </div>
{% endblock %}
