{% form_theme form with app_form_themes()|merge(['extends/form/cart/cart.html.twig']) only %}
<div {{ attributes.defaults({ class: 'theme-cart-form' }) }}>
    {% if deleteItemId %}
        <turbo-stream action="remove" target="cart_{{ deleteItemId }}"> </turbo-stream>
    {% endif %}
    {% if form.vars.data == null or form.vars.data.getQuantity == 0 %}
        <div class="theme-cart-form__empty" id="cart">
            <div>{{ 'cart.cart-empty'|trans }}</div>
            <a href="{{ path('shop') }}" class="theme-button-fill theme-hover-link-effect">
                {{ 'cart.discover'|trans }}
            </a>
        </div>
        <turbo-stream action="update" targets=".cart-items-count">
            <template>0</template>
        </turbo-stream>
    {% else %}
        <div class="theme-cart-form__filled" id="cart">
            {{ form_start(form, {'attr': {'data-model': 'debounce(300)|on(change)|*', 'class': 'theme-cart-form__form'}}) }}

            <div class="theme-cart-form__items" data-cart-scroll-container>
                {% set visibleQuantityProgressRules = quantityProgressRules|filter(rule => not rule.isComplete) %}

                {% if visibleQuantityProgressRules is not empty %}
                    {% set deliverySourceLabel = '' %}
                    {% for rule in visibleQuantityProgressRules %}
                        {% if deliverySourceLabel is empty and rule.sourceLabel is not empty %}
                            {% set deliverySourceLabel = rule.sourceLabel %}
                        {% endif %}
                    {% endfor %}

                    <div class="theme-cart-rules" data-cart-rules>
                        {% if not shippingCountryRulePending and deliverySourceLabel is not empty %}
                            <div class="theme-cart-rules__source">{{ deliverySourceLabel }}</div>
                        {% endif %}

                        {% for rule in visibleQuantityProgressRules %}
                            <div class="theme-cart-rules__item">
                                <div class="theme-cart-rules__label">
                                    <div>
                                        <span>{{ rule.title }} :</span>
                                        <span>{{ rule.requirementLabel }}</span>
                                    </div>
                                    <strong>{{ rule.currentQuantity }}/{{ rule.targetQuantity }}</strong>
                                </div>
                                <div class="theme-cart-rules__track">
                                    <div style="width: {{ rule.progressPercent }}%"></div>
                                </div>
                            </div>
                        {% endfor %}
                    </div>
                {% endif %}

                {{ form_widget(form.items, {'attr' : { 'class': 'theme-cart-form__item-list' }}) }}
                {{ form_rest(form) }}
            </div>

            <div class="theme-cart-form__summary">
                <div>
                    <span>{{ 'cart.subtotal'|trans() }}</span>
                    <strong>{{ form.vars.data.getPricing.subtotalTTC|price_format }} €</strong>
                </div>
                {% if form.vars.data.getPricing.degressiveTTC > 0 %}
                    <div>
                        <span>{{ (form.vars.data.getPricing.degressiveIsBottleOffered ? 'shop.of_which_bottle_offered' : 'shop.of_which_degressive')|trans() }}</span>
                        <strong>-{{ form.vars.data.getPricing.degressiveTTC|price_format }} €</strong>
                    </div>
                {% endif %}
                <div>
                    <span>{{ 'cart.delivery'|trans() }}</span>
                    <strong>{{ 'cart.undefined'|trans() }}</strong>
                </div>
                <div class="theme-cart-form__total">
                    <span>{{ 'shop.total_ttc'|trans }}</span>
                    <strong>{{ form.vars.data.getPricing.subtotalTTC|price_format }} €</strong>
                </div>
                <button
                    type="submit"
                    data-action="live#action:prevent"
                    data-live-action-param="debounce(300)|submitCart"
                    class="theme-button-fill theme-hover-link-effect">
                    {{ 'cart.button'|trans() }}
                </button>
            </div>

            {{ form_end(form) }}
        </div>
        <turbo-stream action="update" targets=".cart-items-count">
            <template>{{ form.vars.data.getQuantity }}</template>
        </turbo-stream>
    {% endif %}
</div>
