<!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
{% block sw_promotion_v2_cart_condition_form %}
<div class="sw-promotion-v2-cart-condition-form">

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_promotion_v2_cart_condition_form_rules_field %}
    <sw-promotion-v2-rule-select
        v-if="promotion"
        v-model:collection="promotion.cartRules"
        class="sw-promotion-v2-cart-condition-form__rule-select-cart"
        :local-mode="promotion.isNew()"
        :criteria="ruleFilter"
        :label="$tc('sw-promotion-v2.detail.conditions.preConditions.labelCartConditionSelect')"
        :placeholder="$tc('sw-promotion-v2.detail.conditions.preConditions.placeholderCartConditionSelect')"
        :rule-scope="['checkout', 'global', 'lineItem']"
        rule-aware-group-key="cartPromotions"
        :disabled="isEditingDisabled"
    />
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_promotion_v2_cart_condition_form_use_setgroups_field %}
    <sw-switch-field
        v-model:value="promotion.useSetGroups"
        class="sw-promotion-v2-cart-condition-form__use-setgroups"
        :disabled="!acl.can('promotion.editor')"
        :label="$tc('sw-promotion-v2.detail.conditions.setgroups.switchGroupsEnabled')"
    />
    {% endblock %}

    <template v-if="promotion.useSetGroups">

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_promotion_v2_cart_condition_setgroup_card %}
        <sw-card
            v-for="(group, index) in promotion.setgroups"
            :id="`sw-promotion-v2-cart-condition-form__setgroup-card-${index + 1}`"
            :key="group.id"
            position-identifier="sw-promotion-cart-condition-setgroup"
            class="sw-promotion-v2-cart-condition-form__setgroup-card"
        >

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

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_promotion_v2_cart_condition_setgroup_card_context_action_duplicate %}
                <sw-context-menu-item
                    :disabled="isEditingDisabled"
                    @click="duplicateSetGroup(group)"
                >
                    {{ $tc('global.default.duplicate') }}
                </sw-context-menu-item>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_promotion_v2_cart_condition_setgroup_card_context_action_delete %}
                <sw-context-menu-item
                    v-tooltip="{
                        message: $tc('sw-privileges.tooltip.warning'),
                        disabled: acl.can('promotion.editor'),
                        showOnDisabledElements: true
                    }"
                    variant="danger"
                    :disabled="isEditingDisabled"
                    @click="deleteSetGroup(group)"
                >
                    {{ $tc('global.default.delete') }}
                </sw-context-menu-item>
                {% endblock %}

            </template>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_promotion_v2_cart_condition_setgroup_card_title %}
            <div class="sw-promotion-v2-cart-condition-form__setgroup-card-title">
                {{ $tc('sw-promotion-v2.detail.conditions.setgroups.titleName') }} {{ index + 1 }}
            </div>
            {% endblock %}

            <sw-container
                columns="1fr 1fr"
                gap="0px 30px"
            >
                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_promotion_v2_cart_condition_setgroup_mode_field %}
                <sw-select-field
                    v-model:value="group.packagerKey"
                    class="sw-promotion-v2-cart-condition-form__setgroup-mode"
                    :label="$tc('sw-promotion-v2.detail.conditions.setgroups.labelMode')"
                    :disabled="isEditingDisabled"
                >
                    <option
                        v-for="packager in packagers"
                        :key="packager.key"
                        :value="packager.key"
                    >
                        {{ packager.name }}
                    </option>
                </sw-select-field>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_promotion_v2_cart_condition_setgroup_value_field %}
                <sw-number-field
                    v-model:value="group.value"
                    class="sw-promotion-v2-cart-condition-form__setgroup-value"
                    :label="$tc('sw-promotion-v2.detail.conditions.setgroups.labelValue')"
                    :disabled="isEditingDisabled"
                />
                {% endblock %}

            </sw-container>

            <sw-container
                columns="1fr 1fr"
                gap="0px 30px"
            >
                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_promotion_v2_cart_condition_setgroup_sorting_field %}
                <sw-select-field
                    v-model:value="group.sorterKey"
                    class="sw-promotion-v2-cart-condition-form__setgroup-sorting"
                    :label="$tc('sw-promotion-v2.detail.conditions.setgroups.labelSorting')"
                    :disabled="isEditingDisabled"
                >
                    <option
                        v-for="sorter in sorters"
                        :key="sorter.key"
                        :value="sorter.key"
                    >
                        {{ sorter.name }}
                    </option>
                </sw-select-field>
                {% endblock %}

            </sw-container>

            <sw-container
                columns="1fr"
                gap="0px 30px"
            >

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_promotion_v2_cart_condition_setgroup_rules_field %}
                <sw-promotion-v2-rule-select
                    v-model:collection="group.setGroupRules"
                    class="sw-promotion-v2-cart-condition-form__setgroup-rules"
                    :label="$tc('sw-promotion-v2.detail.conditions.setgroups.labelRules')"
                    :placeholder="$tc('sw-promotion-v2.detail.conditions.setgroups.placeholder')"
                    :criteria="ruleFilter"
                    :rule-scope="['checkout', 'global', 'lineItem']"
                    :disabled="isEditingDisabled"
                    rule-aware-group-key="promotionSetGroups"
                />
                {% endblock %}

            </sw-container>
        </sw-card>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_promotion_v2_cart_condition_add_group_button %}
        <div class="sw-promotion-v2-cart-condition-form__add-group-button-container">
            <sw-button
                variant="ghost"
                class="sw-promotion-v2-cart-condition-form__add-group-button"
                :disabled="isEditingDisabled"
                @click="addSetGroup"
            >
                {{ $tc('sw-promotion-v2.detail.conditions.setgroups.buttonAddGroup') }}
            </sw-button>
        </div>
        {% endblock %}

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