{% extends 'layouts/members.twig' %}

{% block members_content %}

    {% include 'includes/elements/intro_block.twig' with {
        intro_title: 'Order Details',
        intro_content: 'Below are the details of all orders which you have previously placed',
        class: 'membersIntro',
        use_h1: true
    }%}

    <div class="membersContentWrap">

        <div class="previousOrder">

            {% include 'members/orders/partials/view.twig' %}

            <h5 class="memberTitle">Billing details</h5>

            <div class="overviewTables overviewDelivery">

                <table class="alternating">

                    <tr>
                        <td>Name</td>
                        <td>{{ order.address.billing.firstname }} {{ order.address.billing.lastname }}</td>
                    </tr>
                    <tr>
                        <td>Email address</td>
                        <td class="emailRow">{{ order.info.email }}</td>
                    </tr>
                    <tr>
                        <td>Phone no.</td>
                        <td>{{ order.info.contact_no }}
                    </tr>
                    <tr>
                        <td>Address line 1</td>
                        <td>{{ order.address.billing.address1 }}</td>
                    </tr>
                    <tr>
                        <td>Address line 2</td>
                        <td>{{ order.address.billing.address2 }}</td>
                    </tr>
                    <tr>
                        <td>City</td>
                        <td>{{ order.address.billing.city }}</td>
                    </tr>
                    <tr>
                        <td>Postcode</td>
                        <td>{{ order.address.billing.postcode }}</td>
                    </tr>
                    <tr>
                        <td>Country</td>
                        <td>{{ order.address.billing.country }}</td>
                    </tr>
                </table>

            </div> <!-- .overviewDelivery -->

            <h5 class="memberTitle">Shipping details</h5>

            <div class="overviewTables overviewBilling">

                <table class="alternating">

                    <tr>
                        <td>Name</td>
                        <td>{{ order.address.shipping.firstname }} {{ order.address.shipping.lastname }}</td>
                    </tr>
                    <tr>
                        <td>Address line 1</td>
                        <td>{{ order.address.shipping.address1 }}</td>
                    </tr>
                    <tr>
                        <td>Address line 2</td>
                        <td>{{ order.address.shipping.address2 }}</td>
                    </tr>
                    <tr>
                        <td>City</td>
                        <td>{{ order.address.shipping.city }}</td>
                    </tr>
                    <tr>
                        <td>Postcode</td>
                        <td>{{ order.address.shipping.postcode }}</td>
                    </tr>
                    <tr>
                        <td>Country</td>
                        <td>{{ order.address.shipping.country }}</td>
                    </tr>

                </table>

            </div> <!-- .overviewBilling -->

            {% if order.tracking_no is not empty %}

                <h5 class="memberTitle">Tracking details</h5>

                <div class="overviewTables overviewTracking">
                    <table class="alternating">
                        <tr>
                            <th>Date/Time</th>
                            <th>Event</th>
                            <th>Location</th>
                        </tr>
                        {% for tracking_event in tracking_events %}
                            <tr>
                                <td>{{ tracking_event.formattedDateTime }}</td>
                                <td>{{ tracking_event.eventName }}</td>
                                <td>{{ tracking_event.locationName }}</td>
                            </tr>
                        {% else %}
                            <tr>
                                <td colspan="3">No events yet. Please try again later.</td>
                            </tr>
                        {% endfor %}
                    </table>
                </div> <!-- .overviewTracking -->
            {% endif %}

            <h5 class="memberTitle">Order information</h5>

            <div class="overviewTables overviewBilling">

                <table class="alternating">

                    <tr>
                        <td>Order date</td>
                        <td>
                            {% if order.date is not empty %}
                                {{ order.date }}
                            {% else %}
                                &ndash;
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Order reference</td>
                        <td>
                            {% if order.order_ref is not empty %}
                                #{{ order.order_ref }}
                            {% else %}
                                #ID{{ order.id }}
                            {% endif %}
                        </td>
                    </tr>
                    {% if order.status is not empty %}
                        <tr>
                            <td>Order status</td>
                            <td>
                                {{ order.status }}
                            </td>
                        </tr>
                    {% endif %}

                </table>

            </div> <!-- .overviewBilling -->

        </div> <!-- .recentOrder -->

        {% if not order.paid %}
            {% include 'members/includes/buttons/action_buttons.twig' with {
                button_link_1: route('members-orders', [], false),
                button_text_1: 'Back to orders',
                button_link_2: '/shop/checkout/basket_overview.php?order_id=' ~ order.id,
                button_text_2: 'Pay'
            } %}
        {% endif %}

        {% include 'members/includes/buttons/action_buttons.twig' with {
            button_link_1: route('members-orders', [], false),
            button_text_1: 'Back to orders',
        } %}

    </div> <!-- .membersContentGrid -->

{% endblock %}
