{% import "@SyliusShop/Common/Macro/money.html.twig" as money %}

<table class="ui single line small table" id="sylius-product-variants" {{ sylius_test_html_attribute('product-variants') }}>
    <thead>
    <tr>
        <th>{{ 'sylius.ui.variant'|trans }}</th>
        <th>{{ 'sylius.ui.price'|trans }}</th>
        <th></th>
    </tr>
    </thead>
    <tbody>
    {% for key, variant in product.enabledVariants %}
        {% set channelPricing = variant.getChannelPricingForChannel(sylius.channel) %}
        <tr {{ sylius_test_html_attribute('product-variants-row') }}>
            <td>
                {{ variant.name|default(variant.descriptor) }}
                {% if product.hasOptions() %}
                    <div class="ui horizontal divided list">
                        {% for optionValue in variant.optionValues %}
                            <div class="item">
                                {{ optionValue.value }}
                            </div>
                        {% endfor %}
                    </div>
                {% endif %}
            </td>
            {% set appliedPromotions = channelPricing.appliedPromotions|map(promotion => ({'label': promotion.label, 'description': promotion.description})) %}
            {% set days = sylius.channel.channelPriceHistoryConfig.lowestPriceForDiscountedProductsCheckingPeriod %}
            {% set hasLowestPrice = variant|sylius_has_lowest_price({'channel': sylius.channel})%}
            {% set hasDiscount = variant|sylius_has_discount({'channel': sylius.channel}) %}

            <td class="sylius-product-variant-price"
                data-applied-promotions="{{ appliedPromotions|json_encode }}"
                {% if hasDiscount %}
                data-original-price="{{ money.calculateOriginalPrice(variant) }}"
                {% if hasLowestPrice %}
                    {% set lowestPriceBeforeDiscount = money.calculateLowestPrice(variant) %}
                    data-lowest-price-before-discount="{{
                    'sylius.ui.lowest_price_days_before_discount_was'|trans({
                        '%days%': days,
                        '%price%': lowestPriceBeforeDiscount
                    })
                    }}"
                {% endif %}
                {% endif %}>
                {{ money.calculatePrice(variant) }}
            </td>
            <td class="right aligned">
                {{ form_widget(form.cartItem.variant[key], {'label': false}) }}
            </td>
        </tr>
    {% endfor %}
    </tbody>
</table>
