{% extends 'oscar/customer/order/order_detail.html' %}

{% load i18n display_tags reviews_tags currency_filters %}

{% block tabcontent %}
    <table class="table table-striped table-bordered">
        {% block table_head %}
            <thead>
                <tr>
                    <th>{% trans 'Product' %}</th>
                    <th>{% trans 'Dispatch date' %}</th>
                    <th>{% trans 'Qty' %}</th>
                    <th>{% trans 'Line price excl. tax' %}</th>
                    <th>{% trans 'Line price incl. tax' %}</th>
                    <th></th>
                </tr>
            </thead>
        {% endblock %}

        {% block table_body %}
        <tbody>
            {% block order_lines %}
                <h2>{% trans 'Order lines' %}</h2>
                {% for line in order.lines.all %}
                    {% with product=line.product %}
                        <tr>
                            <td>
                                {% if product %}
                                    <p>
                                        <a href="{{ product.get_absolute_url }}">{{ line.description }}</a>
                                    </p>
                                    {% iffeature "reviews" %}
                                        {% if product|is_review_permitted:user %}
                                            <a class="btn btn-default" href="{% url 'catalogue:reviews-add' product_slug=product.slug product_pk=product.id %}#addreview">{% trans 'Write a review' %}</a>
                                        {% endif %}
                                    {% endiffeature %}
                                {% else %}
                                    <p>
                                        {{ line.description }}
                                    </p>
                                {% endif %}
                            </td>
                            <td>{{ line.est_dispatch_date|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>
                            <td width="90">
                                {% if product %}
                                    <form id="line_form_{{ line.id }}" action="{% url 'customer:order-line' order_number=order.number line_id=line.id %}" method="POST">
                                        {% csrf_token %}
                                        <input type="hidden" name="action" value="reorder" />
                                        <button id="reorder_line_{{ line.id }}" class="btn btn-success" type="submit" data-loading-text="{% trans 'Re-ordering...' %}">{% trans 'Re-order' %}</button>
                                    </form>
                                {% else %}
                                    {% trans 'Not available anymore' %}
                                {% endif %}
                            </td>
                        </tr>
                    {% endwith %}
                {% endfor %}
            {% endblock %}

            {% with discounts=order.basket_discounts %}
                {% block discount_totals %}
                    {{block.super}}
                {% endblock discount_totals %}

                {% block basket_total %}
                    {{block.super}}
                {% endblock basket_total %}
            {% endwith %}

            {% block shipping_totals %}
                {{block.super}}
            {% endblock %}

            {% block order_total %}
                {{block.super}}
            {% endblock order_total %}
        </tbody>
        {% endblock %}
    </table>

    {% block order_actions %}
        {{block.super}}
        <hr>
    {% endblock order_actions %}

    {% block shipping_method %}
        <h2>{% trans 'Shipping Method' %}</h2>
        <p>{{ order.shipping_method }}</p>
        <hr>
    {% endblock %}

    {% block shipping_address %}
        <h2>{% trans 'Shipping Address' %}</h2>

        <table class="table table-striped table-bordered">
            <tr>
                <th>{% trans 'Address' %}</th>
                <th>{% trans 'Contact Number' %}</th>
                <th>{% trans 'Shipping Notes' %}</th>
            </tr>
            <tr>
                <td>
                        {% for field in order.shipping_address.ordered_active_address_fields %}
                            {{ field }}<br/>
                        {% endfor %}
                </td>
                <td>{{ order.shipping_address.phone_number|default:"-" }}</td>
                <td>{{ order.shipping_address.notes|linebreaks }}</td>
            </tr>
        </table>
    {% endblock %}
{% endblock tabcontent %}
