{% extends "postman/base.html" %}
{% load i18n postman_tags allauth df_site pagination_tags django_bootstrap5 %}{% comment %}
WARNING: 'pagination_tags' is a name from the dj-pagination application.
For convenience, the design of this template is done with the use of that application.
Django-postman will still be working, even if that application is not installed, by providing a mock
for the template tag library.
If the real implementation is to be used, just make sure that 'dj_pagination' is declared before 'postman'
in the INSTALLED_APPS setting.
{% endcomment %}
{% block content %}
<div id="postman">
<h1 class="card-header text-center">{% block pm_folder_title %}{% endblock %}</h1>

{% if invalid_page %}
<p class="alert alert-danger">{% trans "Sorry, this page number is invalid." %}</p>
{% else %}
{% if pm_messages %}
{% block pm_by_modes %}<ul id="pm_byModes" class="nav justify-content-center">
    <li class="pm_by-mode nav-item"><a class="nav-link{% if by_conversation %} active disabled{% else %}{% endif %}" href="{{ by_conversation_url }}">{% trans "by conversation" %}</a></li>
    <li class="pm_by-mode nav-item"><a class="nav-link{% if by_message %} active disabled{% else %}{% endif %}" href="{{ by_message_url }}">{% trans "by message" %}</a></li>
</ul>
{% endblock pm_by_modes %}
<form class="card-body" action="{% block pm_form_action %}{% url 'postman:update-message' %}{% endblock %}" method="post">{% csrf_token %}

    {% block pm_form_buttons %}<div id="pm_buttons" class="btn-group">
{% block pm_delete_button %}<button name="action" value="delete" type="submit" class="btn btn-sm btn-danger pm_btn pm_btn-delete" >{% trans "Delete" %}</button>{% endblock %}
{% block pm_archive_button %}<button name="action" value="archive" type="submit" class="btn btn-sm btn-primary pm_btn pm_btn-archive" >{% trans "Archive" %}</button>{% endblock %}
{% block pm_undelete_button %}<button name="action" value="undelete" type="submit" class="btn btn-sm btn-primary pm_btn pm_btn-undelete" >{% trans "Undelete" %}</button>{% endblock %}
{% block pm_read_button %}<button name="action" value="read" type="submit" class="btn btn-sm btn-primary pm_btn pm_btn-read" >{% trans "Mark as read" %}</button>{% endblock %}
{% block pm_unread_button %}<button name="action" value="unread" type="submit" class="btn btn-sm btn-primary pm_btn pm_btn-unread" >{% trans "Mark as unread" %}</button>{% endblock %}
</div>{% endblock %}
<table id="pm_messages" class="table table-striped table-hover">
 <thead>
  <tr>
   <th>{% trans "Action" %}</th>
{% block pm_sender_header %}   <th><a class="d-block nav-link" href="{% postman_order_by sender %}">{% trans "Sender" %} <span class="float-end">{% fa6_icon 'sort' %}</span></a></th>{% endblock %}
{% block pm_recipient_header %}   <th><a class="d-block nav-link" href="{% postman_order_by recipient %}">{% trans "Recipient" %} <span class="float-end">{% fa6_icon 'sort' %}</span></a></th>{% endblock %}
   <th><a class="d-block nav-link" href="{% postman_order_by subject %}">{% trans "Subject" %} <span class="float-end">{% fa6_icon 'sort' %}</span></a></th>
   <th><a class="d-block nav-link" href="{% postman_order_by date %}">{% block pm_date %}{% trans "Date" %}{% endblock %} <span class="float-end">{% fa6_icon 'sort' %}</span></a></th>
  </tr>
 </thead>
{% paginate_qs pm_messages per_page=10 as pm_messages_p %}
 <tbody>{% for message in pm_messages_p %}
  <tr>
   <td><input type="checkbox" {% if by_conversation and message.thread_id %}name="tpks" value="{{ message.thread_id }}"{% else %}name="pks" value="{{ message.pk }}"{% endif %}></td>
{% block pm_sender_cell %}   <td>{{ message.obfuscated_sender|or_me:user }}{% if message.count %} ({{ message.count }}){% endif %}</td>{% endblock %}
{% block pm_recipient_cell %}   <td>{{ message.obfuscated_recipient|or_me:user }}{% if message.count %} ({{ message.count }}){% endif %}</td>{% endblock %}
   <td>{% if message.is_new %}<strong>{% endif %}{% if message.is_replied %}<em>{% endif %}
{% block pm_subject %}
    <a href="{% if by_conversation and message.thread_id %}{% url 'postman:view_conversation' message.thread_id %}{% else %}{% url 'postman:view' message.pk %}{% endif %}?next={{ current_url|urlencode }}">
    {% include "postman/inc_subject_ex.html" %}
    </a>
    {% if message.body %}<div class="text-body-tertiary">{{ message.body|truncatewords_html:7|safe }}</div>{% endif %}
{% endblock %}
   {% if message.is_replied %}</em>{% endif %}{% if message.is_new %}</strong>{% endif %}</td>
   <td>{{ message.sent_at|compact_date:_("g:i A,M j,n/j/y") }}</td>
  </tr>{% endfor %}
 </tbody>
</table>
{% bootstrap_pagination pm_messages_p size='sm' justify_content='center' %}

</form>
{% else %}
    {% element p %}
        {% trans "No messages." %}
    {% endelement %}
{% endif %}
{% endif %}
{% block pm_footer_info %}{% endblock %}
</div>
{% endblock content %}
