{% load i18n l10n wagtailadmin_tags %}
<table class="listing">
    <col />
    <col  />
    {% if collections %}
        <col  />
    {% endif %}
    <col width="16%" />
    <thead>
        <tr class="table-headers">
            <th>
                {% if not is_searching %}
                    {% if ordering == "-title" %}
                        <a href="{% url 'wagtailmedia:index' %}?ordering=title" class="icon icon-arrow-up-after teal" data-ordering="title">
                    {% elif ordering == "title" %}
                        <a href="{% url 'wagtailmedia:index' %}?ordering=-title" class="icon icon-arrow-down-after teal" data-ordering="-title">
                    {% else %}{# ordering by created at, so default to title, asc #}
                        <a href="{% url 'wagtailmedia:index' %}?ordering=title" class="icon icon-arrow-down-after" data-ordering="title">
                    {% endif %}
                        {% trans "Title" %}
                    </a>
                {% else %}
                    {% trans "Title" %}
                {% endif %}
            </th>
            <th>{% trans "File" %}</th>
            <th>{% trans "Type" %}</th>
            {% if collections %}
                <th>{% trans "Collection" %}</th>
            {% endif %}
            <th>
                {% if not is_searching %}
                    {% if ordering == "-created_at" %}
                        <a href="{% url 'wagtailmedia:index' %}?ordering=created_at" class="icon icon-arrow-up-after teal" data-ordering="created_at">
                    {% else %}
                        <a href="{% url 'wagtailmedia:index' %}?ordering=-created_at" class="icon icon-arrow-down-after" data-ordering="-created_at">
                    {% endif %}
                        {% trans "Uploaded" %}
                    </a>
                {% else %}
                    {% trans "Uploaded" %}
                {% endif %}
            </th>
        </tr>
    </thead>
    <tbody>
        {% for media_file in media_files %}
            <tr>
                <td id="media_{{ media_file.pk|unlocalize }}_title" class="title">
                    {% if choosing %}
                        <div class="title-wrapper"><a href="{% url 'wagtailmedia:media_chosen' media_file.pk %}" class="media-choice">{{ media_file.title }}</a></div>
                    {% else %}
                        <div class="title-wrapper"><a href="{% url 'wagtailmedia:edit' media_file.id %}">{{ media_file.title }}</a></div>
                    {% endif %}
                </td>
                <td>
                    {% if choosing %}
                        {{ media_file.filename }}
                    {% else %}
                        <a href="{{ media_file.url }}" class="nolink">{{ media_file.filename }}</a>
                    {% endif %}
                </td>
                <td>{{ media_file.get_type_display }}</td>
                {% if collections %}
                    <td>{{ media_file.collection.name }}</td>
                {% endif %}
                <td>{% human_readable_date media_file.created_at %}</td>
            </tr>
        {% endfor %}
    </tbody>
</table>
