{% extends 'layout/checkout.html.twig' %}

{% block title %}{% trans from 'meta' %}checkout.title{% endtrans %}{% endblock %}

{% block main %}
    {% set pricing = cart.getPricing %}
    {% set checkout = cart.cartCheckout %}
    {% set payment_method = cart.paymentMethod %}
    {% set payment_configuration = payment_method ? payment_method.configuration : {} %}
    {% set payment_method_label = payment_configuration['name'] ?? payment_page_title_key|trans %}
    {% set payment_text = payment_configuration['text'] ?? null %}
    {% set order_date = checkout and checkout.orderedAt ? checkout.orderedAt : cart.updatedAt %}

    <section class="theme-checkout-page">
        <div class="theme-checkout-container">
            <article class="theme-checkout-confirmation">
                <header class="theme-checkout-confirmation__header">
                    <p class="theme-checkout-eyebrow">{{ 'checkout_design.offline_badge'|trans }}</p>
                    <h1>{{ 'checkout_design.offline_title'|trans }}</h1>
                    <p>
                        {{ 'checkout_design.offline_notice'|trans({
                            '%reference%': cart.token,
                            '%payment_method%': payment_method_label
                        }) }}
                    </p>
                </header>

                <div class="theme-checkout-confirmation__body">
                    <div class="theme-checkout-confirmation__grid">
                        <div class="theme-checkout-confirmation__main">
                            <section class="theme-checkout-card">
                                <h2>{{ 'checkout_design.offline_instructions'|trans }}</h2>
                                <dl class="theme-checkout-details">
                                    <div>
                                        <dt>{{ 'checkout_design.paid_method'|trans }}</dt>
                                        <dd>{{ payment_method_label }}</dd>
                                    </div>
                                    <div>
                                        <dt>{{ 'account_page.order.ordered_at'|trans }}</dt>
                                        <dd>{{ order_date ? order_date|date('d/m/Y H:i') : '-' }}</dd>
                                    </div>
                                    <div>
                                        <dt>{{ 'checkout_design.success_order_number'|trans }}</dt>
                                        <dd>{{ cart.token }}</dd>
                                    </div>
                                    {% if cart.deliveryMethod %}
                                        <div>
                                            <dt>{{ 'checkout_design.success_delivery_method'|trans }}</dt>
                                            <dd>{{ cart.deliveryMethod.name }}</dd>
                                        </div>
                                    {% endif %}
                                </dl>

                                <div class="theme-checkout-instructions">
                                    {% if payment_text %}
                                        {{ payment_text|raw }}
                                    {% else %}
                                        <p>{{ 'checkout_design.offline_payment_description_fallback'|trans }}</p>
                                    {% endif %}
                                </div>
                            </section>

                            <section class="theme-checkout-card">
                                <h2>{{ 'checkout_design.success_summary'|trans }}</h2>
                                <div class="theme-checkout-lines">
                                    {% if pricing and pricing.lines is not empty %}
                                        {% for line in pricing.lines %}
                                            <div class="theme-checkout-line">
                                                <div>
                                                    <strong>{{ line.productName }}</strong>
                                                    <span>
                                                        {{ line.quantity }} x {{ line.variantFullName ?: line.typeName ?: line.unitLabel ?: '' }}
                                                    </span>
                                                    {% if line.optionName %}
                                                        <span>
                                                            {{ 'shop.option_label'|trans }} : {{ line.optionName }}
                                                            {% if line.optionTotalTTC > 0 %}
                                                                · +{{ line.optionTotalTTC|price_format }} €
                                                            {% endif %}
                                                        </span>
                                                    {% endif %}
                                                </div>
                                                <strong>
                                                    {% if line.isPromoGift or line.netTTC <= 0 %}
                                                        {{ 'shop.offered'|trans }}
                                                    {% else %}
                                                        {{ line.netTTC|price_format }} €
                                                    {% endif %}
                                                </strong>
                                            </div>
                                        {% endfor %}
                                    {% else %}
                                        {% for item in cart.items %}
                                            <div class="theme-checkout-line">
                                                <div>
                                                    <strong>{{ item.variant.product.name }}</strong>
                                                    <span>{{ item.quantity }} x {{ item.variant.name ?: item.variant.type.name ?: '' }}</span>
                                                </div>
                                                <strong>
                                                    {% if item.totalFinalTTC <= 0 %}
                                                        {{ 'shop.offered'|trans }}
                                                    {% else %}
                                                        {{ item.totalFinalTTC|price_format }} €
                                                    {% endif %}
                                                </strong>
                                            </div>
                                        {% endfor %}
                                    {% endif %}
                                </div>
                            </section>
                        </div>

                        <aside class="theme-checkout-summary">
                            <h2>{{ 'checkout_design.payment_resume'|trans }}</h2>
                            <div class="theme-checkout-summary__rows">
                                <div>
                                    <span>{{ 'checkout_design.subtotal'|trans }}</span>
                                    <strong>{{ pricing ? pricing.subtotalTTC|price_format : cart.total|price_format }} €</strong>
                                </div>
                                <div>
                                    <span>{{ 'shop.total_shipping'|trans }}</span>
                                    <strong>
                                        {% if cart.cartShipping %}
                                            {{ cart.cartShipping.amountTTC|price_format }} €
                                        {% else %}
                                            {{ 'checkout_design.free'|trans }}
                                        {% endif %}
                                    </strong>
                                </div>
                                <div class="theme-checkout-summary__total">
                                    <span>{{ 'checkout_design.total_ttc'|trans }}</span>
                                    <strong>{{ pricing ? pricing.totalTTC|price_format : cart.total|price_format }} €</strong>
                                </div>
                            </div>

                            <a href="{{ path('shop') }}" class="theme-button-fill theme-hover-link-effect">
                                {{ 'checkout_design.back_shop'|trans }}
                            </a>
                        </aside>
                    </div>
                </div>
            </article>
        </div>
    </section>
{% endblock %}
