<!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
{% block sw_sales_channel_product_assignment_categories %}
<div class="sw-sales-channel-product-assignment-categories">
    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_sales_channel_product_assignment_categories_info %}
    <sw-alert ref="alert">
        {{ $tc('sw-sales-channel.detail.productAssignmentModal.categories.textInfo') }}
    </sw-alert>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_sales_channel_product_assignment_categories_content %}
    <sw-card
        :is-loading="!isComponentReady || isProductLoading"
        position-identifier="sw-sales-channel-product-assignment-categories"
    >
        <div :style="containerStyle">
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_sales_channel_products_assignment_single_products_secondary %}
            <sw-card-section
                ref="cardSectionSecondary"
                secondary
                divider="bottom"
            >
                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_sales_channel_product_assignment_categories_search_field %}
                <sw-simple-search-field
                    :value="searchTerm"
                    variant="form"
                    size="small"
                    :placeholder="$tc('sw-sales-channel.detail.productAssignmentModal.categories.textSearch')"
                    @search-term-change="onSearchTermChange"
                />
                {% endblock %}
            </sw-card-section>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_sales_channel_product_assignment_categories_tree %}
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_sales_channel_product_assignment_categories_tree_result %}
            <sw-tree
                v-if="searchTerm.length <= 0 && categories.length > 0"
                ref="swTree"
                after-id-property="afterCategoryId"
                :items="categories"
                :sortable="false"
                @get-tree-items="getTreeItems"
            >
                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_sales_channel_product_assignment_categories_tree_headline %}
                <template #headline>
                    <span></span>
                </template>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_sales_channel_product_assignment_categories_tree_search %}
                <template #search>
                    <span></span>
                </template>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_sales_channel_product_assignment_categories_tree_items %}
                <template
                    #items="{
                        treeItems,
                        draggedItem,
                        translationContext
                    }"
                >
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block ssw_sales_channel_product_assignment_categories_tree_item %}
                    <sw-tree-item
                        v-for="item in treeItems"
                        :key="item.id"
                        :item="item"
                        :translation-context="translationContext"
                        :dragged-item="draggedItem"
                        :active-parent-ids="selectedCategoriesPathIds"
                        :active-item-ids="selectedCategoriesItemsIds"
                        :sortable="false"
                        :mark-inactive="true"
                        @check-item="onCheckItem"
                    >

                        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                        {% block sw_sales_channel_product_assignment_categories_tree_item_actions %}
                        <template #actions>
                            <span></span>
                        </template>
                        {% endblock %}

                    </sw-tree-item>
                    {% endblock %}
                </template>
                {% endblock %}
            </sw-tree>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_sales_channel_product_assignment_categories_search_results %}
            <ul
                v-else-if="searchResult.length > 0 && searchTerm.length > 0"
                class="sw-sales-channel-product-assignment-categories__search-results"
            >

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_sales_channel_product_assignment_categories_search_results_item %}
                <li
                    v-for="item in searchResult"
                    :key="item.id"
                    class="sw-sales-channel-product-assignment-categories__search-result"
                    role="option"
                    tabindex="0"
                    :aria-selected="isSearchItemChecked(item.id)"
                    @click.stop="onCheckSearchItem(item)"
                    @keydown.enter="onCheckSearchItem(item)"
                >

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_sales_channel_product_assignment_categories_search_results_item_checkbox %}
                    <sw-checkbox-field
                        class="sw-sales-channel-product-assignment-categories__search-results-checkbox"
                        :value="isSearchItemChecked(item.id)"
                    />
                    {% endblock %}

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_sales_channel_product_assignment_categories_search_results_item_folder %}
                    <div
                        v-if="item.childCount > 0"
                        class="sw-sales-channel-product-assignment-categories__search-results-icon"
                    >
                        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                        {% block sw_sales_channel_product_assignment_categories_search_results_item_folder_icon %}
                        <sw-icon
                            name="regular-folder"
                            small
                        />
                        {% endblock %}
                    </div>
                    {% endblock %}

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_category_tree_field_input_results_search_results_item_endpoint %}
                    <div
                        v-else
                        class="sw-sales-channel-product-assignment-categories__search-results-icon"
                    >
                        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                        {% block sw_category_tree_field_input_results_search_results_item_endpoint_icon %}
                        <sw-icon
                            name="regular-circle-xxs"
                            size="18"
                        />
                        {% endblock %}
                    </div>
                    {% endblock %}

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_sales_channel_product_assignment_categories_search_results_item_name %}
                    <span class="sw-sales-channel-product-assignment-categories__search-results-name">
                        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                        {% block sw_category_tree_field_input_results_search_results_item_name_highlight %}
                        <sw-highlight-text
                            :search-term="searchTerm"
                            :text="getBreadcrumb(item)"
                        />
                        {% endblock %}
                    </span>
                    {% endblock %}
                </li>
                {% endblock %}
            </ul>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_sales_channel_product_assignment_categories_search_results_empty %}
            <sw-empty-state
                v-else
                :show-description="false"
                :absolute="false"
                :title="$tc('sw-sales-channel.detail.productAssignmentModal.categories.emptySearchResults')"
                :icon="'regular-products'"
                class="sw-sales-channel-product-assignment-categories__empty-state"
            />
            {% endblock %}
            {% endblock %}
        </div>
    </sw-card>
    {% endblock %}
</div>
{% endblock %}
