<!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
{% block sw_promotion_v2_settings_discount_type %}
<div class="sw-promotion-v2-settings-discount-type">
    <sw-container
        columns="1fr 1fr"
        gap="20px"
    >

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_promotion_v2_settings_discount_type_type %}
        <sw-select-field
            v-model:value="discount.type"
            class="sw-promotion-v2-settings-discount-type__field-select-discount-type"
            :label="$tc('sw-promotion-v2.detail.discounts.settings.discountType.labelDiscountType')"
            :disabled="!acl.can('promotion.editor')"
        >

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_promotion_v2_settings_discount_type_type_options %}
            <option
                v-for="selection in getDiscountTypeSelection()"
                :key="selection.value"
                :disabled="selection.disabled"
                :value="selection.value"
            >
                {{ selection.display }}
            </option>
            {% endblock %}

        </sw-select-field>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_promotion_v2_settings_discount_type_price %}
        <sw-number-field
            v-model:value="discount.value"
            class="sw-promotion-v2-settings-discount-type__field-price"
            :id-suffix="discount.id"
            :min="0"
            :max="discount.type === 'percentage' ? 100 : null"
            :label="labelValue"
            :disabled="discount.type === 'free' || !acl.can('promotion.editor')"
        >

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_promotion_v2_settings_discount_type_price_suffix %}
            <template #suffix>
                <span v-if="isPercentageType">%</span>
                <span v-else>{{ currencySymbol }}</span>
            </template>
            {% endblock %}

        </sw-number-field>
        {% endblock %}

    </sw-container>

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

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_promotion_v2_settings_discount_type_apply_discount_to %}
        <sw-select-field
            v-model:value="discount.applierKey"
            class="sw-promotion-v2-settings-discount-type__field-apply-discount-to"
            :label="$tc('sw-promotion-v2.detail.discounts.settings.discountType.labelApplyDiscountTo')"
            :disabled="discount.type === 'free' || !acl.can('promotion.editor')"
        >

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_promotion_v2_settings_discount_type_apply_discount_to_options %}
            <option
                v-for="selection in getApplyDiscountToSelection()"
                :key="selection.value"
                :disabled="selection.disabled"
                :value="selection.value"
            >
                {{ selection.display }}
            </option>
            {% endblock %}

        </sw-select-field>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_promotion_v2_settings_discount_type_max_discount_value %}
        <sw-number-field
            v-model:value="discount.maxValue"
            class="sw-promotion-v2-settings-discount-type__field-max-discount"
            :id-suffix="discount.id"
            :label="$tc('sw-promotion-v2.detail.discounts.settings.discountType.labelMaxDiscountValue')"
            :disabled="discount.type !== 'percentage' || !acl.can('promotion.editor')"
            allow-empty
            @update:value="onMaxValueChanged"
        >

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_promotion_v2_settings_discount_type_max_discount_value_suffix %}
            <template #suffix>
                <span>{{ currencySymbol }}</span>
            </template>
            {% endblock %}

        </sw-number-field>
        {% endblock %}

    </sw-container>

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_promotion_v2_settings_discount_type_advanced_prices_link %}
    <a
        v-if="showAdvancedPricesLink"
        class="sw-promotion-v2-settings-discount-type__advanced-prices"
        role="button"
        tabindex="0"
        @click="onClickAdvancedPrices"
        @keydown.enter="onClickAdvancedPrices"
    >
        {{ $tc('sw-promotion-v2.detail.discounts.pricesModal.linkAdvancedPrices') }}
        <sw-icon
            name="regular-long-arrow-right"
            small
        />
    </a>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_promotion_v2_settings_discount_type_advanced_prices_modal %}
    <sw-modal
        v-if="displayAdvancedPricesModal"
        :title="$tc('sw-promotion-v2.detail.discounts.pricesModal.advancedPricesHeader')"
        class="sw-promotion-v2-settings-discounts-type__advanced-prices-modal"
        @modal-close="onCloseAdvancedPricesModal"
    >

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_promotion_v2_settings_discount_type_advanced_prices_modal_grid %}
        <sw-one-to-many-grid
            :collection="discount.promotionDiscountPrices"
            :local-mode="true"
            :columns="currencyPriceColumns"
            :show-selection="false"
            :show-actions="!acl.can('promotion.editor')"
        >

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_promotion_v2_settings_discount_type_advanced_prices_modal_grid_column_name %}
            <template #column-currency.translated.name="{ item }">
                <p class="sw-promotion-v2-settings-discounts-type__advances-prices-column-name">
                    {{ item.currency.translated.name }}
                </p>
            </template>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_promotion_v2_settings_discount_type_advanced_prices_modal_grid_column_price %}
            <template #column-price="{ item }">
                <sw-number-field
                    v-model:value="item.price"
                    class="sw-promotion-v2-settings-discounts-type__advanced-prices-column-price"
                    type="text"
                    size="small"
                    :disabled="!acl.can('promotion.editor')"
                >

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_promotion_v2_settings_discount_type_advanced_prices_modal_grid_column_price_suffix %}
                    <template #suffix>
                        {{ item.currency.symbol }}
                    </template>
                    {% endblock %}

                </sw-number-field>
            </template>
            {% endblock %}

        </sw-one-to-many-grid>
        {% endblock %}

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

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_promotion_v2_settings_discount_type_advanced_prices_modal_footer_button_close %}
            <sw-button
                variant="primary"
                size="small"
                @click="onCloseAdvancedPricesModal"
            >
                {{ $tc('sw-promotion-v2.detail.discounts.pricesModal.closeModal') }}
            </sw-button>
            {% endblock %}

        </template>
        {% endblock %}

    </sw-modal>
    {% endblock %}

</div>
{% endblock %}
