{% sw_extends '@Storefront/storefront/page/checkout/cart/index.html.twig' %}

{% block page_checkout_cart_add_promotion_submit %}
    <div class="input-group-append">
        <button class="btn btn-secondary"
                type="submit"
                id="addPromotion">
            {% sw_icon 'arrow-head-right' %}
        </button>
    </div>
{% endblock %}

{% block page_checkout_cart_product_table %}
    {% set customizedProductsCount = 0 %}
    {% set customizedProductsCountTemp = 0 %}
    {% set addCustomizedProducts = 0 %}

    {% for lineItem in page.cart.lineItems %}
        {% if lineItem.payload is defined and lineItem.payload.customFields is defined and
            lineItem.payload.customFields.spwn_discountable_box is defined %}
            {% set customizedProductsCount = customizedProductsCount + lineItem.quantity %}
        {% endif %}
    {% endfor %}
    
    <div class="card checkout-product-table">
        <div class="card-body">
            {% block page_checkout_cart_table_header %}
                {% sw_include '@Storefront/storefront/page/checkout/cart/cart-product-header.html.twig' %}
            {% endblock %}

            {% block page_checkout_cart_table_items %}
                {% for lineItem in page.cart.lineItems %}
                
                    {% if lineItem.payload.customFields.spwn_discountable_box %}
                    
                        {% if lineItem.payload is defined and lineItem.payload.customFields is defined and
                            lineItem.payload.customFields.spwn_discountable_box is defined and customizedProductsCount < 3 %}
                            {% set customizedProductsCountTemp = customizedProductsCountTemp + lineItem.quantity %}
                            {% if customizedProductsCountTemp == customizedProductsCount %}
                                {% set addCustomizedProducts = customizedProductsCount %}
                            {% endif %}
                        {% endif %}
                        {% block page_checkout_cart_table_item %}
                            {% block page_checkout_item %}
                                {% sw_include '@Storefront/storefront/page/checkout/checkout-item.html.twig' with {
                                    data: {
                                        addCustomizedProducts: addCustomizedProducts
                                    }
                                } %}
                            {% endblock %}
                        {% endblock %}
                    {% endif %}
                {% endfor %}
                {% set addCustomizedProducts = 0 %}
                {% for lineItem in page.cart.lineItems %}
                    {% if not lineItem.payload.customFields.spwn_discountable_box %}
                        {{ block ('page_checkout_item') }}
                    {% endif %}
                {% endfor %}
            {% endblock %}
        </div>
    </div>
{% endblock %}

{% block page_checkout_cart_shipping_costs %}
{% endblock %}
