{% load i18n %}
{% load currency_filters %}
{% load ocyanjson %}

{% ocyanjson "oscar" "show_tax_everywhere" False as show_tax_separately %}

<div id="basket_totals">
    <table class="table table-smaller table-borderless mt-3 mb-0 thankyou-table">
        {% with discounts=order.basket_discounts %}
        {% block discount_totals %}
            {% if discounts %}
            <tr>
                <td>{% trans "Basket total (before discounts)" %}</td>
                <td class="text-right">{{ order.basket_total_before_discounts_incl_tax|currency:order.currency }}</td>
            </tr>
            {% for discount in discounts %}
            <tr>
                <td><span>{% trans "Discount" %}</span> {{ discount.offer }}</td>
                <td class="text-right">- {{ discount.amount|currency:order.currency }}</td>
            </tr>
            {% endfor %}
            {% endif %}
        {% endblock discount_totals %}

        {% block basket_total %}
            {% if discounts %}
            <tr>
                <th class="total">{% trans "Basket total (after discounts)" %}</th>
                <th class="total text-right">{{ order.basket_total_incl_tax|currency:order.currency }}</th>
            </tr>
            {% else %}
            <tr class="basket-items">
                <td class="total">{% trans "Basket total" %}</td>
                <td class="total text-right">
                {% if show_tax_separately %}
                    {{ order.basket_total_excl_tax|currency:order.currency }}
                {% else %}
                    {{ order.basket_total_incl_tax|currency:order.currency }}
                {% endif %}
                </td>
            </tr>
            {% endif %}
        {% endblock basket_total %}
        {% endwith %}

        {% block shipping_total %}
            <tr>
                <th colspan="2">&nbsp;</th>
            </tr>
            <tr>
                <th colspan="2">{% trans "Shipping" %}</th>
                <td></td>
            </tr>
            <tr>
                <td>{% trans "Shipping method" %}</td>
                <td class="text-right">{{ order.shipping_method }}</td>
            </tr>
            {% if order.has_shipping_discounts %}
            <tr class="border-top">
                <td>{% trans "Shipping charge (before discounts)" %}</td>
                <td class="text-right">{{ order.shipping_before_discounts_incl_tax|currency:order.currency }}</td>
            </tr>
            {% for discount in order.shipping_discounts %}
                <tr class="border-top">
                    <td><span class="">{% trans "Discount" %}</span> {{ discount.offer }}</td>
                    <td class="text-right">- {{ discount.amount|currency:order.currency }}</td>
                </tr>
            {% endfor %}
            <tr>
                <th class="total">{% trans "Shipping charge (after discounts)" %}</th>
                <th class="total text-right">{{ order.shipping_incl_tax|currency:order.currency }}</th>
            </tr>
            {% else %}
            <tr>
                <td class="total">{% trans "Shipping charge" %}</td>
                <td class="total text-right">
                    {% if show_tax_separately %}
                        {{ order.shipping_excl_tax|currency:order.currency }}
                    {% else %}
                        {{ order.shipping_incl_tax|currency:order.currency }}
                    {% endif %}
                </td>
            </tr>
            {% endif %}

            {% with surcharges=order.surcharges.all %}
            {% if surcharges %}
            <tr>
                <th colspan="2">&nbsp;</th>
            </tr>
            <tr>
                <th>{% trans 'Surcharges' %}</th>
                <td></td>
            </tr>
            {% for charge in surcharges %}
            <tr>
                <td class="total">{{charge.name}}</td>
                <td class="total text-right">
                    {% if not show_tax_separately and order.shipping_charge.is_tax_known %}
                        {{ charge.excl_tax|currency:order.currency }}
                    {% else %}
                        {{ charge.incl_tax|currency:order.currency }}
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
            {% endif %}
            {% endwith %}
        {% endblock shipping_total %}

        {% block post_order_action_totals %}
            {% with actions=order.post_order_actions %}
            {% if actions %}
            <tr>
                <th colspan="2">&nbsp;</th>
            </tr>
            <tr>
                <th colspan="2">{% trans "Post order actions" %}</th>
            </tr>
            {% for action in order.post_order_actions %}
            <tr>
                <td class="total" colspan="2"><p>{{ action.message }}</p></td>
            </tr>
            {% endfor %}
            {% endif %}
            {% endwith %}
        {% endblock post_order_action_totals %}

        {% block order_total %}
        <tr>
            <th colspan="2">&nbsp;</th>
        </tr>
        {% if show_tax_separately %}
            <tr class="totals">
                <td class=""><b>{% trans "Total excl. tax" %}</b></td>
                <td class="text-right"><b class="price_color">{{ order.total_excl_tax|currency:order.currency }}</b></td>
            </tr>
            <tr class="totals">
                <td class="">{% trans "Total tax" %}</td>
                <td class="text-right"><b class="price_color">{{ order.total_tax|currency:order.currency }}</b></td>
            </tr>
        {% endif %}
        <tr class="totals">
            {% if order.total_tax %}
                <td><b>{% trans "Total incl. tax" %}</b></td>
            {% else %}
                <td><b>{% trans "Total" %}</b></td>
            {% endif %}
            <td class="text-right"><b class="price_color">{{ order.total_incl_tax|currency:order.currency }}</b></td>
        </tr>
        {% endblock order_total %}
    </table>
</div>