<section class="filters-wrapper collapse-panel" id="filters-wrapper">
    <ul class="collapse-group custom-collapse">
        {% if result.filters|length == 0 %}
            <li class="filter-selected-wrapper">
                {{ 'monsieurbiz_searchplugin.filters.no_filter'|trans }}
            </li>
        {% else %}
            {% set encodedQuery = app.request.attributes.get('_route_params').query|default('')|url_encode %}
            {% set path = path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge(app.request.query.all)|merge({query: encodedQuery})) %}
            <form name="filters-form" method="get" action="{{ path }}">
                {% include '@MonsieurBizSyliusSearchPlugin/Search/_appliedFilters.html.twig' %}

                {% for filter in result.filters %}
                    {% include '@MonsieurBizSyliusSearchPlugin/Search/_filter.html.twig' with {'filter': filter} %}
                {% endfor %}

                {# Don't loose current document_type #}
                {% set documentType = app.request.query.all()['document_type']|default() %}
                {% if documentType is not empty %}
                    <input type="hidden" name="document_type" value="{{ documentType|escape('html_attr') }}" />
                {% endif %}

                {# Don't loose current sorting #}
                {% set sorting = app.request.query.all()['sorting']|default() %}
                {% if sorting is not empty %}
                    {% for sort, order in sorting %}
                        <input type="hidden" name="sorting[{{ sort }}]" value="{{ order|escape('html_attr') }}" />
                    {% endfor %}
                {% endif %}

                {# Don't loose current limit #}
                {% set limit = app.request.query.get('limit') %}
                {% if limit is not empty %}
                    <input type="hidden" name="limit" value="{{ limit|escape('html_attr') }}" />
                {% endif %}

                {% if apply_filters_manually %}
                    <div class="filter-btn">
                        <button type="submit" class="btn btn-primary btn-block btn-sm">{{ 'app.ui.apply_filters'|trans }}</button>
                    </div>
                {% endif %}
            </form>
        {% endif %}
    </ul>
</section>
