{% extends "orga/mails/base.html" %}
{% load i18n %}
{% load url_replace %}

{% block mail_content %}
    <h2>
        <span>
            {{ page_obj.paginator.count }}
            {% blocktrans trimmed count count=page_obj.paginator.count %}
                pending mail
            {% plural %}
                pending mails
            {% endblocktrans %}
        </span>
    </h2>
    <div class="submit-group">
        <span>
            {% include "common/search_form.html" %}
        </span>
        <span>
            <a href="{{ request.event.orga_urls.send_outbox }}">
                <button class="btn btn-lg btn-success">{% trans "Send all" %}</button>
            </a>
            <a href="{{ request.event.orga_urls.purge_outbox }}">
                <button class="btn btn-lg btn-danger">{% trans "Discard all" %}</button>
            </a>
        </span>
    </div>
    <table class="table table-sm table-hover table-responsive-md">
        <thead>
            <tr>
                <th>
                    {% trans "Subject" %}
                    <a href="?{% url_replace request 'sort' 'subject' %}"><i class="fa fa-caret-down" title="{% trans "Sort by subject (a-z)" %}"></i></a>
                    <a href="?{% url_replace request 'sort' '-subject' %}"><i class="fa fa-caret-up" title="{% trans "Sort by subject (z-a)" %}"></i></a>
                </th>
                <th>
                    {% trans "To" %}
                    <a href="?{% url_replace request 'sort' 'to' %}"><i class="fa fa-caret-down" title="{% trans "Sort by recipient (a-z)" %}"></i></a>
                    <a href="?{% url_replace request 'sort' '-to' %}"><i class="fa fa-caret-up" title="{% trans "Sort by recipient (z-a)" %}"></i></a>
                </th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            {% for mail in mails %}
            <tr>
                <td>
                    <a href="{{ mail.urls.base }}">
                        {{ mail.subject }}
                    </a>
                </td>
                <td>
                    {% for user in mail.to_users.all %}
                    {% if user in request.event.submitters %}
                        <a href="{% url "orga:speakers.view" event=request.event.slug pk=user.pk %}">
                            {{ user }}
                        </a>{% else %}{{ user }}{% endif %}{% if not forloop.last or mail.to %}, {% endif %}
                    {% endfor %}
                    {% if mail.to %}
                    {{ mail.to }}
                    {% endif %}
                </td>
                <td class="action-column">
                    <a href="{{ mail.urls.send }}"
                        title="{% trans "send" %}"
                        class="btn btn-sm btn-success">
                        <i class="fa fa-mail-forward"></i>
                    </a>
                    <a href="{{ mail.urls.edit }}"
                        title="{% trans "edit" %}"
                        class="btn btn-sm btn-info">
                        <i class="fa fa-edit"></i>
                    </a>
                    <a href="{{ mail.urls.delete }}"
                        title="{% trans "delete" %}"
                        class="btn btn-sm btn-danger">
                        <i class="fa fa-trash"></i>
                    </a>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    {% include "orga/pagination.html" %}
{% endblock %}
