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

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_promotion_v2_search_bar %}
    <template #search-bar>
        <sw-search-bar
            initial-search-type="promotion"
            :placeholder="$tc('sw-promotion-v2.list.placeholderSearchBar')"
            :initial-search="term"
            @search="onSearch"
        />
    </template>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_promotion_v2_list_smart_bar_header %}
    <template #smart-bar-header>

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

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_promotion_v2_list_smart_bar_header_title_text %}
            {{ $tc('sw-promotion-v2.list.textTitle') }}
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_promotion_v2_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_promotion_v2_list_smart_bar_actions %}
    <template #smart-bar-actions>

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_promotion_v2_list_smart_bar_actions_add %}
        <sw-button
            v-tooltip="addButtonTooltip"
            class="sw-promotion-v2-list__smart-bar-button-add"
            variant="primary"
            :router-link="{ name: 'sw.promotion.v2.create' }"
            :disabled="!acl.can('promotion.creator') || undefined"
        >
            {{ $tc('sw-promotion-v2.list.buttonAddPromotion') }}
        </sw-button>
        {% endblock %}

    </template>
    {% endblock %}

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

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

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_promotion_v2_list_grid %}
            <sw-entity-listing
                v-if="entitySearchable"
                :repository="promotionRepository"
                :columns="promotionColumns"
                :items="promotions"
                detail-route="sw.promotion.v2.detail"
                :is-loading="isLoading"
                :allow-inline-edit="acl.can('promotion.editor') || undefined"
                :show-selection="acl.can('promotion.deleter') || undefined"
                :allow-edit="acl.can('promotion.editor') || undefined"
                :allow-view="acl.can('promotion.viewer') || undefined"
                allow-column-edit
                full-page
                @update-records="updateTotal"
                @selection-change="updateSelection"
            >

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_promotion_v2_list_grid_columns %}
                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_promotion_v2_list_grid_columns_active %}
                <template #column-active="{ item }">
                    <sw-icon
                        v-if="item.active"
                        class="sw-promotion-v2-list__icon-activity is--active"
                        name="regular-checkmark-xs"
                    />
                    <sw-icon
                        v-else
                        class="sw-promotion-v2-list__icon-activity is--inactive"
                        name="regular-times-s"
                    />
                </template>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_promotion_v2_list_grid_columns_valid_from %}
                <template #column-validFrom="{ item }">
                    {{ dateFilter(item.validFrom, { hour: '2-digit', minute: '2-digit' }) }}
                </template>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_promotion_v2_list_grid_columns_valid_until %}
                <template #column-validUntil="{ item }">
                    {{ dateFilter(item.validUntil, { hour: '2-digit', minute: '2-digit' }) }}
                </template>
                {% endblock %}
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_promotion_v2_list_grid_columns_actions %}
                <template #more-actions="{ item }">
                    {% block sw_promotion_v2_list_grid_columns_actions_duplicate %}
                    <sw-context-menu-item
                        :disabled="!acl.can('promotion.creator')"
                        @click="onDuplicatePromotion(item)"
                    >
                        {{ $tc('global.default.duplicate') }}
                    </sw-context-menu-item>
                    {% endblock %}
                </template>

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_promotion_v2_list_grid_columns_actions_delete %}
                <template #delete-action="{ item, showDelete }">
                    <sw-context-menu-item
                        variant="danger"
                        :disabled="(item && item.orderCount > 0) || !acl.can('promotion.deleter') || undefined"
                        @click="showDelete(item.id)"
                    >
                        {{ $tc('global.default.delete') }}
                    </sw-context-menu-item>
                </template>
                {% endblock %}
                {% endblock %}

            </sw-entity-listing>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_promotion_v2_list_empty_state %}
            <template v-if="!isLoading && !total">
                <sw-promotion-v2-empty-state-hero
                    v-if="isValidTerm(term)"
                    :title="$tc('sw-empty-state.messageNoResultTitle')"
                    :description="$tc('sw-empty-state.messageNoResultSubline')"
                />
                <sw-promotion-v2-empty-state-hero
                    v-else
                    :title="$tc('sw-promotion-v2.list.titleEmpty')"
                    :description="$tc('sw-promotion-v2.list.descriptionEmpty')"
                >

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_promotion_v2_list_empty_state_actions %}
                    <template #actions>
                        <sw-button
                            v-tooltip="addButtonTooltip"
                            class="sw-promotion-v2-list__empty-state-button-add"
                            variant="primary"
                            :router-link="{ name: 'sw.promotion.v2.create' }"
                            :disabled="!acl.can('promotion.creator') || undefined"
                        >
                            {{ $tc('sw-promotion-v2.list.buttonAddPromotion') }}
                        </sw-button>
                    </template>
                    {% endblock %}

                </sw-promotion-v2-empty-state-hero>
            </template>
            {% endblock %}

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

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

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

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

</sw-page>
{% endblock %}
