{%- block _cart_items_entry_row -%}
    {% set cart = form.parent.parent.vars.data ?? null %}
    {% set pricing = cart ? cart.getPricing : null %}
    {% set pricing_line = null %}
    {% if pricing %}
        {% for line in pricing.lines %}
            {% if line.itemId == form.vars.data.id %}
                {% set pricing_line = line %}
            {% endif %}
        {% endfor %}
    {% endif %}

    {% set line_previous_ttc = pricing_line and pricing_line.degressiveTTC > 0 ? pricing_line.netTTC + pricing_line.degressiveTTC : null %}
    {% set product = form.vars.data.variant.product %}
    {% set product_image_path = pricing_line and pricing_line.imagePath ? pricing_line.imagePath : (product.secondImage and product.secondImage.path ? product.secondImage.path : (product.image and product.image.path ? product.image.path : null)) %}
    {% set product_title = pricing_line and pricing_line.productName ? pricing_line.productName : product.name %}
    {% set product_meta = pricing_line and (pricing_line.typeName or pricing_line.unitLabel)
        ? ((pricing_line.typeName ?: '') ~ (pricing_line.unitLabel ? ' (' ~ pricing_line.unitLabel ~ ')' : ''))
        : form.vars.data.variant.label
    %}
    {% set option_meta = pricing_line and pricing_line.optionName
        ? ('shop.option_label'|trans ~ ' : ' ~ pricing_line.optionName ~ (pricing_line.optionTotalTTC > 0 ? ' (+' ~ pricing_line.optionTotalTTC|price_format ~ ' €' ~ (pricing_line.optionFlatFee ? ', ' ~ ('shop.flat_fee'|trans|lower) : '') ~ ')' : ''))
        : null
    %}

    <div class="theme-cart-item" id="cart_{{ form.vars.data.id }}">
        <div class="theme-cart-item__media">
            {% if product_image_path %}
                <twig:Image
                    alt="{{ product_title }}"
                    class="theme-cart-item__picture"
                    img:class="theme-cart-item__image"
                    lazy="{{ false }}"
                    quality="{{ 70 }}"
                    responsive="{{ false }}"
                    path="{{ product_image_path }}"
                    imageWidth="220"
                    imageHeight="220"/>
            {% endif %}
        </div>

        <div class="theme-cart-item__content">
            <div class="theme-cart-item__header">
                <div class="theme-cart-item__details">
                    <div class="theme-cart-item__title">{{ product_title }}</div>
                    {% if product_meta %}
                        <div class="theme-cart-item__meta">{{ product_meta }}</div>
                    {% endif %}
                    {% if option_meta %}
                        <div class="theme-cart-item__option">{{ option_meta }}</div>
                    {% endif %}
                </div>

                <button
                    type="button"
                    class="theme-cart-item__delete"
                    data-action="live#action:prevent"
                    data-live-action-param="debounce(300)|deleteItem"
                    data-loading="action(deleteItem)|addAttribute(disabled)"
                    data-live-id-param="{{ form.vars.data.id }}"
                    aria-label="{{ 'content.delete_cart'|trans }}">
                    <svg aria-hidden="true" viewBox="0 0 24 24" focusable="false">
                        <path d="M9 3h6l1 2h4v2H4V5h4l1-2Zm-3 6h12l-1 12H7L6 9Zm3 2v8h2v-8H9Zm4 0v8h2v-8h-2Z"/>
                    </svg>
                </button>
            </div>

            {% if pricing_line and pricing_line.degressiveTTC > 0 %}
                <div class="theme-cart-item__discount">
                    <span>{{ 'shop.degressive'|trans }}</span>
                    <span> : -{{ pricing_line.degressiveTTC|price_format }} €</span>
                </div>
            {% endif %}

            <div class="theme-cart-item__footer" id="qty-{{ form.vars.name }}-{{ form.quantity.vars.errors|length }}">
                <div data-controller="quantity-stepper" class="theme-cart-quantity">
                    <label class="sr-only" for="{{ form.quantity.vars.id }}">{{ 'shop.quantity'|trans }}</label>
                    <button
                        type="button"
                        class="theme-cart-quantity__button"
                        data-action="quantity-stepper#decrement"
                        data-loading="action(updateItemQuantity)|addAttribute(disabled)"
                        aria-controls="{{ form.quantity.vars.id }}"
                        aria-label="{{ 'shop.quantity'|trans }} -">
                        -
                    </button>
                    {{ form_widget(form.quantity, {
                        attr: {
                            class: 'theme-cart-quantity__input',
                            inputmode: 'numeric',
                            'data-model': 'norender|' ~ form.quantity.vars.full_name,
                            'data-quantity-stepper-target': 'input',
                            'data-action': 'input->quantity-stepper#syncDisplay change->quantity-stepper#syncDisplay change->live#action:prevent',
                            'data-live-action-param': 'debounce(300)|updateItemQuantity',
                            'data-loading': 'action(updateItemQuantity)|addAttribute(disabled)'
                        }
                    }) }}
                    <button
                        type="button"
                        class="theme-cart-quantity__button"
                        data-action="quantity-stepper#increment"
                        data-loading="action(updateItemQuantity)|addAttribute(disabled)"
                        aria-controls="{{ form.quantity.vars.id }}"
                        aria-label="{{ 'shop.quantity'|trans }} +">
                        +
                    </button>
                </div>

                <div class="theme-cart-item__price">
                    {% if line_previous_ttc is not null and line_previous_ttc > pricing_line.netTTC %}
                        <span class="theme-cart-item__price-old">{{ line_previous_ttc|price_format }}</span>
                    {% elseif form.vars.data.isDiscounted %}
                        <span class="theme-cart-item__price-old">{{ form.vars.data.getTotalTTC|price_format }}</span>
                    {% endif %}
                    <span>{{ (pricing_line ? pricing_line.netTTC : form.vars.data.getTotalFinalTTC)|price_format }} €</span>
                </div>
            </div>
        </div>
    </div>
{%- endblock -%}
