{% extends "docbow/base_user.html" %}
{% load i18n %}
{% load docbow %}
{% load humanize %}

{% block title %}
  {% include "docbow/message_title.html" %}
{% endblock %}

{% block extra_scripts %}
  {{ form.media }}
{% endblock %}

{% block main-column %}
  <h3>{% include "docbow/message_title.html" %}</h3>

  <div id="download-buttons">
    {% for kind, files in attached_files %}
      <span>{{ kind.name }}</span>
      {% for file in files %}
        <h4 class="download-button">
          <a title="{{file.name}}" href="{{file.pk}}/{{file.name}}">
            {% trans "Download" %}
            <span class="file-size">({{file.content.size|frfilesizeformat}})</span>
            <div class="filename">{{file.ellipsed_name}}</div>
          </a>
        </h4>
      {% endfor %}
    {% endfor %}
    {% if document.has_zip_download %}
      <h4 id="zip-download" class="download-button">
        <a title="documents.zip" href="allfiles/" download>
          {% trans "Download every file" %}
        </a>
      </h4>
    {% endif %}
  </div>

  <h4 id="to-header">{% trans "To" %}:</h4>
  <div id="to">
  <!-- Only recipient users which has a visibility on are shown -->
    {% for recipient_user in document.delivered_to %}
      {% if outbox or recipient_user in related_users %}
        <span>{{ recipient_user|username }}</span>
      {% endif %}
    {% endfor %}
  <!-- All recipient list are shown -->
    {% for recipient_list in document.group_human_to %}
      <span>{{ recipient_list }}</span>
    {% endfor %}
  </div>
  <h4 id="comment-header">{% trans "Comment" %}:</h4>
  <p id="comment">{{ document.comment }}</p>
  {% if view_name == 'inbox' %}
    <div class="form">
      <form action="{% url 'send-file-selector' %}" class="uniForm">
        <input type="hidden" name="reply_to" value="{{ document.pk }}"/>
        <div class="buttonHolder">
          <input type="submit" class="submit submitButton" value="{% trans "Reply" %}"/>
        </div>
      </form>
    </div>
  {% endif %}
  {% if form %}
    {% if document.document_forwarded_to.all %}
      <h4 id="forwarded-header">{% trans "Forwarded to" %}</h4>
      <div id="forwarded">
        <ul>
          {% for document_forwarded in document.document_forwarded_to.all %}
            {% with document_forwarded=document_forwarded.to_document %}
              <li>{{document_forwarded.recipients}}
                {% with date=document_forwarded.date|date:"SHORT_DATE_FORMAT" sender=document_forwarded.sender|username time=document_forwarded.date|time:"H:i" %}
                  {% if document_forwarded.automatic %}
                    {% blocktrans %}on {{date}} at {{time}} automatically{% endblocktrans %}
                  {% else %}
                    {% blocktrans %}on {{date}} at {{time}} by {{sender}}{% endblocktrans %}
                  {% endif %}
                {% endwith %}
              </li>

            {% endwith %}
          {% endfor %}
        </ul>
      </div>
    {% endif %}
    <br class="clear"/>
    <div class="forward-form">
      <h3>Transférer le document à&nbsp;:</h3>
      <div class="form">
        <form class="uniForm" method="post">
          {% csrf_token %}
          {% include "docbow/errors.html" with error_form=form %}

          {% if form.sender %}
            {% include "docbow/field.html" with field=form.sender %}
          {% endif %}

          {% include "docbow/field.html" with field=form.recipients %}

          <div class="buttonHolder">
            <input name="forward" value="{% trans 'forward the document' %}" class="submit submitButton" id="submit-id-forward" type="submit">
          </div>

        </form>
      </div>
    </div>
  {% endif %}
{% endblock %}
