{% extends 'mail/_layout.html.twig' %}

{% block mail_subject %}{{ email_subject }}{% endblock %}
{% block mail_eyebrow %}{{ company }}{% endblock %}
{% block mail_heading %}{{ email_title }}{% endblock %}

{% block mail_body %}
    <p style="margin:0 0 26px; text-align:center;">
        {{ 'marketing.abandoned_cart.mail.intro'|trans({'%company%': company}, 'messages', locale|default('fr')) }}
    </p>

    <table role="presentation" width="100%" cellspacing="0" cellpadding="0" bgcolor="#fcf7f0" style="width:100%; margin:0 0 26px; border:1px solid #eadfce; background:#fcf7f0;">
        <tr>
            <td class="email-block" style="padding:22px 24px;">
                <div style="margin:0 0 12px; font-size:11px; letter-spacing:0.18em; text-transform:uppercase; color:#8a6a2f;">
                    {{ 'marketing.abandoned_cart.mail.cart_heading'|trans({}, 'messages', locale|default('fr')) }}
                </div>

                <table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="width:100%;">
                    {% for item in cart.items %}
                        {% set variant = item.variant %}
                        {% set product_name = variant ? (variant.fullName ?: (variant.product ? variant.product.fullName : '')) : '' %}
                        <tr>
                            <td class="email-product-name" style="padding:12px 12px 12px 0; border-bottom:1px solid #eadfce; vertical-align:top;">
                                <strong style="font-size:15px; line-height:1.5; color:#3f2f24;">{{ product_name ?: '-' }}</strong>
                                {% if item.selectedOptionName %}
                                    <div style="margin-top:4px; font-size:13px; line-height:1.5; color:#8c7564;">
                                        {{ 'shop.option_label'|trans({}, 'messages', locale|default('fr')) }} : {{ item.selectedOptionName }}
                                    </div>
                                {% endif %}
                            </td>
                            <td class="email-product-price" align="right" style="padding:12px 0; border-bottom:1px solid #eadfce; vertical-align:top; white-space:nowrap;">
                                <div style="font-size:13px; line-height:1.5; color:#8c7564;">
                                    {{ 'marketing.abandoned_cart.mail.cart_quantity'|trans({'%quantity%': item.quantity}, 'messages', locale|default('fr')) }}
                                    {{ item.finalPriceTTC|price_format }} €
                                </div>
                                <strong style="font-size:15px; line-height:1.5; color:#3f2f24;">{{ item.totalFinalTTC|price_format }} €</strong>
                            </td>
                        </tr>
                    {% endfor %}
                    <tr>
                        <td style="padding:16px 12px 0 0; font-size:14px; font-weight:700; color:#3f2f24;">
                            {{ 'marketing.abandoned_cart.mail.cart_subtotal'|trans({}, 'messages', locale|default('fr')) }}
                        </td>
                        <td align="right" style="padding:16px 0 0; font-family:Georgia, 'Times New Roman', serif; font-size:20px; color:#3f2f24; white-space:nowrap;">
                            {{ cart_subtotal_ttc|price_format }} €
                        </td>
                    </tr>

                    {% if has_existing_cart_discounts %}
                        <tr>
                            <td colspan="2" style="padding:22px 0 4px; font-size:11px; letter-spacing:0.16em; text-transform:uppercase; color:#8a6a2f;">
                                {{ 'marketing.abandoned_cart.mail.existing_discounts_heading'|trans({}, 'messages', locale|default('fr')) }}
                            </td>
                        </tr>
                        {% if cart_catalog_discount_ttc > 0 %}
                            <tr>
                                <td style="padding:8px 12px 0 0; font-size:14px; color:#8c7564;">
                                    {{ 'shop.discount'|trans({}, 'messages', locale|default('fr')) }}
                                </td>
                                <td align="right" style="padding:8px 0 0; font-size:14px; color:#8c7564; white-space:nowrap;">
                                    -{{ cart_catalog_discount_ttc|price_format }} €
                                </td>
                            </tr>
                        {% endif %}
                        {% if cart_degressive_discount_ttc > 0 %}
                            <tr>
                                <td style="padding:8px 12px 0 0; font-size:14px; color:#8c7564;">
                                    {{ (cart_degressive_is_bottle_offered ? 'shop.of_which_bottle_offered' : 'shop.of_which_degressive')|trans({}, 'messages', locale|default('fr')) }}
                                </td>
                                <td align="right" style="padding:8px 0 0; font-size:14px; color:#8c7564; white-space:nowrap;">
                                    -{{ cart_degressive_discount_ttc|price_format }} €
                                </td>
                            </tr>
                        {% endif %}
                        {% for cart_promo in existing_cart_promos %}
                            {% if cart_promo.discountItemsTTC > 0 %}
                                <tr>
                                    <td style="padding:8px 12px 0 0; font-size:14px; color:#8c7564;">
                                        {{ 'shop.discount'|trans({}, 'messages', locale|default('fr')) }}
                                        {% if cart_promo.code %} — {{ cart_promo.code }}{% endif %}
                                        {% if cart_promo.percent is not null %} — {{ (cart_promo.percent * 100)|number_format(0, ',', ' ') }}%{% endif %}
                                    </td>
                                    <td align="right" style="padding:8px 0 0; font-size:14px; color:#8c7564; white-space:nowrap;">
                                        -{{ cart_promo.discountItemsTTC|price_format }} €
                                    </td>
                                </tr>
                            {% endif %}
                            {% if cart_promo.discountShippingTTC > 0 %}
                                <tr>
                                    <td style="padding:8px 12px 0 0; font-size:14px; color:#8c7564;">
                                        {{ 'shop.discount_shipping'|trans({}, 'messages', locale|default('fr')) }}
                                        {% if cart_promo.code %} — {{ cart_promo.code }}{% endif %}
                                    </td>
                                    <td align="right" style="padding:8px 0 0; font-size:14px; color:#8c7564; white-space:nowrap;">
                                        -{{ cart_promo.discountShippingTTC|price_format }} €
                                    </td>
                                </tr>
                            {% endif %}
                        {% endfor %}
                    {% endif %}
                </table>
            </td>
        </tr>
    </table>

    {% if promo %}
        <table role="presentation" width="100%" cellspacing="0" cellpadding="0" bgcolor="#fffaf5" style="width:100%; margin:0 0 26px; border:1px solid #d8c7aa; background:#fffaf5;">
            <tr>
                <td class="email-block" align="center" style="padding:22px 24px; text-align:center;">
                    <div style="font-size:11px; letter-spacing:0.18em; text-transform:uppercase; color:#8a6a2f;">
                        {{ 'marketing.abandoned_cart.mail.coupon_heading'|trans({}, 'messages', locale|default('fr')) }}
                    </div>
                    <div style="margin-top:10px; font-family:Georgia, 'Times New Roman', serif; font-size:28px; line-height:1.2; letter-spacing:0.08em; color:#3f2f24;">{{ promo.title }}</div>
                    <div style="margin-top:10px; color:#3f2f24;">
                        {% if promo.amountTTC is not null %}
                            {{ 'marketing.abandoned_cart.mail.fixed_discount'|trans({'%amount%': promo.amountTTC|price_format}, 'messages', locale|default('fr')) }}
                        {% elseif promo.percent is not null %}
                            {{ (has_existing_cart_discounts ? 'marketing.abandoned_cart.mail.percent_discount_additional' : 'marketing.abandoned_cart.mail.percent_discount')|trans({'%percent%': (promo.percent * 100)|round(2)}, 'messages', locale|default('fr')) }}
                        {% elseif promo.percentShippingCost is not null %}
                            {{ 'marketing.abandoned_cart.mail.free_shipping'|trans({}, 'messages', locale|default('fr')) }}
                        {% endif %}
                    </div>
                    <div style="margin-top:14px; font-size:13px; line-height:1.6; color:#8c7564;">
                        {{ 'marketing.abandoned_cart.mail.coupon_cart_change_warning'|trans({}, 'messages', locale|default('fr')) }}
                    </div>
                </td>
            </tr>
        </table>
    {% endif %}

    <table role="presentation" cellspacing="0" cellpadding="0" align="center" style="margin:0 auto 24px;">
        <tr>
            <td class="email-button" align="center" bgcolor="#3f2f24" style="background:#3f2f24;">
                <a href="{{ recovery_url }}" style="display:inline-block; padding:16px 28px; color:#ffffff; font-size:12px; font-weight:700; letter-spacing:0.12em; text-decoration:none; text-transform:uppercase;">
                    {{ 'marketing.abandoned_cart.mail.button'|trans({}, 'messages', locale|default('fr')) }}
                </a>
            </td>
        </tr>
    </table>

    <p style="margin:0; text-align:center; font-size:13px; color:#8c7564;">
        {{ 'marketing.abandoned_cart.mail.expiry'|trans({'%date%': expires_at|date('d/m/Y')}, 'messages', locale|default('fr')) }}
    </p>
{% endblock %}
