<!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
{% block sw_tree %}
<div
    class="sw-tree"
    role="tree"
    :aria-label="$tc(`${translationContext}.general.treeHeadline`)"
>
    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_tree_search %}
    <slot name="search">
        <div
            v-if="searchable"
            class="sw-tree__search"
        >
            <sw-text-field
                v-model:value="currentTreeSearch"
                name="treeSearch"
                :placeholder="$tc('sw-tree.general.placeholderSearch')"
                size="small"
                @update:value="searchItems"
            >
                <template #prefix>
                    <sw-icon name="regular-search" />
                </template>
            </sw-text-field>
        </div>
    </slot>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_tree_actions_headline %}
    <slot name="headline">
        <div
            v-if="checkedElementsCount > 0"
            class="sw-tree-actions__headline"
        >
            <span> {{ $tc(`${translationContext}.general.treeHeadSelected`, 0, { count: checkedElementsCount }) }}:</span>
            <sw-button
                class="sw-tree-actions__delete_categories"
                :disabled="!allowDeleteCategories || undefined"
                variant="danger"
                size="small"
                @click="onDeleteElements(null)"
            >
                {{ $tc('global.default.delete') }}
            </sw-button>
        </div>

        <div
            v-else
            class="sw-tree-actions__headline"
        >
            <span>{{ $tc(`${translationContext}.general.treeHeadline`) }}</span>
        </div>
    </slot>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_tree_content %}
    <div class="sw-tree__content">
        <div class="tree-items">

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_tree_items %}
            <sw-tree-input-field
                v-if="hasNoItems && allowCreateCategories"
                :disabled="disableContextMenu"
                @new-item-create="onCreateNewItem"
            />
            <slot
                v-else
                name="items"
                :tree-items="treeItems"
                :dragged-item="draggedItem"
                :new-element-id="newElementId"
                :check-item="checkItem"
                :translation-context="translationContext"
                :on-change-route="onChangeRoute"
                :sortable="sortable"
                :disable-context-menu="disableContextMenu"
                :selected-items-path-ids="selectedItemsPathIds"
                :checked-item-ids="checkedItemIds"
            >
                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_tree_slot_items %}
                <sw-tree-item
                    v-for="item in treeItems"
                    :key="item.id"
                    :item="item"
                    :translation-context="translationContext"
                    :dragged-item="draggedItem"
                    :active-parent-ids="selectedItemsPathIds"
                    :active-item-ids="checkedItemIds"
                    @check-item="checkItem"
                />
                {% endblock %}

            </slot>
            {% endblock %}

        </div>
    </div>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_tree_delete_modal %}
    <sw-modal
        v-if="showDeleteModal"
        :title="$tc('global.default.warning')"
        variant="small"
        @modal-close="onCloseDeleteModal"
    >
        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_tree_delete_modal_confirm_delete_text %}
        <div v-if="toDeleteItem">
            <p
                v-if="toDeleteItem.childCount > 0"
                class="sw_tree__confirm-delete-text"
            >
                {{ $tc(`${translationContext}.modal.textDeleteConfirm`, 0, { name: toDeleteItem.data.name || toDeleteItem.data.translated.name }) }}<br>
                <b>{{ $tc(`${translationContext}.modal.textDeleteChildrenConfirm`) }}</b>
            </p>
            <p
                v-else
                class="sw_tree__confirm-delete-text"
            >
                {{ $tc(`${translationContext}.modal.textDeleteConfirm`, 0, { name: toDeleteItem.data.name || toDeleteItem.data.translated.name }) }}
            </p>
        </div>
        <div v-else>
            <p
                v-if="checkedElementsChildCount > 0"
                class="sw_tree__confirm-delete-text"
            >
                {{ $tc(`${translationContext}.modal.textDeleteMultipleConfirm`, 0, { count: checkedElementsCount }) }}<br>
                <b>{{ $tc(`${translationContext}.modal.textDeleteChildrenConfirm`) }}</b>
            </p>
            <p
                v-else
                class="sw_tree__confirm-delete-text"
            >
                {{ $tc(`${translationContext}.modal.textDeleteMultipleConfirm`, 0, { count: checkedElementsCount }) }}
            </p>
        </div>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_tree_delete_modal_footer %}
        <template #modal-footer>
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_tree_delete_modal_cancel %}
            <sw-button
                size="small"
                @click="onCloseDeleteModal"
            >
                {{ $tc('global.default.cancel') }}
            </sw-button>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_tree_delete_modal_confirm %}
            <sw-button
                variant="danger"
                size="small"
                @click="onConfirmDelete()"
            >
                {{ $tc('global.default.delete') }}
            </sw-button>
            {% endblock %}
        </template>
        {% endblock %}
    </sw-modal>
    {% endblock %}
</div>
{% endblock %}
