<!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
{% block sw_multi_select %}
<sw-select-base
    class="sw-multi-select"
    :is-loading="isLoading"
    v-bind="$attrs"
    :label="label"
    @select-expanded="onSelectExpanded"
    @select-collapsed="onSelectCollapsed"
    v-on="listeners"
>
    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_multi_select_base %}
    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_multi_select_base_selection %}
    <template #sw-select-selection="{ identification, error, disabled, size, expand, collapse }">
        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_multi_select_base_selection_slot %}
        <sw-select-selection-list
            ref="selectionList"
            :selections="visibleValues"
            :invisible-count="invisibleValueCount"
            v-bind="{ size, valueProperty, labelProperty, placeholder, searchTerm, disabled: disabled || undefined }"
            :input-label="label"
            @total-count-click="expandValueLimit"
            @item-remove="remove"
            @last-item-delete="removeLastItem"
            @search-term-change="onSearchTermChange"
        >
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_multi_select_base_selection_list %}
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_multi_select_base_selection_list_label %}
            <template #label-property="{ item, index, labelProperty, valueProperty }">
                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_multi_select_base_selection_list_label_inner %}
                <slot
                    name="selection-label-property"
                    v-bind="{ item, index, labelProperty, valueProperty}"
                >
                    {{ getKey(item, labelProperty) }}
                </slot>
                {% endblock %}
            </template>
            {% endblock %}
            {% endblock %}
        </sw-select-selection-list>
        {% endblock %}
    </template>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_multi_select_base_results %}
    <template #results-list>
        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_multi_select_base_results_slot %}
        <sw-select-result-list
            ref="swSelectResultList"
            :options="visibleResults"
            :is-loading="isLoading"
            :empty-message="$tc('global.sw-multi-select.messageNoResults', 0, { term: searchTerm })"
            :focus-el="$refs.selectionList.getFocusEl()"
            @paginate="$emit('paginate')"
            @item-select="addItem"
        >
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_multi_select_base_results_list %}
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_multi_select_base_results_list_before %}
            <template #before-item-list>
                <slot name="before-item-list"></slot>
            </template>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_multi_select_base_results_list_result %}
            <template #result-item="{ item, index }">
                <slot
                    name="result-item"
                    v-bind="{ item, index, labelProperty, valueProperty, searchTerm, highlightSearchTerm, isSelected, addItem, getKey }"
                >
                    <sw-select-result
                        :selected="isSelected(item)"
                        :class="'sw-select-option--' + item.value"
                        v-bind="{ item, index }"
                        :aria-label="getKey(item, labelProperty)"
                        @item-select="addItem"
                    >
                        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                        {% block sw_multi_select_base_results_list_result_label %}
                        <slot
                            name="result-label-property"
                            v-bind="{ item, index, labelProperty, valueProperty, searchTerm, getKey }"
                        >
                            <sw-highlight-text
                                v-if="highlightSearchTerm"
                                :text="getKey(item, labelProperty)"
                                :search-term="searchTerm"
                            />
                            <template v-else>
                                {{ getKey(item, labelProperty) }}
                            </template>
                        </slot>
                        {% endblock %}
                    </sw-select-result>
                </slot>
            </template>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_multi_select_base_results_list_after %}
            <template #after-item-list>
                <slot name="after-item-list"></slot>
            </template>
            {% endblock %}
            {% endblock %}
        </sw-select-result-list>
        {% endblock %}
    </template>
    {% endblock %}
    {% endblock %}

    <template #label>
        <slot name="label"></slot>
    </template>

    <template #hint>
        <slot name="hint"></slot>
    </template>
</sw-select-base>
{% endblock %}
