{% load i18n static %}
{% load admin_black %}

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

{% if results %}
    <div class="table-responsive" style="overflow: hidden;">
        <table class="table tablesorter {{ direction.panel }}">
            <thead class="text-primary">
            <tr>
                {% for header in result_headers %}
                    <th scope="col" {{ header.class_attrib }}>
                        <div class="text">
                            {% 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 }}
                                            <span class="form-check-sign"><span class="check"></span></span>
                                        </label>
                                    </div>
                                {% else %}
                                    <span>{{ header.text|capfirst }}</span>
                                {% endif %}
                            {% endif %}
                        </div>
                    </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 class="{% cycle 'row1' 'row2' %}">
                    {% for item in result %}
                        {% if 'checkbox' in item %}
                            <td class="action-checkbox">
                                <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 %}
                            {{ item }}
                        {% endif %}
                    {% endfor %}
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
{% endif %}

