{% block element_sidebar_filter %}
    {# Use values from cms data if context is a cmsPage, otherwise `listing` and `sidebar` must be set manually #}
    {% if cmsPage is defined %}
        {% set config = element.fieldConfig.elements %}
        {% set slot = cmsPage.getFirstElementOfType('product-listing') %}
        {% set listing = slot.data.listing %}
        {% set sidebar = block.sectionPosition == 'sidebar' %}
    {% endif %}

    {% if listing.aggregations.elements|length > 0 %}
        <div class="cms-element-sidebar-filter">
            {% block element_product_listing_filter_button %}
                <button
                    class="btn btn-outline-primary filter-panel-wrapper-toggle"
                    type="button"
                    {# @deprecated tag:v6.6.0 - Registering plugin on selector "data-offcanvas-filter" is deprecated. Use "data-off-canvas-filter" instead #}
                    {% if feature('v6.6.0.0') %}
                        data-off-canvas-filter="true"
                    {% else %}
                        data-offcanvas-filter="true"
                    {% endif %}
                    aria-haspopup="true"
                    aria-expanded="false"
                    aria-label="{{ "general.menuLink"|trans }}"
                >
                    {% block element_product_listing_filter_button_icon %}
                        {% sw_icon 'sliders-horizontal' %}
                    {% endblock %}
                    {{ "listing.filterTitleText"|trans }}
                </button>
            {% endblock %}

            {% block element_sidebar_filter_panel %}
                <div
                    id="filter-panel-wrapper"
                    class="filter-panel-wrapper"
                    {# @deprecated tag:v6.6.0 - Selector "data-off-canvas-filter-content" is deprecated. Use "data-offcanvas-filter-content" instead #}
                    {% if feature('v6.6.0.0') %}
                        data-off-canvas-filter-content="true"
                    {% else %}
                        data-offcanvas-filter-content="true"
                    {% endif %}
                >
                    {% sw_include '@Storefront/storefront/component/listing/filter-panel.html.twig' with {
                        listing: listing,
                        sidebar: sidebar
                    } %}
                </div>
            {% endblock %}
        </div>
    {% endif %}
{% endblock %}
