{% set payment_method = cart.paymentMethod ?: (cart.cartCheckout ? cart.cartCheckout.paymentMethod : null) %}
{% set payment_configuration = payment_method ? payment_method.configuration : {} %}
{% set configured_name = payment_configuration['name'] ?? null %}
{% set order_comment = cart.comment|default('')|trim %}
{% set pricing = cart.pricing %}
{% if configured_name %}
    {% set payment_method_label = '.' in configured_name ? configured_name|trans({}, null, locale|default('fr')) : configured_name %}
{% elseif payment_method %}
    {% set payment_method_label = payment_method.checkoutOnlineMethod
        ? 'checkout_design.payment_card'|trans({}, null, locale|default('fr'))
        : (payment_method.method in ['bankTransfert', 'banktransfert']
            ? 'checkout_design.payment_banktransfert'|trans({}, null, locale|default('fr'))
            : 'checkout_design.payment_check'|trans({}, null, locale|default('fr'))) %}
{% else %}
    {% set payment_method_label = null %}
{% endif %}
{% extends 'mail/_layout.html.twig' %}

{% block mail_subject %}{{ 'order.admin_mail.heading'|trans({}, null, locale|default('fr')) }}{% endblock %}
{% block mail_eyebrow %}{{ 'order.admin_mail.eyebrow'|trans({}, null, locale|default('fr')) }}{% endblock %}
{% block mail_heading %}{{ 'order.admin_mail.heading'|trans({}, null, locale|default('fr')) }}{% endblock %}
{% block mail_header_extra %}
    {% if payment_method_label %}
        <span style="display:block; margin:0 0 6px; font-size:11px; letter-spacing:0.18em; text-transform:uppercase; color:#8a6a2f;">
            {{ 'order.admin_mail.payment_label'|trans({}, null, locale|default('fr')) }}
        </span>
        <span style="display:block; font-family:Georgia, 'Times New Roman', serif; font-size:24px; line-height:1.2; color:#3f2f24;">
            {{ payment_method_label }}
        </span>
    {% endif %}
{% endblock %}

{% block mail_body %}
    <p style="margin:0 0 16px;">{{ 'order.admin_mail.intro'|trans({'%company%': company }, null, locale|default('fr')) }}</p>
    <p style="margin:0 0 24px;">{{ 'order.admin_mail.customer_intro'|trans({'%firstname%': cart.firstname|default(''), '%lastname%': cart.lastname|default('') }, null, locale|default('fr')) }}</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;">{{ 'order.admin_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>
                <div style="margin:18px 0 6px; font-size:11px; letter-spacing:0.18em; text-transform:uppercase; color:#8a6a2f;">{{ 'shop.total'|trans({}, null, locale|default('fr')) }}</div>
                <div style="font-family:Georgia, 'Times New Roman', serif; font-size:28px; line-height:1.2; color:#3f2f24;">{% if cart.total is not null %}{{ cart.total|price_format }} €{% else %}-{% endif %}</div>
            </td>
        </tr>
    </table>

    <p style="margin:0 0 16px;">{{ attachment_notice }}</p>
    <div style="margin:0 0 10px; font-size:11px; letter-spacing:0.18em; text-transform:uppercase; color:#8a6a2f;">{{ 'order.admin_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 %}
                <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;">
                        x{{ line.quantity }}<br>
                        {% 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>

    {% if order_comment != '' %}
        <div style="margin:0 0 10px; font-size:11px; letter-spacing:0.18em; text-transform:uppercase; color:#8a6a2f;">{{ 'checkout_design.info_title'|trans({}, null, locale|default('fr')) }}</div>
        <div class="email-block" style="margin:0 0 24px; padding:20px 22px; border:1px solid #eadfce; background:#fffaf5; color:#6e5848;">
            {{ order_comment|nl2br }}
        </div>
    {% endif %}
{% endblock %}
