{% extends "oscar/layout.html" %}
{% load currency_filters %}
{% load i18n %}
{% load reviews_tags %}
{% load display_tags %}

{% block extrahead %}
    <meta name="robots" content="noindex">
{% endblock %}

{% block headertext %}
    {% blocktrans with number=order.number %}Order #{{ number }}{% endblocktrans %}
{% endblock %}

{% block content %}
    {% if order.status %}
        <div class="sub-header">
            <h3>{% trans 'Status' %}</h3>
        </div>
        <p>{{ order.status }}</p>
    {% endif %}

    {% with address=order.shipping_address %}
        <div class="sub-header">
            <h3>{% trans 'Shipping address' %}</h3>
        </div>
        <table class="table table-striped table-bordered">
            <tr>
                <th>{% trans 'Address' %}</th>
                <td>
                    {% for field in address.active_address_fields %}
                        {{ field }}<br/>
                    {% endfor %}
                </td>
            </tr>
            {% if address.phone_number %}
                <tr>
                    <th>{% trans 'Contact number' %}</th>
                    <td>{{ address.phone_number }}</td>
                </tr>
            {% endif %}
            {% if address.notes %}
                <tr>
                    <th>{% trans 'Notes' %}</th>
                    <td>{{ address.notes|linebreaks }}</td>
                </tr>
            {% endif %}
        </table>
    {% endwith %}

    <div class="sub-header">
        <h3>{% trans 'Shipping method' %}</h3>
    </div>
    <p>{{ order.shipping_method }}</p>

    <div class="sub-header">
        <h3>{% trans 'Order contents' %}</h3>
    </div>
    {% csrf_token %}
    <table class="table table-striped table-bordered">
        <tr>
            <th>{% trans 'Product' %}</th>
            <th>{% trans 'Status' %}</th>
            <th>{% trans 'Quantity' %}</th>
            <th>{% trans 'Line price excl. tax' %}</th>
            <th>{% trans 'Line price incl. tax' %}</th>
            {% iffeature "reviews" %}
                <th></th>
            {% endiffeature %}
        </tr>
        {% for line in order.lines.all %}
            <tr>
                <td>
                    {% if product.is_public %}
                        <a href="{{ line.product.get_absolute_url }}">{{ line.description }}</a>
                    {% else %}
                        {{ line.description }}
                    {% endif %}
                </td>
                <td>{{ line.shipping_status|default:"-" }}</td>
                <td>{{ line.quantity }}</td>
                <td>{{ line.line_price_before_discounts_excl_tax|currency:order.currency }}</td>
                <td>{{ line.line_price_before_discounts_incl_tax|currency:order.currency }}</td>
                {% iffeature "reviews" %}
                    <td>
                        {% if line.product|is_review_permitted:user %}
                            <a href="{% url 'catalogue:reviews-add' product_slug=line.product.slug product_pk=line.product.id %}" class="btn btn-primary">{% trans 'Write a review' %}</a>
                        {% endif %}
                    </td>
                {% endiffeature %}
            </tr>
        {% endfor %}
        {% for discount in order.discounts.all %}
            <tr>
                <td colspan="4">{{ discount.description }}</td>
                <td>-{{ discount.amount|currency:order.currency }}</td>
                {% iffeature "reviews" %}
                    <td colspan="1"></td>
                {% endiffeature %}
            </tr>
        {% endfor %}
    </table>

    <table class="table table-striped table-bordered">
        <caption>{% trans 'Totals' %}</caption>
        <tr>
            <th>{% trans 'Basket total (inc. tax)' %}</th>
            <td>{{ order.basket_total_incl_tax|currency:order.currency }}</td>
        </tr>
        <tr>
            <th>{% trans 'Shipping charge (inc. tax)' %}</th>
            <td>{{ order.shipping_incl_tax|currency:order.currency }}</td>
        </tr>
        <tr>
            <th>{% trans 'Order total' %}</th>
            <td>{{ order.total_incl_tax|currency:order.currency }}</td>
        </tr>
    </table>

{% endblock content %}
