{% extends "dictionary/conversation/inbox_base.html" %}
{% load humanize i18n %}

{% block title %}{% trans "messages" context "titleblock" %}{% endblock %}

{% block titlemeta %}
    {% if request.GET.search_term.strip %}
        <span class="ml-2">[{% trans "search keywords" %}: <strong>{{ request.GET.search_term.strip }}</strong>]</span>
    {% endif %}
{% endblock %}

{% block innercontent %}
    {% if conversations %}
        <ul class="threads" data-mode="present">
            {% for chat in conversations %}
                {% with lastmsg=chat.messages.latest %}
                    <li class="chat{% if lastmsg.recipient == user and not lastmsg.read_at %} unread{% endif %}" data-id="{{ chat.pk }}">
                        <a href="{{ chat.get_absolute_url }}">
                            <header class="d-flex justify-content-between">
                                <h2 class="h5">{{ chat.target.username }} {% if chat.unread_count > 0 %}({{ chat.unread_count }}){% endif %}</h2>
                                <div class="custom-control custom-checkbox">
                                    <input type="checkbox" class="chat-selector custom-control-input" id="_cvs{{ chat.pk }}">
                                    <label class="text-hide custom-control-label" for="_cvs{{ chat.pk }}">{% trans "select" %}</label>
                                </div>
                            </header>
                            <p>{{ lastmsg.body|default:_("<em>no messages</em>")|truncatechars:225 }}</p>
                        </a>

                        <footer class="d-flex justify-content-between fs-90">
                            <div>
                                <a role="button" tabindex="0" class="chat-delete-individual mr-1">{% trans "delete" %}</a>
                                {% if lastmsg %}
                                    <a role="button" tabindex="0" class="chat-archive-individual">{% trans "archive" context "verb" %}</a>
                                {% endif %}
                            </div>
                            {% if lastmsg %}
                                <time>{{ lastmsg.sent_at|naturaltime }}</time>
                            {% endif %}
                        </footer>
                    </li>
                {% endwith %}
            {% endfor %}
        </ul>
    {% else %}
        <div class="border rounded p-3 bg-light">{% trans "sorry, but couldn't find anything 🤷" %}</div>
    {% endif %}
{% endblock %}
