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

{# Start added by spawntree #}
{% block component_offcanvas_cart_item_container %}
    {% if isCustomizedProduct %}
        {% set isNested = false %}
        {% for child in lineItem.children %}
            {% if child.type == 'product' %}
                {% set label = child.label %}
                {% set referencedId = child.referencedId %}
                {% set productNumber = lineItem.payload|merge({ 'productNumber': child.payload.productNumber }) %}

                {% if child.cover.url %}
                    {% set cover = child.cover %}
                {% endif %}

                {% do lineItem.setLabel(label) %}
                {% do lineItem.setCover(cover) %}
                {% do lineItem.setReferencedId(referencedId) %}
                {% do lineItem.setPayload(productNumber) %}
            {% endif %}
        {% endfor %}
    {% endif %}

    {% set isDiscountableItem = false %}    
    {% if lineItem.payload is defined and lineItem.payload.customFields is defined and
        lineItem.payload.customFields.spwn_discountable_box is defined %}
        {% set isDiscountableItem = true %}
    {% endif %}
    <div class="cart-item cart-item-{{ type }}{% if isDiscount %} is-discount{% endif %}{{ cartItemClasses }} js-cart-item{% if isDiscountableItem %} is-discountable-item{% endif %}">
        <div class="row cart-item-row">
            {{ block('component_offcanvas_product_image') }}
            {{ block('component_offcanvas_product_details') }}
            {{ block('component_offcanvas_product_remove') }}
            {{ block('component_offcanvas_children') }}
        </div>
    </div>
{% endblock %}

{% block component_offcanvas_children %}
    {% if isNested %}
        {# @deprecated tag:v6.5.0 - block will be removed, use `component_offcanvas_item_children` in `@Storefront/storefront/component/checkout/offcanvas-item-children.html.twig` instead #}
        {% block component_offcanvas_cart_item_children %}
            {% sw_include childrenTemplate %}
        {% endblock %}
    {% endif %}
	{% set addCustomizedProducts = addCustomizedProducts | default(0) %}
    {% if lineItem.payload is defined and lineItem.payload.customFields is defined and
        lineItem.payload.customFields.spwn_discountable_box is defined and addCustomizedProducts !== 0 %}
        <div class="spwn-add-customized-products">
            <a href="/Abnehmprogramme/" class="spwn-add-customized-products-detail">{{ "checkout.diaekoItemNotice"|trans|sw_sanitize }}</a>
            {% if addCustomizedProducts == 1 %}
                <a href="/Abnehmprogramme/" class="spwn-add-customized-products-detail">{{ "checkout.diaekoItemNotice"|trans|sw_sanitize }}</a>
            {% endif %}
        </div>
    {% endif %}
{% endblock %}

{% block component_offcanvas_product_label %}
    <div class="cart-item-details">
        {% if type == PRODUCT_LINE_ITEM_TYPE %}
            <a href="{{ seoUrl('frontend.detail.page', {'productId': referencedId}) }}"
               class="cart-item-label"
               title="{{ label|replace({'&amp;':'&'}) }}">
                {{ quantity }}{{ "checkout.quantityTimes"|trans|sw_sanitize }} {{ label|replace({'&amp;':'&'})|u.truncate(60, '...', false) }}
            </a>
        {% else %}
            <div class="cart-item-label">
                {{ label|replace({'&amp;':'&'})|u.truncate(60, '...', false) }}
            </div>
        {% endif  %}
    </div>
{% endblock %}

{# coming from AtlProductConfigurator #}
{% block cart_item_variant_characteristics %}
    <div class="cart-item-characteristics">
       {% for input in lineItem.payload.atlProductConfigurator %}
            <div>
                <span class="cart-item-characteristics-option">{{ input.value }}</span>
            </div>
        {% endfor %}
    </div>
{% endblock %}
{# End added by spawntree #}
