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

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

{% block main %}
    {% set billing_address = cart.invoiceAddress ?: cart.deliveryAddress %}
    {% set delivery_address = cart.deliveryAddress %}

    <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.success_badge'|trans }}</p>
                    <h1>{{ 'checkout_design.success_title'|trans }}</h1>
                    <p>
                        {{ 'checkout_design.success_email_notice'|trans({
                            '%document%': document_label|trans|lower,
                            '%email%': cart.getEmail() ?? '-'
                        }) }}
                    </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.success_summary'|trans }}</h2>
                                <div class="theme-checkout-lines">
                                    {% for line in cart.getPricing.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>{{ line.netTTC|price_format }} €</strong>
                                        </div>
                                    {% endfor %}
                                </div>
                            </section>

                            <section class="theme-checkout-card">
                                <div class="theme-checkout-addresses">
                                    <div>
                                        <h2>{{ 'checkout_design.success_billing'|trans }}</h2>
                                        {% if billing_address %}
                                            <address>
                                                <span>{{ billing_address.getName() }}</span>
                                                {% if billing_address.company %}<span>{{ billing_address.company }}</span>{% endif %}
                                                <span>{{ billing_address.street }}</span>
                                                <span>{{ billing_address.postal }} {{ billing_address.city }}</span>
                                                <span>{{ billing_address.country|country_name }}</span>
                                                <span>{{ billing_address.email }}</span>
                                                <span>{{ billing_address.phone }}</span>
                                            </address>
                                        {% else %}
                                            <p>-</p>
                                        {% endif %}
                                    </div>
                                    <div>
                                        <h2>{{ 'checkout_design.success_delivery'|trans }}</h2>
                                        {% if delivery_address %}
                                            <address>
                                                <span>{{ delivery_address.getName() }}</span>
                                                {% if delivery_address.company %}<span>{{ delivery_address.company }}</span>{% endif %}
                                                <span>{{ delivery_address.street }}</span>
                                                <span>{{ delivery_address.postal }} {{ delivery_address.city }}</span>
                                                <span>{{ delivery_address.country|country_name }}</span>
                                                <span>{{ delivery_address.email }}</span>
                                                <span>{{ delivery_address.phone }}</span>
                                            </address>
                                        {% else %}
                                            <p>-</p>
                                        {% endif %}
                                    </div>
                                </div>
                            </section>

                            <section class="theme-checkout-card">
                                <h2>{{ 'checkout_design.success_payment'|trans }}</h2>
                                <dl class="theme-checkout-details">
                                    <div>
                                        <dt>{{ 'checkout_design.paid_method'|trans }}</dt>
                                        <dd>{{ payment_method_label ? payment_method_label|trans : '-' }}</dd>
                                    </div>
                                    <div>
                                        <dt>{{ 'checkout_design.paid_at'|trans }}</dt>
                                        <dd>{{ cart.cartCheckout and cart.cartCheckout.payedAt ? cart.cartCheckout.payedAt|date('d/m/Y H:i') : '-' }}</dd>
                                    </div>
                                    {% if cart.deliveryMethod %}
                                        <div>
                                            <dt>{{ 'checkout_design.success_delivery_method'|trans }}</dt>
                                            <dd>{{ cart.deliveryMethod.name }}</dd>
                                        </div>
                                    {% endif %}
                                    <div>
                                        <dt>{{ 'checkout_design.success_order_number'|trans }}</dt>
                                        <dd>{{ cart.token }}</dd>
                                    </div>
                                </dl>
                            </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>{{ cart.getPricing.subtotalTTC|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>{{ 'shop.total_ttc'|trans }}</span>
                                    <strong>{{ cart.getPricing.totalTTC|price_format }} €</strong>
                                </div>
                            </div>
                        </aside>
                    </div>

                    <div class="theme-checkout-actions">
                        <a href="{{ path('shop_purchase_order_download', { cartId: cart.id }) }}" class="theme-button-fill theme-hover-link-effect">
                            {{ download_document_label|trans }}
                        </a>
                        <a href="{{ path('shop') }}" class="theme-button-stroke theme-hover-link-effect">
                            {{ 'checkout_design.back_shop'|trans }}
                        </a>
                    </div>

                    {% if can_prompt_guest_account_creation %}
                        <section class="theme-checkout-guest">
                            <div>
                                <p class="theme-checkout-eyebrow">{{ 'checkout_design.guest_account_badge'|trans }}</p>
                                <h2>{{ 'checkout_design.guest_account_title'|trans }}</h2>
                                <p>{{ 'checkout_design.guest_account_notice'|trans }}</p>
                            </div>
                            <a href="{{ path('shop_checkout_success_register', { cartId: cart.id }) }}" class="theme-button-fill theme-hover-link-effect">
                                {{ 'checkout_design.guest_account_cta'|trans }}
                            </a>
                        </section>
                    {% endif %}
                </div>
            </article>
        </div>
    </section>
{% endblock %}
