{% set queryParameters = app.request.query.all %}
{% set baseParameters = app.request.attributes.get('_route_params')|merge(queryParameters) %}

{% set appliedAttributes = app.request.query.get('attribute') %}

{%- set appliedFilters -%}
    {%- for filter in resultSet.filters -%}
        {%- set currentValues = (appliedAttributes[filter.code] is defined) ? appliedAttributes[filter.code] : [] -%}

        {%- for value in currentValues -%}
            {%- set parameters = baseParameters|unset_nested_value(['attribute', filter.code], value) -%}

            <a href="{{ path(app.request.attributes.get('_route'), parameters, true) }}" class="filter-selected">
                {% include '@SyliusShop/Icons/cross.html.twig' %}
                {{ value }}
            </a>
        {%- endfor -%}
    {%- endfor -%}
{%- endset -%}

{% if appliedFilters != '' %}
    <li class="filter-selected-wrapper">
        {{ appliedFilters }}

        {% set parameters = baseParameters|unset_nested_key(['attribute']) %}

        <a href="{{ path(app.request.attributes.get('_route'), parameters, true) }}" class="link-secondary">{{ 'monsieurbiz_searchplugin.filters.reinit_btn'|trans }}</a>
    </li>
{% endif %}
