{% extends '@CpCreationVitiCore/admin/base.html.twig' %}

{% block content %}
    {% set customer_name = ((customer.firstname ?: '') ~ ' ' ~ (customer.lastname ?: ''))|trim %}

    <div class="row">
        <div class="col-md-12">
            <div class="page-header" style="margin-top: 0;">
                <h1>{{ 'admin.client.guests.details_title'|trans }}</h1>
            </div>
            <p>
                <a href="{{ path('admin_guest_client') }}" class="btn btn-default btn-sm">
                    <i class="fas fa-arrow-left"></i> {{ 'admin.client.guests.back'|trans }}
                </a>
            </p>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">{{ 'admin.client.guests.customer'|trans }}</div>
        <table class="table table-striped">
            <tbody>
            <tr>
                <th style="width: 220px;">{{ 'admin.client.guests.customer'|trans }}</th>
                <td>{{ customer_name ?: '-' }}</td>
            </tr>
            <tr>
                <th>{{ 'admin.client.guests.email'|trans }}</th>
                <td>{{ customer.email }}</td>
            </tr>
            </tbody>
        </table>
    </div>

    {% set latest_order = order_insights.orders|first %}
    {% if latest_order %}
        <p class="help-block">{{ 'admin.client.guests.latest_addresses_help'|trans }}</p>
        <div class="row">
            {% for address_data in [
                { title: 'admin.client.guests.latest_invoice_address', address: latest_order.invoiceAddress ?: latest_order.deliveryAddress },
                { title: 'admin.client.guests.latest_delivery_address', address: latest_order.deliveryAddress ?: latest_order.invoiceAddress }
            ] %}
                <div class="col-md-6">
                    <div class="panel panel-default">
                        <div class="panel-heading">{{ address_data.title|trans }}</div>
                        <div class="panel-body">
                            {% set address = address_data.address %}
                            {% if address %}
                                <p><strong>{{ address.firstname }} {{ address.lastname }}</strong></p>
                                {% if address.company %}<p>{{ address.company }}</p>{% endif %}
                                <p>{{ address.street ?: '-' }}<br>{{ address.postal ?: '-' }} {{ address.city ?: '' }}<br>{{ address.country ? address.country|upper : '-' }}</p>
                                <p>{{ address.email ?: customer.email }}<br>{{ address.phone ?: '-' }}</p>
                            {% else %}
                                <p class="text-muted">-</p>
                            {% endif %}
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    {% endif %}

    {% include '@CpCreationVitiCore/admin/client/_order_insights.html.twig' with { order_insights: order_insights } only %}
{% endblock %}
