{#
    Displays a list of files.

    files       - A list of files to display.
    owner_type  - type of the files owner
    owner_id    - ID of the files owner

    Example:

    {% snippet 'files/snippets/file_table.html', files=files %}

    #}
{% set columns = [
    {"name": "name", "label": "Name"},
    {"name": "created", "label": "Created"},
    {"name": "storage_data.content_type", "label": "Type"},
    {"name": "storage_data.size", "label": "Size"},
    ] %}

{% set params = request.args %}

{% block file_table %}
    <table class="table table-striped">
        <thead>
            {% block table_header %}
                <tr>
                    {% for column in columns %}
                        <th>
                            {% if params.sort == column.name and params.reverse == 'false' %}
                                {{ _(column.label) }}

                                <i class="fa fa-sort-amount-desc"></i>
                            {% else %}
                                <a href="{{ h.remove_url_param(['sort', 'reverse'], replace=column.name, alternative_url=request.path) }}&reverse=false">
                                    {{ _(column.label) }}
                                </a>
                            {% endif %}

                        </th>
                    {% endfor %}
                    <th>{{ _("Actions") }}</th>
                </tr>
            {% endblock table_header %}
        </thead>

        <tbody>
            {% for file in files %}

                {% block table_row scoped %}
                    <tr class="file-item">
                        <td>
                            {{ file.name }}
                        </td>
                        <td>
                            {% with created = h.files_parse_tz_date(file.created) %}
                                <div class="file-item__creation-time">
                                    {{ h.render_datetime(created, with_hours=True) }}
                                </div>

                            {% endwith %}

                        </td>
                        <td>
                            {% set content_type = file.content_type %}
                            <div data-content-type="{{ content_type }}" class="file-item__type" aria-label="{{ content_type }}">
                                {% set icon_path = h.files_content_type_icon(content_type, "amy-dark", "svg") %}
                                {% if icon_path %}
                                    <img alt="type icon" src="{{ icon_path }}"/>
                                {% endif %}

                                {{ _(h.files_humanize_content_type(content_type)) }}
                            </div>
                        </td>
                        <td>
                            {{ h.localised_filesize(file.size) }}
                        </td>
                        <td>
                            {% block file_actions %}
                                {% block action_public_link %}
                                    {% set public_link = h.files_link_details(file.id, "permanent") %}
                                    {% if public_link %}
                                        <a class="btn btn-default btn-sm" aria-label="Copy file link"
                                            data-module="copy-into-buffer"
                                            data-module-copy-value="{{ public_link.href }}">
                                            <i class="fas fa-copy"></i>
                                        </a>
                                    {% endif %}
                                {% endblock action_public_link %}

                                {% block action_download %}
                                    {% if h.check_access("files_permission_download_file", {"id": file.id}) %}
                                        <a class="btn btn-default btn-sm" aria-label="Download the file" download
                                            href="{{ h.url_for('files.dispatch_download', file_id=file.id) }}">
                                            <i class="fa fa-download"></i>
                                        </a>
                                    {% endif %}
                                {% endblock action_download %}

                                {% block action_remove %}
                                    {% if h.check_access("files_permission_download_file", {"id": file.id}) %}
                                        <a class="btn btn-danger btn-sm" aria-label="Remove the file"
                                            href="{{ h.url_for('files.delete_file',
                                                      file_id=file.id,
                                                      came_from=request.path, owner_type=owner_type, owner_id=owner_id) }}">
                                            <i class="fa fa-remove"></i>
                                        </a>
                                    {% endif %}
                                {% endblock action_remove %}

                            {% endblock %}
                        </td>
                    </tr>
                {% endblock table_row %}

	        {% endfor %}
        </tbody>
    </table>
{% endblock %}
