<!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
{% block sw_category %}
<sw-page
    class="sw-category"
    :class="pageClasses"
>
    <template #search-bar>
        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_category_search_bar %}
        <sw-search-bar
            ref="searchBar"
            initial-search-type="category"
            :initial-search="term"
            type-search-always-in-container
            @search="onSearch"
        />
        {% endblock %}
    </template>

    <template #smart-bar-header>
        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_category_smart_bar_header %}
        <h2 v-if="category">
            {{ placeholder(category, 'name') }}
        </h2>
        <h2 v-else>
            {{ $tc('sw-category.general.headlineCategories') }}
        </h2>
        {% endblock %}
    </template>

    <template #language-switch>
        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_category_language_switch %}
        <sw-language-switch
            :save-changes-function="saveOnLanguageChange"
            :abort-change-function="abortOnLanguageChange"
            :disabled="landingPageId === 'create'"
            @on-change="onChangeLanguage"
        />
        {% endblock %}
    </template>

    <template #smart-bar-actions>
        <template v-if="category || landingPage">
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_category_smart_bar_abort %}
            <sw-button
                v-tooltip.bottom="tooltipCancel"
                :disabled="isLoading"
                @click="cancelEdit"
            >
                {{ $tc('global.default.cancel') }}
            </sw-button>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_category_smart_bar_save %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_category_smart_bar_save_category %}
            <sw-button-process
                v-if="category"
                v-tooltip.bottom="tooltipSave"
                class="sw-category-detail__save-action"
                :is-loading="isLoading"
                :process-success="isSaveSuccessful"
                :disabled="isLoading || !acl.can('category.editor')"
                variant="primary"
                @update:process-success="saveFinish"
                @click.prevent="onSave"
            >
                {{ $tc('sw-category.general.buttonSafeCategory') }}
            </sw-button-process>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_category_smart_bar_save_landing_page %}
            <sw-button-process
                v-if="landingPage"
                v-tooltip.bottom="landingPageTooltipSave"
                class="sw-category-detail__save-landing-page-action"
                :is-loading="isLoading"
                :process-success="isSaveSuccessful"
                :disabled="isLoading || !acl.can('landing_page.editor')"
                variant="primary"
                @update:process-success="saveFinish"
                @click.prevent="onSaveLandingPage"
            >
                {{ $tc('sw-category.general.buttonSafeCategory') }}
            </sw-button-process>
            {% endblock %}
            {% endblock %}
        </template>
    </template>

    <template #side-content>
        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_category_side_content %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_category_collapse %}
        <sw-sidebar-collapse
            class="sw-category-detail__category-collapse"
            :expand-on-loading="landingPageId === null"
        >
            <template #header>

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_category_collapse_header %}
                <div
                    v-if="categoryCheckedItem > 0"
                    class="sw-category-detail__collapse-selected-count"
                >
                    {{ $tc(`sw-category.general.treeHeadSelected`, 0, { count: categoryCheckedItem }) }}:
                </div>
                <div
                    v-else
                    class="sw-category-detail__collapse-headline"
                >
                    {{ $tc(`sw-category.general.treeHeadline`) }}
                </div>
                {% endblock %}

            </template>

            <template #actions>

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_category_collapse_actions %}
                <div v-if="categoryCheckedItem > 0">
                    <sw-button
                        class="sw-tree-actions__delete_categories"
                        variant="danger"
                        size="small"
                        @click="onCategoryDelete"
                    >
                        {{ $tc('global.default.delete') }}
                    </sw-button>
                </div>
                {% endblock %}

            </template>

            <template #content>

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_category_tree %}
                <sw-category-tree
                    ref="categoryTree"
                    :category-id="categoryId"
                    :current-language-id="currentLanguageId"
                    :allow-edit="acl.can('category.editor')"
                    :allow-create="acl.can('category.creator')"
                    :allow-delete="acl.can('category.deleter')"
                    @unsaved-changes="openChangeModal"
                    @category-checked-elements-count="categoryCheckedElementsCount"
                />
                {% endblock %}

            </template>
        </sw-sidebar-collapse>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_landing_page_collapse %}
        <sw-sidebar-collapse
            class="sw-category-detail__landing-page-collapse"
            :expand-on-loading="landingPageId !== null"
        >
            <template #header>

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_landing_page_collapse_header %}
                <div
                    v-if="landingPageCheckedItem > 0"
                    class="sw-category-detail__collapse-selected-count"
                >
                    {{ $tc(`sw-landing-page.general.treeHeadSelected`, 0, { count: landingPageCheckedItem }) }}:
                </div>
                <div
                    v-else
                    class="sw-category-detail__collapse-headline"
                >
                    {{ $tc(`sw-landing-page.general.treeHeadline`) }}
                </div>
                {% endblock %}

            </template>

            <template #actions>

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_landing_page_collapse_actions %}
                <div v-if="landingPageCheckedItem > 0">
                    <sw-button
                        class="sw-tree-actions__delete_categories"
                        variant="danger"
                        size="small"
                        @click="onLandingPageDelete"
                    >
                        {{ $tc('global.default.delete') }}
                    </sw-button>
                </div>
                {% endblock %}

            </template>

            <template #content>

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_landing_page_tree %}
                <sw-landing-page-tree
                    ref="landingPageTree"
                    :landing-page-id="landingPageId"
                    :current-language-id="currentLanguageId"
                    :allow-edit="acl.can('landing_page.editor')"
                    :allow-create="acl.can('landing_page.creator')"
                    :allow-delete="acl.can('landing_page.deleter')"
                    @unsaved-changes="openChangeModal"
                    @landing-page-checked-elements-count="landingPageCheckedElementsCount"
                />
                {% endblock %}

            </template>
        </sw-sidebar-collapse>
        {% endblock %}
        {% endblock %}
    </template>

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_category_content %}
    <template #content>

        <template v-if="isLoading">
            <sw-skeleton variant="detail-bold" />
            <sw-skeleton />
        </template>

        <template v-else>
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_category_content_view %}
            <sw-category-view
                v-if="category"
                ref="categoryView"
                :is-loading="isLoading"
                :type="category.type"
            />
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_category_content_entry_point_overwrite_modal %}
            <sw-category-entry-point-overwrite-modal
                v-if="showEntryPointOverwriteModal"
                :sales-channels="entryPointOverwriteSalesChannels"
                @cancel="cancelEntryPointOverwrite"
                @confirm="confirmEntryPointOverwrite"
            />
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_landing_page_content_view %}
            <sw-landing-page-view
                v-if="landingPage"
                ref="landingPageView"
                :is-loading="isLoading"
            />
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_category_content_discard_changes_modal %}
            <sw-discard-changes-modal
                v-if="isDisplayingLeavePageWarning"
                @keep-editing="onLeaveModalClose(nextRoute)"
                @discard-changes="onLeaveModalConfirm(nextRoute)"
            />
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_category_content_empty %}
            <sw-empty-state
                v-if="showEmptyState"
                :title="$tc('sw-category.general.emptyStateHeadline')"
            >
                <template #icon>
                    <img
                        :src="assetFilter('/administration/static/img/empty-states/products-empty-state.svg')"
                        :alt="$tc('sw-category.general.emptyStateHeadline')"
                    >
                </template>
            </sw-empty-state>
        {% endblock %}

        </template>
    </template>
    {% endblock %}

</sw-page>
{% endblock %}
