{% load i18n staticfiles arctic_tags %}

<div class="row">
    {% block tool_links %}
        <div class="col">
            {% if tool_links %}
                <div class="form-group">
                {% if tool_links|length > 1 %}
                    <button class="btn btn-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="btn btn-secondary" title="{{ tool_links.0.label }}" href="{% url tool_links.0.url %}"><i title="{{ tool_links.0.label }}" class="fa {% if tool_links.0.icon %}{{ tool_links.0.icon }}{% else %}{{ tool_links_icon }}{% endif %}"></i></a>
                {% endif %}
                </div>
            {% endif %}
        </div>
    {% endblock %}
    {% if simple_search_form or advanced_search_form %}
        <form action="" method="GET" class="col-12 col-md-6 push-right list-inline-search">
            {% block search_form %}
            <fieldset type="get" id="arctic_search_form">
                <div class="page-filters row">
                    <div class="col">
                        <label class="sr-only" for="search">Search</label>
                        <div class="input-group mb-2 mr-sm-2 mb-sm-0">
                            {% if advanced_search_form %}
                                <a class="input-group-addon arctic_toggle_form_button" tabindex="0" data-toggle="popover" data-placement="bottom" data-container="#arctic_search_form" data-popover_content_container="#arctic_advanced_search">
                                    <i class="fa fa-sliders"></i>
                                </a>
                            {% endif %}
                            <input type="text" class="form-control" id="search" placeholder="{% trans 'Search' %}" value="{{ simple_search_form.search.value|default:"" }}" name="search">
                            <div class="input-group-addon" js-search-submit><i class="fa fa-search"></i></div>
                        </div>
                        {% if advanced_search_form %}
                            {% block advanced_search_form %}
                                <div class="artic_toggle_form hidden" id="arctic_advanced_search" hidden>
                                    {% include "arctic/partials/form_fields.html" with form=advanced_search_form %}
                                    <div class="form-block">
                                        <input type="submit" value="{% trans 'Search' %}" class="btn btn-primary">
                                    </div>
                                </div>
                            {% endblock %}
                        {% endif %}
                    </div>
                </div>
            </fieldset>
            {% endblock %}
        </form>
    {% endif %}
</div>

{% block table %}
<div class="row">
    {# data table #}
    {% if list_items %}
        <div class="col-sm-12 col">
            <div class="arctic-card">
                {% if list_summary %}
                    <div class="arctic-card__header">
                        <h4 class="arctic-card__title">
                            {{ page_title }}
                        </h4>
                    </div>
                {% endif %}
                <div class="table-responsive">
                    <table class="table table-striped table-hover">
                        <thead>
                            <tr>
                                {% for item in list_header %}
                                    <th>
                                        {% if item.order_url %}
                                            <a href="{{ item.order_url }}">{{ item.label }}&nbsp;
                                                {% 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 show-on-hover"></i>
                                                {% endif %}</a>
                                        {% else %}
                                            {{ item.label }}
                                        {% endif %}
                                        {% block extra_table_header_data %}{% endblock %}
                                    </th>
                                {% endfor %}

                                {% if has_action_links %}
                                    <th>&nbsp;</th>
                                {% endif %}
                            </tr>
                        </thead>
                        <tbody>
                            {% for row in list_items %}
                                <tr>
                                    {% for column in row %}
                                        {% if column.type == 'field' %}
                                            <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="list-tag">{{ item }}</span>
                                                    {% endfor %}
                                                {% endif %}
                                                {% if column.url %}
                                                    </a>
                                                {% endif %}
                                            </td>
                                        {% elif column.type == 'actions' %}
                                            <td>
                                            <div class="list-actions">
                                                {% for link in column.actions %}
                                                    <a href="{{ link.url }}" class="action-{{ link.label }} btn btn-secondary btn-sm show-on-hover" title="{{ link.label|capfirst }}">
                                                        {% if link.icon %}
                                                            <i class="fa {{ link.icon }} fa-lg"></i>
                                                        {% else %}
                                                            {{ link.label|capfirst }}
                                                        {% endif %}
                                                    </a>
                                                {% endfor %}
                                                <div class="list-actions-placeholder"></div>
                                            </div>
                                            </td>
                                        {% endif %}
                                    {% endfor %}
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
            {% block pagination %}
                {% with page_obj=page_obj paginator=page_obj.paginator %}
                    {% include "arctic/partials/pagination.html" %}
                {% endwith %}
            {% endblock %}
    {% endif %}
    </div>
</div>
{% endblock %}

{% block extra_data %}{% endblock %}
