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

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

{% appearance_get_icon 'mayan.apps.appearance.icons.icon_menu_actions' extra_context__html_data__style='pointer-events: none;' extra_context__icon_css_classes_extra='appearance-icon-padding-none' as icon_menu_actions %}
{% appearance_get_icon 'mayan.apps.appearance.icons.icon_menu_views' extra_context__html_data__style='pointer-events: none;' extra_context__icon_css_classes_extra='appearance-icon-padding-none' as icon_menu_views %}

{% smart_setting "COMMON_COLLAPSE_LIST_MENU_LIST_FACET" as setting_common_collapse_list_menu_list_facet %}
{% smart_setting "COMMON_COLLAPSE_LIST_MENU_OBJECT" as setting_common_collapse_list_menu_object %}

<div class="row">
    <div class="col-xs-12">
        {% include 'appearance/partials/list_header.html' %}

        {% navigation_resolve_menu name='multi item' sort_results=True source=object_list.0 as links_multi_menus_results %}

        {% navigation_get_source_columns source=object_list only_identifier=True as source_columns_identifier %}
        {% navigation_get_source_columns source=object_list exclude_identifier=True as source_columns_non_identifier %}

        <div class="well center-block">
            <div class="table-responsive">
                <table class="table table-condensed table-striped appearance-table-condensed">
                    <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 %}
                                    {% if source_columns_identifier %}
                                        <th>
                                            <span style="white-space: nowrap">
                                                {% if source_columns_identifier.0.is_sortable %}
                                                    <a href="{% navigation_get_sort_field_querystring column=source_columns_identifier.0 %}">{{ source_columns_identifier.0.label }}</a>
                                                        {% navigation_source_column_get_sort_icon column=source_columns_identifier.0 as icon_sort %}
                                                        {% if icon_sort %}
                                                            <span class="appearance-list-column-sort-icon">
                                                                {{ icon_sort.render }}
                                                            </span>
                                                        {% endif %}
                                                {% else %}
                                                    <span class="appearance-list-column-label">{{ source_columns_identifier.0.label }}</span>
                                                {% endif %}
                                                {% include 'appearance/partials/column_help_text.html' with source_column=source_columns_identifier.0 %}
                                            </span>
                                        </th>
                                    {% endif %}
                                {% endif %}

                                {% if not hide_columns %}
                                    {% for source_column in source_columns_non_identifier %}
                                        <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>
                                                        {% navigation_source_column_get_sort_icon column=source_column as icon_sort %}
                                                        {% if icon_sort %}
                                                            <span class="appearance-list-column-sort-icon">
                                                                {{ icon_sort.render }}
                                                            </span>
                                                        {% endif %}
                                                {% else %}
                                                    <span class="appearance-list-column-label">{{ source_column.label }}</span>
                                                {% endif %}
                                                {% include 'appearance/partials/column_help_text.html' %}
                                            </span>
                                        </th>
                                    {% endfor %}
                                {% endif %}

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

                                {% if not hide_links %}
                                    {% navigation_resolve_menu name='list facet' sort_results=True source=object_list.0 as facet_menus_results %}
                                    {% if facet_menus_results %}
                                        <th class="text-center">{% trans 'Views' %}</th>
                                    {% endif %}


                                    {% navigation_resolve_menu name='object' source=object_list.0 sort_results=True as object_menus_results %}
                                    {% if object_menus_results %}
                                        <th class="text-center">{% trans 'Actions' %}</th>
                                    {% endif %}
                                {% endif %}
                            </tr>
                        {% endif %}
                        <tr class="appearance-table-thead-tr-spacer">
                            <th></th>
                        </tr>

                        <tr class="appearance-table-thead-tr-ruler">
                            <th></th>
                        </tr>
                    </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 %}
                                    {% if source_columns_identifier %}
                                        {% navigation_source_column_resolve column=source_columns_identifier.0 as column_value %}
                                        <td>
                                            {{ column_value }}
                                        </td>
                                    {% endif %}
                                {% endif %}

                                {% if not hide_columns %}
                                    {% for column in source_columns_non_identifier %}
                                        <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 %}
                                    {% navigation_resolve_menu name='list facet' sort_results=True source=object as facet_menus_link_results %}
                                    {% if facet_menus_results %}
                                        <td class="text-center">
                                            <div class="btn-list {% if setting_common_collapse_list_menu_list_facet %}text-center{% else %}text-left{% endif %}">
                                                {% include 'appearance/partials/list_object_facet_links_column.html' %}
                                            </div>
                                        </td>
                                    {% endif %}

                                    {% navigation_resolve_menu name='object' source=object sort_results=True as object_menus_link_results %}
                                    {% if object_menus_results %}
                                        <td class="last">
                                            <div class="btn-list {% if setting_common_collapse_list_menu_object %}text-center{% else %}text-left{% endif %}">
                                               {% include 'appearance/partials/list_object_links_column.html' %}
                                            </div>
                                        </td>
                                    {% endif %}
                                {% endif %}
                            </tr>
                        {% endfor %}
                        {% if object_list %}
                            <tr class="appearance-table-tbody-tr-ruler">
                                <td></td>
                            </tr>
                        {% endif %}
                    </tbody>
                </table>
                {% if not object_list %}
                    <div class="well center-block">
                        {% include 'appearance/partials/no_results.html' %}
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>
