{% 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 payment_text = payment_configuration['text'] ?? null %}
{% set is_paid = is_paid|default(cart.cartCheckout and cart.cartCheckout.payedAt) %}
{% set mail_translation_prefix = mail_translation_prefix|default(is_paid ? 'order.paid_mail' : 'order.offline_mail') %}
{% set requires_order_reference_for_payment = payment_method and payment_method.method in ['check', 'bankTransfert', 'banktransfert'] %}
{% 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.paymentOnline
        ? '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 %}
{% set reference_intro_translation_parameters = {
    '%payment_method%': payment_method_label ?: '-',
    '%reference%': reference
} %}
{{ (mail_translation_prefix ~ '.intro')|trans({}, null, locale|default('fr')) }}

{{ (mail_translation_prefix ~ '.reference_intro')|trans(reference_intro_translation_parameters, null, locale|default('fr')) }}

{{ (mail_translation_prefix ~ '.reference_label')|trans({}, null, locale|default('fr')) }}: {{ reference }}

{{ (mail_translation_prefix ~ '.attachment_notice')|trans({'%document%': document_label_lower }, null, locale|default('fr')) }}

{% if is_paid %}
{{ (mail_translation_prefix ~ '.payment_paid_heading')|trans({}, null, locale|default('fr')) }}
{{ (mail_translation_prefix ~ '.payment_paid_text')|trans({
    '%payment_method%': payment_method_label ?: '-',
    '%date%': cart.cartCheckout.payedAt|date('d/m/Y H:i')
}, null, locale|default('fr')) }}
{% else %}
{{ (mail_translation_prefix ~ '.payment_pending_heading')|trans({}, null, locale|default('fr')) }}
{{ (mail_translation_prefix ~ '.payment_pending_text')|trans({
    '%payment_method%': payment_method_label ?: '-'
}, null, locale|default('fr')) }}
{% if requires_order_reference_for_payment %}
{{ (mail_translation_prefix ~ '.offline_reference_notice')|trans({
    '%reference%': reference
}, null, locale|default('fr')) }}
{% endif %}
{% if payment_text %}
{{ payment_text|striptags|trim }}
{% else %}
{{ 'checkout_design.offline_payment_description_fallback'|trans({}, null, locale|default('fr')) }}
{% endif %}
{% endif %}

{{ (mail_translation_prefix ~ '.footer')|trans({'%company%': company }, null, locale|default('fr')) }}
