{% sw_extends '@Storefront/storefront/component/checkout/offcanvas-cart.html.twig' %}

{# Start added by spawntree #}
{% block component_offcanvas_cart_items %}
    {% set customizedProductsCount = 0 %}
    {% set customizedProductsCountTemp = 0 %}
    {% set addCustomizedProducts = 0 %}

    {# copy from SpnoSortBasket #}
    {% set sortBasketConfig = context.extensions.SpnoSortBasket %}

    {% 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="offcanvas-cart-items">
{#         spawntree start #}
        {% if customizedProductsCount == 1 || customizedProductsCount == 2 || customizedProductsCount > 3 %}
            <div class="spwn-customized-products{% if customizedProductsCount > 3 %} spwn-c-p-more{% endif %}">
                {% sw_icon 'checkmark-circle' %}
                <div class="spwn-customized-products--text">
                {% if customizedProductsCount == 1 %}
                    {{ "checkout.diaekoProgramNoticeFirst"|trans|sw_sanitize }}
                {% elseif customizedProductsCount == 2 %}
                    {{ "checkout.diaekoProgramNoticeSecond"|trans|sw_sanitize }}
                {% elseif customizedProductsCount > 3 %}
                    {{ "checkout.diaekoProgramNoticeMore"|trans|sw_sanitize }}
                {% endif %}
                </div>
            </div>
        {% endif %}
{#         spawntree end #}
        {% for lineItem in page.cart.lineItems %}
{#                 spawntree start #}
            {% 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 component_offcanvas_cart_item %}
                    {% sw_include '@Storefront/storefront/component/checkout/offcanvas-item.html.twig' with {
                        data: {
                            addCustomizedProducts: addCustomizedProducts
                        }
                    } %}
                {% endblock %}
            {% endif %}
{#                 spawntree end #}
        {% endfor %}
        {% set addCustomizedProducts = 0 %}
        {% for lineItem in page.cart.lineItems %}
            {% if not lineItem.payload.customFields.spwn_discountable_box %}
                {{ block ('component_offcanvas_cart_item') }}
            {% endif %}
        {% endfor %}
    </div>
{% endblock %}

{% block component_offcanvas_cart_actions_promotion_submit %}
    <div class="input-group-append">
        <button class="btn btn-secondary"
                type="submit"
                id="addPromotionOffcanvasCart">
            {% sw_icon 'arrow-head-right' %}
        </button>
    </div>
{% endblock %}
{# End added by spawntree #}
