{% set pricing = cart.pricing %}
{% set shipping = cart.cartShipping %}
{% set promos = cart.cartPromos ? cart.cartPromos.items : [] %}
{% extends 'mail/_layout.html.twig' %}

{% block mail_subject %}{{ 'delivery.mail.subject_mail'|trans({'%company%': company, '%ref%': reference }, null, locale|default('fr')) }}{% endblock %}
{% block mail_eyebrow %}{{ 'delivery.mail.eyebrow'|trans({}, null, locale|default('fr')) }}{% endblock %}
{% block mail_heading %}{{ 'delivery.mail.heading'|trans({}, null, locale|default('fr')) }}{% endblock %}

{% block mail_body %}
    <p style="margin:0 0 24px;">{{ 'delivery.mail.intro'|trans({'%ref%': reference }, null, locale|default('fr'))|nl2br }}</p>

    <table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="width:100%; margin:0 0 24px; border:1px solid #eadfce; background:#fcf7f0;">
        <tr>
            <td class="email-block" style="padding:18px 22px;">
                <div style="margin:0 0 6px; font-size:11px; letter-spacing:0.18em; text-transform:uppercase; color:#8a6a2f;">{{ 'delivery.mail.reference_label'|trans({}, null, locale|default('fr')) }}</div>
                <div style="font-family:Georgia, 'Times New Roman', serif; font-size:28px; line-height:1.2; color:#3f2f24;">{{ reference }}</div>
            </td>
        </tr>
    </table>

    <div style="margin:0 0 10px; font-size:11px; letter-spacing:0.18em; text-transform:uppercase; color:#8a6a2f;">{{ 'delivery.mail.details_heading'|trans({}, null, locale|default('fr')) }}</div>
    <table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="width:100%; margin:0 0 24px; border-top:1px solid #eadfce; border-bottom:1px solid #eadfce;">
        {% if pricing and pricing.lines is not empty %}
            {% for line in pricing.lines %}
                {% set line_previous_ttc = line.isPromoGift ? line.totalTTC : (line.degressiveTTC > 0 ? line.netTTC + line.degressiveTTC : null) %}
                <tr>
                    <td class="email-line-label" style="padding:16px 0; vertical-align:top; color:#3f2f24;">
                        <div>{{ line.productName }}</div>
                        {% if line.typeName or line.unitLabel %}
                            <div style="margin-top:4px; color:#6e5848; font-size:14px;">
                                {{ line.typeName }}{% if line.unitLabel %}{% if line.typeName %} ({{ line.unitLabel }}){% else %}{{ line.unitLabel }}{% endif %}{% endif %}
                            </div>
                        {% endif %}
                        {% if line.optionName %}
                            <div style="margin-top:4px; color:#6e5848; font-size:14px;">
                                {{ 'shop.option_label'|trans({}, null, locale|default('fr')) }} : {{ line.optionName }}
                                {% if line.optionTotalTTC > 0 %}
                                    (+{{ line.optionTotalTTC|price_format }} €)
                                {% endif %}
                            </div>
                        {% endif %}
                        {% if line.isPromoGift %}
                            <div style="margin-top:6px; color:#8a6a2f; font-size:14px;">{{ 'shop.offered'|trans({}, null, locale|default('fr')) }}</div>
                        {% endif %}
                        {% if line.degressiveTTC > 0 %}
                            <div style="margin-top:6px; color:#8a6a2f; font-size:14px;">{{ 'shop.degressive'|trans({}, null, locale|default('fr')) }} : -{{ line.degressiveTTC|price_format }} €</div>
                        {% endif %}
                    </td>
                    <td class="email-line-value" align="right" style="padding:16px 0 16px 16px; vertical-align:top; color:#3f2f24; white-space:nowrap;">
                        {{ 'delivery.mail.quantity_short'|trans({}, null, locale|default('fr')) }}{{ line.quantity }}<br>
                        {% if line_previous_ttc is not null and line_previous_ttc > line.netTTC %}
                            <span style="color:#8c7564; text-decoration:line-through;">{{ line_previous_ttc|price_format }} €</span><br>
                        {% endif %}
                        {% if line.isPromoGift %}
                            {{ 'shop.offered'|trans({}, null, locale|default('fr')) }}
                        {% else %}
                            {{ line.netTTC|price_format }} €
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
        {% else %}
            <tr>
                <td style="padding:16px 0; color:#6e5848;">{{ 'delivery.mail.details_empty'|trans({}, null, locale|default('fr')) }}</td>
            </tr>
        {% endif %}
    </table>

    <div style="margin:0 0 10px; font-size:11px; letter-spacing:0.18em; text-transform:uppercase; color:#8a6a2f;">{{ 'delivery.mail.summary_heading'|trans({}, null, locale|default('fr')) }}</div>
    <table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="width:100%; margin:0 0 24px; border-top:1px solid #eadfce; border-bottom:1px solid #eadfce;">
        <tr>
            <td class="email-line-label" style="padding:16px 0; vertical-align:top; color:#3f2f24;">{{ 'checkout_design.subtotal'|trans({}, null, locale|default('fr')) }}</td>
            <td class="email-line-value" align="right" style="padding:16px 0 16px 16px; vertical-align:top; color:#3f2f24;">{% if pricing %}{{ pricing.subtotalTTC|price_format }} €{% else %}-{% endif %}</td>
        </tr>
        {% if pricing and pricing.degressiveTTC > 0 %}
            <tr>
                <td class="email-line-label" style="padding:16px 0; vertical-align:top; color:#3f2f24;">{{ (pricing.degressiveIsBottleOffered ? 'shop.of_which_bottle_offered' : 'shop.of_which_degressive')|trans({}, null, locale|default('fr')) }}</td>
                <td class="email-line-value" align="right" style="padding:16px 0 16px 16px; vertical-align:top; color:#3f2f24;">-{{ pricing.degressiveTTC|price_format }} €</td>
            </tr>
        {% endif %}
        {% for promo in promos %}
            {% if promo.discountItemsTTC > 0 %}
                <tr>
                    <td class="email-line-label" style="padding:16px 0; vertical-align:top; color:#3f2f24;">
                        {{ 'shop.discount'|trans({}, null, locale|default('fr')) }}
                        <div style="margin-top:4px; color:#6e5848; font-size:14px;">{{ promo.code ?: 'Promo' }}{% if promo.percent is not null %} - {{ (promo.percent * 100)|number_format(0, ',', ' ') }}%{% endif %}</div>
                    </td>
                    <td class="email-line-value" align="right" style="padding:16px 0 16px 16px; vertical-align:top; color:#3f2f24;">-{{ promo.discountItemsTTC|price_format }} €</td>
                </tr>
            {% endif %}
        {% endfor %}
        <tr>
            <td class="email-line-label" style="padding:16px 0; vertical-align:top; color:#3f2f24;">{{ 'delivery.mail.delivery_label'|trans({}, null, locale|default('fr')) }}</td>
            <td class="email-line-value" align="right" style="padding:16px 0 16px 16px; vertical-align:top; color:#3f2f24;">
                {% if shipping is not null %}
                    {{ shipping.amountTTC|price_format }} €
                    {% if shipping.name %}<br><span style="color:#6e5848;">{{ shipping.name }}</span>{% endif %}
                {% else %}
                    -
                {% endif %}
            </td>
        </tr>
        {% for promo in promos %}
            {% if promo.discountShippingTTC > 0 %}
                <tr>
                    <td class="email-line-label" style="padding:16px 0; vertical-align:top; color:#3f2f24;">
                        {{ 'shop.discount_shipping'|trans({}, null, locale|default('fr')) }}
                        <div style="margin-top:4px; color:#6e5848; font-size:14px;">{{ promo.code ?: 'Promo' }}{% if promo.percent is not null %} - {{ (promo.percent * 100)|number_format(0, ',', ' ') }}%{% endif %}</div>
                    </td>
                    <td class="email-line-value" align="right" style="padding:16px 0 16px 16px; vertical-align:top; color:#3f2f24;">-{{ promo.discountShippingTTC|price_format }} €</td>
                </tr>
            {% endif %}
        {% endfor %}
        <tr>
            <td class="email-line-label" style="padding:16px 0; vertical-align:top; font-size:11px; letter-spacing:0.18em; text-transform:uppercase; color:#8a6a2f;">{{ 'checkout_design.total_ttc'|trans({}, null, locale|default('fr')) }}</td>
            <td class="email-line-value" align="right" style="padding:16px 0 16px 16px; vertical-align:top; font-family:Georgia, 'Times New Roman', serif; font-size:28px; line-height:1.2; color:#3f2f24;">{% if pricing %}{{ pricing.totalTTC|price_format }} €{% else %}-{% endif %}</td>
        </tr>
    </table>

    {% if cart.urlDeSuiviCarrier %}
        <p style="margin:0 0 24px;">{{ 'delivery.mail.tracking_intro'|trans({}, null, locale|default('fr')) }}</p>
        <table role="presentation" cellspacing="0" cellpadding="0" style="margin:0 auto 26px;">
            <tr>
                <td class="email-button" align="center" style="background:#3f2f24;">
                    <a href="{{ cart.urlDeSuiviCarrier }}"
                       style="display:inline-block; padding:16px 28px; color:#ffffff; text-decoration:none; font-size:11px; letter-spacing:0.22em; text-transform:uppercase; font-weight:600;">
                        {{ 'delivery.mail.tracking_cta'|trans({}, null, locale|default('fr')) }}
                    </a>
                </td>
            </tr>
        </table>

        <div class="email-block" style="margin:0 0 24px; padding:18px 22px; border:1px solid #eadfce; background:#fcf7f0;">
            <div style="margin:0 0 8px; font-size:11px; letter-spacing:0.18em; text-transform:uppercase; color:#8a6a2f;">{{ 'delivery.mail.tracking_fallback'|trans({}, null, locale|default('fr')) }}</div>
            <a href="{{ cart.urlDeSuiviCarrier }}" style="color:#8a5a34; word-break:break-word;">{{ cart.urlDeSuiviCarrier }}</a>
        </div>
    {% endif %}

    <p style="margin:0;">{{ 'delivery.mail.footer'|trans({'%company%': company }, null, locale|default('fr'))|nl2br }}</p>
{% endblock %}
