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

{% load appearance_tags %}
{% load common_tags %}
{% load navigation_tags %}

<div class="row">
    <div class="col-xs-12">
        {% if not object_list %}
            <div class="well center-block">
                {% include 'appearance/no_results.html' %}
            </div>
        {% else %}
            {% include 'appearance/list_header.html' %}
            {% navigation_resolve_menu name='multi item' sort_results=True source=object_list.0 as links_multi_menus_results %}
            <div class="well center-block">
                <div class="table-responsive">
                    <table class="table table-condensed table-striped">
                        <thead>
                            {% if not hide_header %}
                                <tr>
                                    {% if links_multi_menus_results %}
                                        <th class="first"></th>
                                    {% endif %}

                                    {% if not hide_object %}
                                        <th>{% trans 'Identifier' %}</th>
                                    {% else %}
                                        {% navigation_get_source_columns source=object_list only_identifier=True as source_column %}
                                        {% if source_column %}
                                            <th>
                                                <span style="white-space: nowrap">
                                                    {% if source_column.is_sortable %}
                                                        <a href="{% navigation_get_sort_field_querystring column=source_column %}">{{ source_column.label }}</a>
                                                        {% if source_column.get_sort_field == sort_field %}
                                                            {% if icon_sort %}{{ icon_sort.render }}{% endif %}
                                                        {% endif %}
                                                    {% else %}
                                                        {{ source_column.label }}
                                                    {% endif %}

                                                    {% if source_column.help_text %}
                                                        <span data-toggle="tooltip" data-placement="bottom" title="{{ source_column.help_text }}">
                                                        {% appearance_get_icon icon_path='mayan.apps.navigation.icons.icon_source_column_help_text' %}
                                                        </span>
                                                    {% endif %}
                                                </span>
                                            </th>
                                        {% endif %}
                                    {% endif %}

                                    {% if not hide_columns %}
                                        {% navigation_get_source_columns source=object_list exclude_identifier=True as source_columns %}
                                        {% for source_column in source_columns %}
                                            <th>
                                                <span style="white-space: nowrap">
                                                    {% if source_column.is_sortable %}
                                                        <a href="{% navigation_get_sort_field_querystring column=source_column %}">{{ source_column.label }}</a>
                                                        {% if source_column.get_sort_field == sort_field %}
                                                            {% if icon_sort %}{{ icon_sort.render }}{% endif %}
                                                        {% endif %}
                                                    {% else %}
                                                        {{ source_column.label }}
                                                    {% endif %}

                                                    {% if source_column.help_text %}
                                                        <span data-toggle="tooltip" data-placement="bottom" title="{{ source_column.help_text }}">
                                                        {% appearance_get_icon icon_path='mayan.apps.navigation.icons.icon_source_column_help_text' %}
                                                        </span>
                                                    {% endif %}
                                                </span>
                                            </th>
                                        {% endfor %}
                                    {% endif %}

                                    {% for column in extra_columns %}
                                        <th>{{ column.name }}</th>
                                    {% endfor %}

                                    {% if not hide_links %}
                                        <th class="">&nbsp;</th>
                                    {% endif %}
                                </tr>
                            {% endif %}
                        </thead>
                        <tbody>
                            {% for object in object_list %}
                                <tr>

                                    {% if links_multi_menus_results %}
                                        <td>
                                            <input class="form-multi-object-action-checkbox check-all-slave checkbox" name="pk_{{ object.pk }}" type="checkbox" value="" />
                                        </td>
                                    {% endif %}

                                    {% if not hide_object %}
                                        <td>{% if not hide_link %}<a href="{{ object.get_absolute_url }}">{{ object }}</a>{% else %}{{ object }}{% endif %}</td>
                                    {% else %}
                                        {% navigation_get_source_columns source=object only_identifier=True as source_column %}
                                        {% navigation_source_column_resolve column=source_column as column_value %}
                                        {% if column_value %}
                                            <td>
                                                {{ column_value }}
                                            </td>
                                        {% endif %}
                                    {% endif %}

                                    {% if not hide_columns %}
                                        {% navigation_get_source_columns source=object exclude_identifier=True as source_columns %}
                                        {% for column in source_columns %}
                                            <td>
                                                <div class="{{ table_cell_container_classes }} {{ column.html_extra_classes }}">
                                                    {% navigation_source_column_resolve column=column as column_value %}{{ column_value }}
                                                    {# Use explicit 'as column_value ' to force date rendering #}
                                                </div>
                                            </td>
                                        {% endfor %}
                                    {% endif %}

                                    {% for column in extra_columns %}
                                        <td>{{ object|common_object_property:column.attribute }}</td>
                                    {% endfor %}

                                    {% if not hide_links %}
                                        <td class="last">
                                            <div class="btn-list">
                                                {% navigation_resolve_menu name='list facet' sort_results=True source=object as facet_menus_results %}
                                                {% for facet_menu_results in facet_menus_results %}
                                                    {% for link_group in facet_menu_results.link_groups %}
                                                        {% with link_group.links as object_navigation_links %}
                                                        {% with 'btn btn-default btn-outline btn-xs' as link_classes %}
                                                            {% include 'navigation/generic_navigation.html' %}
                                                        {% endwith %}
                                                        {% endwith %}
                                                    {% endfor %}
                                                {% endfor %}
                                                {% navigation_resolve_menu name='object' source=object as object_menus_results %}
                                                {% for object_menu_results in object_menus_results %}
                                                    {% for link_group in object_menu_results.link_groups %}
                                                        {% with link_group.links as object_navigation_links %}
                                                            {% include 'navigation/generic_navigation.html' %}
                                                        {% endwith %}
                                                    {% endfor %}
                                                {% endfor %}
                                            </div>
                                        </td>
                                    {% endif %}
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        {% endif %}
    </div>
</div>
