{% load widget_tweaks %}

{% load i18n staticfiles arctic_tags %}

    <div class="row">
        {% if has_filter %}
            <form action="" method="GET" class="columns expand">
                <fieldset type="get">
                    <div class="page-filters row">
                        {% include "arctic/partials/form_fields_inline.html" with form=filter.form hide_label=True %}
                        <div class="columns shrink left">
                            <button type="submit" class="button secondary">
                                <i class="fa fa-search"></i>
                            </button>
                        </div>
                    </div>
                </fieldset>
            </form>
        {% endif %}
        {% if tool_links %}
            <div class="columns {% if has_filter %}shrink{% endif %}">
                {% if tool_links|length > 1 %}
                    <button class="button secondary float-right" type="button" data-toggle="tool-links"><i class="fa {{ tool_links_icon }}"></i></button>
                        <div class="dropdown-pane bottom" id="tool-links" data-dropdown data-close-on-click="true">
                            <ul>
                                {% for link in tool_links %}
                                    <li><a href="{% url link.url %}">{{ link.label }}</a></li>
                                {% endfor %}
                            </ul>
                        </div>
                {% else %}
                    <a class="button secondary" title="{{ tool_links.0.label }}" href="{% url tool_links.0.url %}"><i class="fa {% if tool_links.0.icon %}{{ tool_links.0.icon }}{% else %}{{ tool_links_icon }}{% endif %}"></i></a>
                {% endif %}
            </div>
        {% endif %}
    </div>

    <div class="row">
    {# data table #}
    {% if list_items %}
        <div class="small-12 columns">
            <div class="table-scroll">
            <table class="table">
                <thead>
                    <tr>
                        {% for item in list_header %}
                            <th>
                                {% if item.order_url %}
                                    <a href="{{ item.order_url }}">{{ item.label }}
                                        {% if item.order_direction == 'desc' %}
                                            <i class="fa fa-sort-desc"></i>
                                        {% elif item.order_direction == 'asc' %}
                                            <i class="fa fa-sort-asc"></i>
                                        {% else %}
                                            <i class="fa fa-sort"></i>
                                        {% endif %}</a>
                                {% else %}
                                    {{ item.label }}
                                {% endif %}
                            </th>
                        {% endfor %}

                        {% if action_links %}
                            <th class="highlight-background">{% trans "Actions" %}</th>
                        {% endif %}
                    </tr>
                </thead>
                <tbody>
                    {% for row in list_items %}
                        <tr>
                            {% for column in row|slice:"1:" %}
                                <td {% if column.class %}class="{{ column.class }}"{%endif%}>
                                    {% if column.url %}
                                        <a href="{{ column.url }}">
                                    {% endif %}
                                    {% if column.value|typename != 'list' %}
                                        {{ column.value|default_if_none:"" }}
                                    {% else %}
                                        {% for item in column.value %}
                                            <span class="badge highlight-background">{{ item }}</span>
                                        {% endfor %}
                                    {% endif %}
                                    {% if column.url %}
                                        </a>
                                    {% endif %}
                                </td>
                            {% endfor %}

                            {% if action_links %}
                                <td class="actions">
                                    {% for link in action_links %}
                                        <a href="{% url link.url row.0 %}" class="action-{{ link.label }}" title="{{ link.label|capfirst }}">
                                            {% if link.icon %}
                                                <i class="fa {{ link.icon }} fa-lg"></i>
                                            {% else %}
                                                {{ link.label|capfirst }}
                                            {% endif %}
                                        </a>
                                        &nbsp;
                                    {% endfor %}
                                </td>
                            {% endif %}
                        </tr>
                    {% endfor %}
                </tbody>
            </table>

            </div> {# table-scroll #}
        </div> {# small-12 columns #}
    </div> {# row #}
    {% block pagination %}
        {% with page_obj=page_obj paginator=page_obj.paginator %}
            {% include "arctic/partials/pagination.html" %}
        {% endwith %}
    {% endblock %}
{% endif %}
