{% extends "misago/admin/generic/list.html" %}
{% load i18n misago_admin_form misago_capture %}


{% block table-header %}
<th style="width: 1px;">&nbsp;</th>
<th>{% trans "Attachment" %}</th>
<th style="width: 40%;">{% trans "Thread" %}</th>
<th style="width: 1px;">&nbsp;</th>
{% endblock table-header %}


{% block table-row %}
{% if item.is_image %}
  <td class="pr-0">
    {% if item.thumbnail %}
      <a href="{{ item.get_absolute_url }}?shva=1" class="btn btn-thumbnail" style='background-image: url("{{  item.get_thumbnail_url }}?shva=1")' target="_blank"></a>
    {% else %}
      <a href="{{ item.get_absolute_url }}?shva=1" class="btn btn-thumbnail" style='background-image: url("{{  item.get_absolute_url }}?shva=1")' target="_blank"></a>
    {% endif %}
  </td>
{% else %}
  <td class="pr-0 text-center">
    <a href="{{ item.get_absolute_url }}?shva=1" class="btn btn-light btn-block btn-sm" target="_blank">
      <span class="far fa-file"></span>
    </a>
  </td>
{% endif %}
<td>
  <div class="small">
    <a href="{{ item.get_absolute_url }}?shva=1" class="item-name" target="_blank">
      {{ item }}
    </a>
  </div>
  <div class="small text-muted">
    {% capture trimmed as uploader %}
      {% if item.uploader %}
        <a href="{{ item.uploader.get_absolute_url }}" class="item-title">{{ item.uploader }}</a>
      {% else %}
        <span class="item-title">{{ item.uploader_name }}</span>
      {% endif %}
    {% endcapture %}
    {% capture trimmed as uploaded_on %}
      <abbr data-timestamp="{{ item.uploaded_on.isoformat }}" data-format="LL">
        {{ item.uploaded_on }}
      </abbr>
    {% endcapture %}
    {% blocktrans trimmed with filetype=item.filetype size=item.size|filesizeformat uploader=uploader|safe uploaded_on=uploaded_on|safe %}
      {{ filetype }}, {{ size }}, uploaded by {{ uploader }} {{ uploaded_on }}.
    {% endblocktrans %}
  </div>
</td>
<td class="small">
  {% if item.post %}
    <a href="{{ item.post.get_absolute_url }}" class="item-name">
      {{ item.post.thread }}
    </a>
  {% else %}
    <em class="text-muted">{% trans "None" %}</em>
  {% endif %}
</td>
<td>
  <form action="{% url 'misago:admin:attachments:delete' pk=item.pk %}" method="post" data-delete-confirmation="true">
    {% csrf_token %}
    <button class="btn btn-light btn-sm">
      {% trans "Delete" %}
    </button>
  </form>
</td>
{% endblock table-row %}


{% block blankslate %}
<td colspan="5">
  {% if active_filters %}
    {% trans "No attachments matching criteria exist." %}
  {% else %}
    {% trans "No attachments exist." %}
  {% endif %}
</td>
{% endblock blankslate %}


{% block filters-modal-body %}
<div class="row">
  <div class="col">
    {% form_row filter_form.uploader %}
  </div>
</div>
<div class="row">
  <div class="col">
    {% form_row filter_form.filename %}
  </div>
</div>
<div class="row">
  <div class="col">
    {% form_row filter_form.filetype %}
  </div>
</div>
<div class="row">
  <div class="col">
    {% form_row filter_form.is_orphan %}
  </div>
</div>
{% endblock filters-modal-body %}


{% block javascripts %}
{{ block.super }}
<script type="text/javascript">
  window.misago.initConfirmation(
    "[data-delete-confirmation]",
    "{% trans 'Are you sure you want to delete this attachment?' %}"
  )
</script>
{% endblock %}
