{% extends "base.html" %}

{% block boutons_droite %}
    {% if famille %}
        {% include './famille_boutons.html' with active='prestation' %}
    {% endif %}
{% endblock %}

{% block content %}
    <div class="row border-bottom lead mt-3 mb-3">
        {% if famille %}
            <div class="col">Famille {{ famille.nom }} - {{ famille.adresse }}</div>
            <div class="col text-end d-flex flex-column justify-content-end">
                <a class="btn btn-primary btn-sm ms-3 mb-2 align-self-end" href="{% url 'prestation-famille-add' famille.pk %}">
                    Ajouter
                </a>
                {% if filter_form %}<form class="filter-form d-flex flex-column" method="get">{{ filter_form.as_div }}</form>{% endif %}
            </div>
        {% else %}
            <div class="col">Mes prestations générales</div>
            <div class="col text-end">
                <a class="btn btn-primary btn-sm mb-2" href="{% url 'prestation-gen-add' %}">
                    Ajouter
                </a>
            </div>
        {% endif %}
    </div>
    <div class="row">
        <div class="col">
            <table class="table table-sm">
                <thead class="table-light">
                    <tr>
                        <th>Date</th>
                        <th>Durée</th>
                        <th>Interv.</th>
                        <th>Contenu</th>
                        <th>Auteur</th>
                        <th>Prest.</th>
                        <th align="center">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for prestation in prestations %}
                        <tr>
                            <td>{{ prestation.date_prestation|date:"d.m.Y" }}</td>
                            <td>{{ prestation.duree|strip_seconds }}</td>
                            <td>{{ prestation|sigles_intervenants }}</td>
                            <td>{{ prestation.texte|truncate_html_with_more:40 }} {{ prestation.fichier|as_icon }}</td>
                            <td>{{ prestation.auteur|sigle_personne }}</td>
                            <td>{{ prestation.lib_prestation.nom }}</td>
                            <td align="center">
                                {% with fam_pk=famille.pk|default:0 %}
                                    {% if prestation|can_edit:user %}
                                        <a href="{% url 'prestation-edit' fam_pk prestation.pk %}">
                                            <img src="{% static 'admin/img/icon-changelink.svg' %}">
                                        </a>
                                    {% endif %}
                                {% endwith %}
                            </td>
                        </tr>
                    {% empty %}
                        <tr><td colspan="5" align="center">
                            {% if filter_form.cleaned_data.recherche or filter_form.cleaned_data.famille %}
                                Pas de résultat pour votre recherche.
                            {% else %}
                                Aucune prestation saisie
                            {% endif %}
                        </td></tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}
