{% extends "layout.html" %}
{% load currency_filters %}
{% load i18n %}

{% block title %}
{% trans 'My account' %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
<ul class="breadcrumb">
    <li>
        <a href="{% url promotions:home %}">{% trans 'Home' %}</a>
        <span class="divider">/</span>
    </li>
    <li class="active"><a href=".">{% trans 'Account' %}</a></li>
</ul>
{% endblock %}

{% block header %}
<div class="page-header">
    <h1>{% trans 'Account' %}</h1>
</div>
{% endblock header %}

{% block content %}

<div class="tabbable dashboard">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#1" data-toggle="tab">{% trans 'Profile' %}</a></li>
        <li><a href="#2" data-toggle="tab">{% trans 'Order History' %}</a></li>
        <li><a href="#3" data-toggle="tab">{% trans 'Address Book' %}</a></li>
        <li><a href="#4" data-toggle="tab">{% trans 'Email History' %}</a></li>
    </ul>

    <div class="tab-content">

        <div class="tab-pane active" id="1">
            {% block tab_profile %}
            <div class="sub-header">
                <h3>{% trans 'Profile' %}</h3>
            </div>
            <table class="table table-striped table-bordered">
                <tbody>
                    <tr>
                        <th>{% trans 'Name' %}</th>
                        <td>{{ request.user.get_full_name|default:'-' }}</td>
                    </tr>
                    <tr>
                        <th>{% trans 'Email address' %}</th>
                        <td>{{ user.email }}</td>
                    </tr>
                    {% block profile_fields %}
                    {% for field in profile_fields %}
                    <tr>
                        <th>{{ field.name }}</th>
                        <td>{{ field.value|default:"-" }}</td>
                    </tr>
                    {% endfor %}
                    {% endblock %}
                    <tr>
                        <th>{% trans 'Date registered' %}</th>
                        <td>{{ user.date_joined }}</td>
                    </tr>
                </tbody>
            </table>

            <div class="form-actions">
                <a href="{% url customer:profile-update %}" class="btn btn-primary">{% trans 'Edit profile' %}</a>
                <a href="{% url customer:change-password %}" class="btn btn-danger">{% trans 'Change password' %}</a>
            </div>
            {% endblock %}
        </div>

        <div class="tab-pane" id="2">
            {% block tab_orderhistory %}
            <div class="sub-header">
                <h3>{% trans 'Order history' %}</h3>
            </div>

            {% if orders %}
            <table class="table table-striped table-bordered">
                <tr>
                    <th>{% trans 'Order number' %}</th>
                    <th>{% trans 'Total inc tax' %}</th>
                    <th>{% trans 'Date submitted' %}</th>
                    <th></th>
                </tr>
                {% for order in orders %}
                <tr>
                    <td>{{ order.number }}</td>
                    <td>{{ order.total_incl_tax|currency }}</td>
                    <td>{{ order.date_placed }}</td>
                    <td>
                        <a class="btn btn-info" href="{% url customer:order order.number %}">{% trans 'View' %}</a>
                        <form action="{% url customer:order order.number %}" method="post">
                            {% csrf_token %}
                            <input type="hidden" name="order_id" value="{{ order.id }}" />
                            <input type="hidden" name="action" value="reorder" />
                            <button type="submit" class="btn btn-success">{% trans 'Re-order' %}</button>
                        </form>
                    </td>
                </tr>
                {% endfor %}
            </table>

            <div class="form-actions">
                <a href="{% url customer:order-list %}" class="btn btn-primary">{% trans 'View order history' %}</a>
            </div>
            {% else %}
            <p>{% trans "You haven't placed any orders yet." %}</p>
            {% endif %}
            {% endblock %}
        </div>

        <div class="tab-pane" id="3">
            {% block tab_addressbook %}
            <div class="sub-header">
                <h3>Address book</h3>
            </div>
            <table class="table table-striped table-bordered">
                <tbody>
                    <tr>
                        <th>{% trans 'Number of addresses in addressbook' %}</th>
                        <td>{{ addressbook_size }}</td>
                    </tr>
                    <tr>
                        <th>{% trans 'Default shipping address' %}</th>
                        <td>{{ default_shipping_address|default:"-" }}</td>
                    </tr>
                    <tr>
                        <th>{% trans 'Default billing address' %}</th>
                        <td>{{ default_billing_address|default:"-" }}</td>
                    </tr>
                </tbody>
            </table>

            <div class="form-actions">
                <a href="{% url customer:address-list %}" class="btn btn-primary">{% trans 'Manage address book' %}</a>
            </div>
            
            {% endblock %}
        </div>

        <div class="tab-pane" id="4">
            {% block tab_emailhistory %}
            <div class="sub-header">
                <h3>{% trans 'Email history' %}</h3>
            </div>
            {% if not emails %}

            <p>{% trans "You haven't been sent any emails yet." %}</p>

            {% else %}

            <table class="table table-striped table-bordered">
                <tr>
                    <th>{% trans 'Date sent' %}</th>
                    <th>{% trans 'Subject' %}</th>
                    <th></th>
                </tr>
                {% for email in emails %}
                <tr>
                    <td>{{ email.date_sent }}</td>
                    <td>{{ email.subject }}</td>
                    <td>
                        <a href="{% url customer:email-detail email.id %}" class="btn btn-info">{% trans 'View' %}</a>
                    </td>
                </tr>
                {% endfor %}
            </table>
            
            <div class="form-actions">
                <a href="{% url customer:email-list %}" class="btn btn-primary">{% trans 'View email history' %}</a>
            </div>
            
            {% endif %}
            {% endblock %}
        </div>
    </div>
</div><!--End of tab-content -->

{% endblock content %}