{% extends "agenda_culturel/page-admin.html" %}

{% block title %}{% block og_title %}{% if filter.is_contact_messages %}Derniers messages de contact reçus{% else %}Derniers messages{% endif %}{% endblock %}{% endblock %}

{% load utils_extra %}
{% load cat_extra %}
{% block entete_header %}
    {% css_categories %}
{% endblock %}

{% block sidemenu-bouton %}
    <li><a href="#contenu-principal" aria-label="Aller au contenu">{% picto_from_name "chevron-up" %}</a></li>
    <li><a href="#sidebar" aria-label="Aller au menu latéral">{% picto_from_name "chevron-down" %}</a></li>
{% endblock %}

{% block content %}
<div class="grid two-columns">
<article>
    <header>
        {% if nb_spams > 0 and filter.is_contact_messages %}
        <div class="slide-buttons">
            <a href="{% url 'delete_cm_spam' %}" role="button" data-tooltip="Supprimer les spams">Supprimer les spams {% picto_from_name "trash-2" %}</a>
        </div>
        {% endif %}
        {% if filter.is_contact_messages %}
        <h1>Derniers messages de contact reçus</h1>
        {% else %}
        <h1>Derniers messages</h1>
        {% endif %}
        <form method="get" class="form django-form recent messages">
            {{ filter.form.as_div }}<br />
            <button type="submit">Filtrer</button>
        </form>
    </header>

    <table role="grid">
        <thead>
            <tr>
                <th>Date</th>
                <th>Type</th>
                <th>Sujet</th>
                <th>Auteur</th>
                <th>Événement</th>
                <th>Fermé</th>
                <th>Spam</th>
            </tr>
        </thead>
        <tbody>
    {% for obj in paginator_filter %}
        <tr>
            <td>{{ obj.date }}</td>
            <td>{% if obj.message_type %}{{ obj.get_message_type_display }}{% else %}-{% endif %}</td>
            <td><a href="{% url 'message' obj.pk %}">{{ obj.subject }}</a></td>
            <td>{% if obj.user %}<em>{{ obj.user }}</em>{% else %}{% if obj.name %}{{ obj.name }}{% else %}-{% endif %}{% endif %}</td>
            <td>{% if obj.related_event %}<a href="{{ obj.related_event.get_absolute_url }}">{{ obj.related_event.pk }}</a>{% else %}-{% endif %}</td>
            <td>{% if obj.closed %}{% picto_from_name "check-square" "fermé" %}{% else %}{% picto_from_name "square" "ouvert" %}{% endif %}</td>
            <td>{% if obj.spam %}{% picto_from_name "check-square" "spam" %}{% else %}{% picto_from_name "square" "non spam" %}{% endif %}</td>
        </tr>
    {% endfor %}
        </tbody>
    </table>
<footer>
    {% include 'agenda_culturel/paginator_filter.html' %}
</footer>
</article>

{% if filter.is_contact_messages %}
    {% include "agenda_culturel/side-nav.html" with current="contact_messages" %}
{% else %}
    {% include "agenda_culturel/side-nav.html" with current="messages" %}
{% endif %}
</div>

{% endblock %}