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

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

{%- 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|replace({ '+': ' ' }) }}
            </a>
        {%- endfor -%}
    {%- endfor -%}
{%- endset -%}

{%- set appliedPricesFilters -%}
    {%- if appliedPrices['min'] is defined and resultSet.priceFilter is defined -%}
        {%- set parameters = baseParameters|unset_nested_value(['price'], appliedPrices['min']) -%}

        <a href="{{ path(app.request.attributes.get('_route'), parameters, true) }}" class="filter-selected">
            {% include '@SyliusShop/Icons/cross.html.twig' %}
            {{ resultSet.priceFilter.minLabel | trans }} {{ appliedPrices['min'] }} {{ moneySymbol }}
        </a>
    {%- endif -%}

    {%- if appliedPrices['max'] is defined and resultSet.priceFilter is defined -%}
        {%- set parameters = baseParameters|unset_nested_value(['price'], appliedPrices['max']) -%}

        <a href="{{ path(app.request.attributes.get('_route'), parameters, true) }}" class="filter-selected">
            {% include '@SyliusShop/Icons/cross.html.twig' %}
            {{ resultSet.priceFilter.maxLabel | trans }} {{ appliedPrices['max'] }} {{ moneySymbol }}
        </a>
    {%- endif -%}
{%- endset -%}

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

        {% if appliedPricesFilters != '' %}
            {{ appliedPricesFilters }}
        {% endif %}

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

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