{% load django_listing %}
{% autoescape off %}
    <div{{ listing.container_attrs }}>
    <style>
        @media (max-width: {{ listing.theme_localized_small_device_styles_width }}) {
          {% for style in listing.get_localized_small_device_styles %}{{ style }}
          {% endfor %}
        }
    </style>
    <div class="listing-spinner"><span class="{{ listing.theme_spinner_icon }}"></span></div>

        {% if listing.row_form_errors %}
            <ul class="listing-row-form-errors">
                {% for error in listing.row_form_errors %}<li>{{error|safe}}</li>
                {% endfor %}
            </ul>
        {% endif %}

        {% if listing.paginator.count or not listing.empty_listing_template_name %}
            {% if has_top_toolbar %}
                <div class="top-toolbar">
                    {% include listing.toolbar.template_name %}
                </div>
            {% endif %}
            {% if listing.can_edit or listing.has_upload or listing.edit_on_demand %}
                {% if listing.action_header_template_name %}
                    {% include listing.action_header_template_name %}
                {% endif %}
            {% endif %}
            {% if listing.has_group_by %}
                <div class="group-by-container">
                    {% include listing.gb_template_name %}
                </div>
            {% endif %}
            {% block listing %}
                <table{{ listing.attrs }}>
                    {% block listing_header %}
                        {% if listing.has_header %}
                            <thead>
                            <tr class="{{ listing.theme_table_header_class }}">
                                {% for col in listing.header_columns %}{{ col.html }}
                                {% endfor %}
                            </tr>
                            </thead>
                        {% endif %}
                    {% endblock listing_header %}
                    {% block listing_body %}
                        <tbody>
                        {% for row in listing.rows %}{% block listing_body_row %}
                            <tr{{ row.attrs }}>{% if listing.has_hidden_selection %}<input class="row-select" type="hidden" {% if row.selected %}name="selected_rows{{ listing.suffix }}" {% endif %}select-name="selected_rows{{ listing.suffix }}" value="{{ row.selection_value }}">{% endif %}
                                {% for col in row.columns %}{{ col.html }}
                                {% endfor %}</tr>{% endblock listing_body_row %}
                        {% empty %}
                            {% if listing.empty_table_msg %}
                                {% block listing_empty %}
                                    <tr>
                                        <td colspan="{{ nb_columns }}">
                                            <div class="empty-message">
                                                {{ listing.empty_table_msg }}
                                            </div>
                                        </td>
                                    </tr>
                                {% endblock listing_empty %}
                            {% endif %}
                        {% endfor %}
                        </tbody>
                    {% endblock listing_body %}
                    {% block listing_footer %}
                        {% if listing.has_footer or listing.footer_template_name or listing.paginator.in_footer %}
                            <tfoot>
                            <tr>
                                {% if listing.paginator.in_footer %}
                                    <td colspan="{{ nb_columns }}">
                                        {% include listing.paginator.template_name %}
                                    </td>
                                {% elif listing.footer_template_name %}
                                    <td colspan="{{ nb_columns }}">
                                        {% include listing.footer_template_name %}
                                    </td>
                                {% else %}
                                    {% for col in listing.footer_columns %}{{ col.html }}
                                    {% endfor %}
                                {% endif %}
                            </tr>
                            </tfoot>
                        {% endif %}
                    {% endblock listing_footer %}
                </table>
            {% endblock listing %}

            {% block hiddens %}
                {% for name, value in listing.form_input_hiddens.items %}
                    <input type="hidden" name="{{ name }}" value="{{ value }}">{% endfor %}
                {% if listing.editable and listing.editing %}
                    {% for hidden_field in listing.editing_hidden_form_fields %}
                        {{ hidden_field }}{% endfor %}
                    {{ listing.get_formset.management_form }}
                {% endif %}
            {% endblock %}

            {% if listing.can_edit or listing.has_upload or listing.edit_on_demand %}
                </form>
            {% endif %}

            {% if has_bottom_toolbar %}
                <div class="bottom-toolbar">
                    {% include listing.toolbar.template_name %}
                </div>
            {% endif %}

            {% if listing.has_paginator and not listing.paginator.in_footer %}
                {% include listing.paginator.template_name %}
            {% endif %}

            {% if listing.can_edit or listing.has_upload or listing.edit_on_demand %}
                {% if listing.action_footer_template_name %}
                    {% include listing.action_footer_template_name %}
                {% endif %}
            {% endif %}
        {% else %}
            {% if listing.can_edit or listing.has_upload or listing.edit_on_demand %}
                {% if listing.action_header_template_name %}
                    {% include listing.action_header_template_name %}
                {% endif %}
            {% endif %}
            {% include listing.empty_listing_template_name %}
            {% if listing.can_edit or listing.has_upload or listing.edit_on_demand %}
                {% if listing.action_footer_template_name %}
                    {% include listing.action_footer_template_name %}
                {% endif %}
            {% endif %}
            {% if listing.can_edit or listing.has_upload or listing.edit_on_demand %}
                </form>
            {% endif %}
        {% endif %}

    </div>
{% endautoescape %}