<!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
{% block sw_product_list %}
<sw-page class="sw-product-list">

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_product_list_search_bar %}
    <template #search-bar>
        <sw-search-bar
            initial-search-type="product"
            :initial-search="term"
            @search="onSearch"
        />
    </template>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_product_list_smart_bar_header %}
    <template #smart-bar-header>
        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_product_list_smart_bar_header_title %}
        <h2>
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_product_list_smart_bar_header_title_text %}
            {{ $tc('sw-product.list.textProductOverview') }}
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_product_list_smart_bar_header_amount %}
            <span
                v-if="!isLoading"
                class="sw-page__smart-bar-amount"
            >
                ({{ total }})
            </span>
            {% endblock %}
        </h2>
        {% endblock %}
    </template>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_product_list_smart_bar_actions %}
    <template #smart-bar-actions>
        <sw-button-group
            v-tooltip.bottom="{
                message: $tc('sw-privileges.tooltip.warning'),
                disabled: acl.can('product.creator'),
                showOnDisabledElements: true
            }"
            class="sw-product-list__add-button-group"
            split-button
        >
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_product_list_smart_bar_actions_add %}
            <sw-button
                v-tooltip="{
                    message: $tc('sw-privileges.tooltip.warning'),
                    disabled: acl.can('product.creator'),
                    showOnDisabledElements: true
                }"
                class="sw-product-list__add-physical-button"
                :router-link="{ name: 'sw.product.create', query: { creationStates: ['is-physical'] } }"
                variant="primary"
                :disabled="!acl.can('product.creator')"
            >
                {{ $tc('sw-product.list.buttonAddProduct') }}
            </sw-button>
            {% endblock %}
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_product_list_smart_bar_actions_add_download %}
            <sw-context-button class="sw-product-list__add-other-context-button">
                <template #button>
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_list_smart_bar_actions_add_download_button %}
                    <sw-button
                        class="sw-product-list__button-context-menu"
                        square
                        variant="primary"
                        :disabled="!acl.can('product.editor')"
                    >
                        <sw-icon
                            name="regular-chevron-down-xs"
                            size="16"
                        />
                    </sw-button>
                    {% endblock %}
                </template>

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_product_list_smart_bar_actions_add_download_context_menu_item_downloadable_product %}
                <sw-context-menu-item
                    v-tooltip="{
                        message: $tc('sw-privileges.tooltip.warning'),
                        disabled: acl.can('product.creator'),
                        showOnDisabledElements: true
                    }"
                    :router-link="{ name: 'sw.product.create', query: { creationStates: ['is-download'] } }"
                    :disabled="!acl.can('product.creator')"
                >
                    {{ $tc('sw-product.list.buttonAddDownloadableProduct') }}
                </sw-context-menu-item>
                {% endblock %}
            </sw-context-button>
            {% endblock %}
        </sw-button-group>
    </template>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_product_list_language_switch %}
    <template #language-switch>
        <sw-language-switch @on-change="onChangeLanguage" />
    </template>
    {% endblock %}

    <template #content>
        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_product_list_content %}
        <div class="sw-product-list__content">

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_product_list_grid %}
            <sw-entity-listing
                v-if="entitySearchable"
                ref="swProductGrid"
                class="sw-product-list-grid"
                :items="products"
                :columns="productColumns"
                :repository="productRepository"
                detail-route="sw.product.detail"
                :show-selection="true"
                :is-loading="isLoading"
                identifier="sw-product-list"
                :allow-edit="acl.can('product.editor')"
                :allow-delete="acl.can('product.deleter')"
                :allow-inline-edit="acl.can('product.editor')"
                :sort-by="currentSortBy"
                :sort-direction="sortDirection"
                :natural-sorting="naturalSorting"
                :criteria-limit="limit"
                :disable-data-fetching="true"
                :allow-bulk-edit="acl.can('product.editor')"
                @column-sort="onColumnSort"
                @page-change="onPageChange"
                @inline-edit-save="onInlineEditSave"
                @selection-change="updateSelection"
                @update-records="updateTotal"
                @bulk-edit-modal-open="onBulkEditModalOpen"
            >
                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_product_list_grid_columns %}
                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_product_list_grid_columns_name_preview %}
                <template #preview-name="{ item }">
                    <sw-media-preview-v2 :source="item.cover ? item.cover.media : null" />
                </template>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_product_list_grid_columns_name %}
                <template #column-name="{ item, isInlineEdit }">
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_list_grid_columns_name_inline_edit %}
                    <sw-text-field
                        v-if="isInlineEdit"
                        v-model:value="item.name"
                        size="small"
                    />
                    {% endblock %}

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_list_grid_columns_name_content %}
                    <div v-else>
                        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                        {% block sw_product_list_grid_columns_name_content_variant_button %}
                        <sw-button
                            v-if="productHasVariants(item)"
                            v-tooltip="{ message: $tc('sw-product.list.variantIndicatorTooltip') }"
                            class="sw-product-list__variant-indicator"
                            size="x-small"
                            @click="openVariantModal(item)"
                        >
                            <sw-icon
                                name="regular-variants"
                                size="14px"
                            />
                        </sw-button>
                        {% endblock %}

                        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                        {% block sw_product_list_grid_columns_name_content_link %}
                        <router-link :to="{ name: 'sw.product.detail', params: { id: item.id } }">
                            {{ item.translated ? item.translated.name : item.name }}
                        </router-link>
                        {% endblock %}

                        <sw-label
                            v-if="productIsDigital(item)"
                            class="sw-product-list__digital-indicator"
                        >
                            {{ $tc('sw-product.variations.generatedListColumnContentProductState.is-download') }}
                        </sw-label>
                    </div>
                    {% endblock %}
                </template>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_product_list_grid_columns_active %}
                <template #column-active="{ item, isInlineEdit }">
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_list_grid_columns_active_inline_edit %}
                    <template v-if="isInlineEdit">
                        <sw-checkbox-field
                            v-model:value="item.active"
                        />
                    </template>
                    {% endblock %}

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_list_grid_columns_active_content %}
                    <template v-else>
                        <sw-icon
                            v-if="item.active"
                            name="regular-checkmark-xs"
                            small
                            class="is--active"
                        />
                        <sw-icon
                            v-else
                            name="regular-times-s"
                            small
                            class="is--inactive"
                        />
                    </template>
                    {% endblock %}
                </template>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_product_list_grid_columns_sales %}
                <template #column-sales="{ item }">
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_list_grid_columns_sales_content %}
                    <template v-if="productHasVariants(item)">
                        -
                    </template>
                    <template v-else>
                        {{ item.sales }}
                    </template>
                    {% endblock %}
                </template>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_product_list_grid_columns_price %}
                <template
                    v-for="currency in currencies"
                    #[`column-price-${currency.isoCode}`]="{ item }"
                >
                    {{ currencyFilter(getCurrencyPriceByCurrencyId(currency.id, item.price).gross, currency.isoCode) }}
                </template>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_product_list_grid_columns_stock %}
                <template #column-stock="{ item, isInlineEdit, compact }">
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_list_grid_columns_stock_inline_edit %}
                    <template v-if="isInlineEdit">
                        <sw-number-field
                            v-model:value="item.stock"
                            :size="compact ? 'small' : 'default'"
                        />
                    </template>
                    {% endblock %}

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_list_grid_columns_stock_content %}
                    <template v-else>
                        {{ item.stock }}
                        <sw-color-badge :variant="stockColorVariantFilter(item.stock)" />
                    </template>
                    {% endblock %}
                </template>
                {% endblock %}

                <template #column-createdAt="{ item }">
                    {{ dateFilter(item.createdAt) }}
                </template>

                <template #column-updatedAt="{ item }">
                    {{ dateFilter(item.updatedAt) }}
                </template>

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_product_list_grid_columns_actions %}
                <template #more-actions="{ item }">
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_list_grid_columns_actions_duplicate %}
                    <sw-context-menu-item
                        class="sw-product-list-grid__duplicate-action"
                        :disabled="item.parentId != null || !acl.can('product.creator')"
                        @click="onDuplicate(item)"
                    >
                        {{ $tc('sw-product.list.buttonDuplicate') }}
                    </sw-context-menu-item>
                    {% endblock %}

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_list_grid_columns_actions_open_variant %}
                    <sw-context-menu-item
                        v-if="productHasVariants(item)"
                        @click="openVariantModal(item)"
                    >
                        {{ $tc('sw-product.list.contextMenuShowVariants') }}
                    </sw-context-menu-item>
                    {% endblock %}
                </template>
                {% endblock %}
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_product_list_bulk_edit_modal %}
                <template #bulk-edit-modal="{ selection }">
                    <sw-bulk-edit-modal
                        v-if="showBulkEditModal"
                        class="sw-product-bulk-edit-modal"
                        :selection="selection"
                        :bulk-grid-edit-columns="productBulkEditColumns"
                        @edit-items="onBulkEditItems"
                        @modal-close="showBulkEditModal = false"
                    >
                        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                        {% block sw_product_list_bulk_edit_grid_columns_name %}
                        <template #column-name="{ item }">
                            <router-link
                                :to="{ name: 'sw.product.detail', params: { id: item.id } }"
                                target="_blank"
                                rel="noreferrer noopener"
                            >
                                {{ item.translated ? item.translated.name : item.name }}
                            </router-link>
                        </template>
                        {% endblock %}

                        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                        {% block sw_product_list_bulk_edit_grid_columns_active %}
                        <template #column-active="{ item }">
                            <sw-icon
                                small
                                :name="item.active ? 'regular-checkmark-xs' : 'regular-times-s'"
                                :color="item.active ? '#37d046' : '#de294c'"
                            />
                        </template>
                        {% endblock %}

                        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                        {% block sw_product_list_bulk_edit_grid_columns_price %}
                        <template
                            v-for="currency in currencies"
                            #[`column-price-${currency.isoCode}`]="{ item }"
                        >
                            {{ currencyFilter(getCurrencyPriceByCurrencyId(currency.id, item.price).gross, currency.isoCode) }}
                        </template>
                        {% endblock %}

                        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                        {% block sw_product_list_bulk_edit_grid_columns_stock %}
                        <template #column-stock="{ item }">
                            {{ item.stock }}
                            <sw-color-badge :variant="stockColorVariantFilter(item.stock)" />
                        </template>
                        {% endblock %}
                    </sw-bulk-edit-modal>
                </template>
                {% endblock %}
            </sw-entity-listing>

            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_product_list_empty_state %}
            <template v-if="!isLoading && !total">
                <sw-empty-state
                    v-if="filterCriteria.length || isValidTerm(term)"
                    :title="$tc('sw-empty-state.messageNoResultTitle')"
                >
                    <template #icon>
                        <img
                            :src="assetFilter('/administration/static/img/empty-states/products-empty-state.svg')"
                            :alt="$tc('sw-empty-state.messageNoResultTitle')"
                        >
                    </template>

                    <template #default>
                        {{ $tc('sw-empty-state.messageNoResultSublineBefore') }}
                        <router-link
                            class="sw-empty-state__description-link"
                            :to="{ name: 'sw.profile.index.searchPreferences' }"
                        >
                            {{ $tc('sw-empty-state.messageNoResultSublineLink') }}
                        </router-link>
                        {{ $tc('sw-empty-state.messageNoResultSublineAfter') }}
                    </template>
                </sw-empty-state>
                <sw-empty-state
                    v-else
                    :title="$tc('sw-product.list.messageEmpty')"
                >
                    <template #icon>
                        <img
                            :src="assetFilter('/administration/static/img/empty-states/products-empty-state.svg')"
                            :alt="$tc('sw-product.list.messageEmpty')"
                        >
                    </template>
                </sw-empty-state>
            </template>
            {% endblock %}

        </div>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_product_list_content_clone_modal %}
        <sw-product-clone-modal
            v-if="cloning"
            :product="product"
            @clone-finish="onDuplicateFinish"
        />
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_product_list_content_variant_modal %}
        <sw-product-variant-modal
            v-if="showVariantModal"
            :product-entity="productEntityVariantModal"
            @modal-close="closeVariantModal"
        />
        {% endblock %}
    </template>

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_product_list_sidebar %}
    <template #sidebar>
        <sw-sidebar>
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_product_list_sidebar_refresh %}
            <sw-sidebar-item
                icon="regular-undo"
                :title="$tc('sw-product.list.titleSidebarItemRefresh')"
                @click="onRefresh"
            />
            {% endblock %}

            <sw-sidebar-filter-panel
                entity="product"
                :store-key="storeKey"
                :active-filter-number="activeFilterNumber"
                :filters="listFilters"
                :defaults="defaultFilters"
                @criteria-changed="updateCriteria"
            />
        </sw-sidebar>
    </template>
    {% endblock %}
</sw-page>
{% endblock %}
