{% extends "conversation/conversation_base.html" %}
{% load i18n conversation_tags %}

{% block head_title %}
    {% chain_user_names object.users.all request.user as user_names %}
    {% if object.pk %}{{ user_names }}{% else %}{% trans "New conversation" %}{% endif %}
{% endblock %}

{% block content %}
{% if object.pk %}
    {% chain_user_names object.users.all request.user 200 as user_names %}
    <form class="pull-right" method="post" action="{% url "conversation_trigger" pk=conversation.pk action='archive' %}">
        {% csrf_token %}
        <div class="btn-group">
            <button type="submit" class="btn btn-default" {% if request.user in conversation.archived_by.all %}disabled{% endif %}>{% trans "Archive" %}</button>
            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <span class="caret"></span>
                <span class="sr-only">Toggle Dropdown</span>
            </button>
            <ul class="dropdown-menu">
                {% if request.user not in conversation.unread_by.all %}
                    <li data-class="conversation-link-parent">
                        <a data-class="conversation-link" href="{% url "conversation_trigger" pk=conversation.pk action='mark-as-unread' %}">{% trans "Mark us unread" %}</a>
                    </li>
                {% endif %}
                {% for user in object.users.all %}
                    {% if user != request.user %}
                        {% is_blocked request.user user as user_is_blocked %}
                        <li><a href="{% url "conversation_block_user" user_pk=user.pk %}">{% if user_is_blocked %}{% trans "Unblock" %}{% else %}{% trans "Block" %}{% endif %} {{ user }}</a></li>
                    {% endif %}
                {% endfor %}
            </ul>
        </div>
    </form>
    <h3 style="margin-top: 0px;">{{ user_names }}</h3>
{% endif %}
<ul id="conversation-messages" class="list-group">
    {% for message in object.messages.all %}
        <li class="list-group-item">
            <strong>{{ message.user }}</strong>
            <small class="pull-right text-muted">{{ message.date|date:"SHORT_DATETIME_FORMAT" }}</small>
            <div class="clearfix"></div>
            {{ message.text|linebreaks }}
            {% if message.attachment %}
                <a href="{{ message.attachment.url }}" target="_blank"><span class="glyphicon glyphicon-file"></span> {{ message.filename }}</a>
            {% endif %}
        </li>
    {% endfor %}
</ul>
{% include "django_libs/partials/form_non_field_errors.html" %}
{% if form.blocked_users %}
    <p class="alert alert-danger">{% trans "This conversation has been blocked." %}</p>
{% else %}
    <form method="post" action="." enctype="multipart/form-data">
        {% csrf_token %}
        {% for field in form %}
            {% include "django_libs/partials/form_field.html" with hide_label=1 %}
        {% endfor %}
        <input type="submit" class="btn btn-primary" value="{% trans "Send" %}" />
    </form>
{% endif %}
{% endblock %}
