{% set appliedAttributes = app.request.query.get('attribute') %}
{% set currentValues = (appliedAttributes[filter.code] is defined) ? appliedAttributes[filter.code] : [] %}

{% if filter.values|length > 0 or currentValues is not empty %}
    <li class="filter-wrapper" id="{{ 'filter-' ~ filter.code }}">
        <div class="collapse-wrapper">
            <button class="collapse-header title-label active" type="button" data-collapse="collapse-{{ 'filter-' ~ filter.code }}">
                {{ filter.label | trans }}
            </button>

            <div id="collapse-{{ 'filter-' ~ filter.code }}" class="collapse-panel active">
                <div class="collapse-body" data-simplebar data-simplebar-auto-hide="false">
                    {% for value in filter.values %}
                        {% set valueIsApplied = (value.slug in currentValues) %}
                        <label for="{{ 'filter-' ~ filter.code ~ '-value-' ~ value.slug }}" class="custom-control custom-checkbox">
                            <input type="checkbox"
                                   name="attribute[{{ filter.code }}][]"
                                   value="{{ value.slug }}"
                                   id="{{ 'filter-' ~ filter.code ~ '-value-' ~ value.slug }}"
                                   class="custom-control-input"
                                {% if valueIsApplied %}
                                    checked="checked"
                                {% endif %}
                            >
                            <span class="custom-control-field"></span>
                            <span class="custom-control-text">{{ value.label }} ({{ value.count }})</span>
                        </label>
                    {% endfor %}
                </div>
            </div>
        </div>
    </li>
{% endif %}
