{% extends "base.html" %}
{% load static %}

{% block head_title %}Account | {% endblock %}

{% block content %}
<article>
    <header class="article__header--with-action">
        <h1>{{customer.get_full_name}}</h1>
        <a href="{% url 'storefront:customer-update' customer.pk %}" class="action-button">Edit profile</a>
    </header>
    <section>
        <h4>Info</h4>
        <div class="customer__detail-section">
            <div>
                <strong>Email address</strong><br>
                {{customer.email}}<br>
                <a href="{% url 'account_email' %}">Manage</a>
            </div>
            <div>
                <strong>Default shipping address</strong>
                {% with shipping_address=customer.default_shipping_address  %}
                    <address>
                        {{shipping_address.first_name}}
                        {{shipping_address.last_name}}<br>
                        {{shipping_address.street_address_1}}<br>
                        {% if shipping_address.street_address_2 %}
                            {{shipping_address.street_address_2}}<br>
                        {% endif %}
                        {{shipping_address.city}}, {{shipping_address.state}}, {{shipping_address.postal_code}}
                    </address>
                {% endwith %}
            </div>
        </div>
    </section>
    <section>
        <h4>Your addresses</h4>
        <p>
            <a href="{% url 'storefront:customer-address-create' user.pk %}" class="action-button">+ New address</a>
        </p>
        <div>
            {% for address in customer.addresses.all  %}
                <p>
                    <address>
                        {{address.first_name}}
                        {{address.last_name}}<br>
                        {{address.street_address_1}}<br>
                        {% if address.street_address_2 %}
                            {{address.street_address_2}}<br>
                        {% endif %}
                        {{address.city}}, {{address.state}}, {{address.postal_code}}
                    </address>
                    <a href="{% url 'storefront:address-update' customer.pk address.pk %}">Edit</a>
                </p>
            {% empty %}
                <p>No other addresses.</p>
            {% endfor %}
        </div>
    </section>
    <section>
        <h3>Your orders</h3>
        <table>
            <thead>
                <tr>
                    <th>Order #</th>
                    <th>Date</th>
                    <th colspan="2">Total</th>
                </tr>
            </thead>
            <tbody>
            {% for order in order_list  %}
                <tr>
                    <td>#{{order.pk}}</td>
                    <td>{{order.created_at|date:"M j, Y"}}</td>
                    <td>${{order.get_total_price_after_discount}}</td>
                    <td><a href="{% url 'storefront:order-detail' customer.pk order.pk %}">See details &rarr;</a></td>
                </tr>
            {% empty %}
                <span class="object__item">No orders</span>
            {% endfor %}
            </tbody>
        </table>
    </section>
</article>
{% endblock content %}
