{% load i18n static admin_soft %}

{% if result_hidden_fields %}
    <div class="hiddenfields">{# DIV for HTML validation #}
        {% for item in result_hidden_fields %}{{ item }}{% endfor %}
    </div>
{% endif %}

{% if results %}

    <table class="table table-hover">
        <thead>
        <tr>
            {% for header in result_headers %}
                <th class="border-gray-200" {{ header.class_attrib }}>
                    {% if header.sortable %}
                        {% if header.sort_priority > 0 %}
                            <a href="{{ header.url_remove }}" title="{% trans "Remove from sorting" %}"><span class="fa fa-arrows-alt"></span></a>&nbsp;
                            {% if num_sorted_fields > 1 %}
                                <span class="fa fa-arrows-v" title="{% blocktrans with priority_number=header.sort_priority %}Sorting priority: {{ priority_number }}{% endblocktrans %}">{{ header.sort_priority }}</span>&nbsp;
                            {% endif %}
                            <a href="{{ header.url_toggle }}" class="fa {% if header.ascending %}fa-angle-up{% else %}fa-angle-down{% endif %}" title="{% trans "Toggle sorting" %}"></a>&nbsp;&nbsp;
                        {% endif %}
                    {% endif %}

                    {% if header.sortable %}
                        <a href="{{ header.url_primary }}">{{ header.text|capfirst }}</a>
                    {% else %}
                        {% if header.class_attrib == ' class="action-checkbox-column"' %}
                            <div class="form-check">
                                <label class="form-check-label">
                                    {{ header.text|capfirst }}
                                </label>
                            </div>
                        {% else %}
                            <span>{{ header.text|capfirst }}</span>
                        {% endif %}
                    {% endif %}
                </th>
            {% endfor %}
        </tr>
        </thead>
        <tbody>
        {% for result in results %}
            {% if result.form and result.form.non_field_errors %}
                <tr><td colspan="{{ result|length }}">{{ result.form.non_field_errors }}</td></tr>
            {% endif %}
            <tr>
                {% for item in result %}
                    {% if 'checkbox' in item %}
                        <td>
                            <div class="form-check">
                                <label class="form-check-label">
                                    {{ item|checkbox|safe }}
                                    <span class="form-check-sign"><span class="check"></span></span>
                                </label>
                            </div>
                        </td>
                    {% else %}
                        <span class="fw-normal">{{ item }}</span>
                    {% endif %}
                {% endfor %}
            </tr>
        {% endfor %}
        </tbody>
    </table>
{% endif %}

