{% import "@SyliusShop/Common/Macro/money.html.twig" as money %}

{% set itemsSubtotal = sylius_order_items_subtotal(order) %}
{% set taxIncluded = sylius_order_tax_included(order) %}
{% set taxExcluded = sylius_order_tax_excluded(order) %}

{% set orderPromotionAdjustment = constant('Sylius\\Component\\Core\\Model\\AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT') %}
{% set orderPromotions = sylius_aggregate_adjustments(order.adjustmentsRecursively(orderPromotionAdjustment)) %}

<tr>
    <td colspan="4" class="text-right" id="subtotal" {{ sylius_test_html_attribute('subtotal') }}>
        {{ 'sylius.ui.items_total'|trans }}: <span class="price-sm">{{ money.convertAndFormat(itemsSubtotal) }}</span>
    </td>
</tr>
<tr>
    <td colspan="4" id="promotion-total" class="text-right" {{ sylius_test_html_attribute('promotion-total') }}>
        {% if order.orderPromotionTotal != 0 and orderPromotions is not empty %}
            <i
                    id="order-promotions-details" class="question circle icon"
                    data-toggle="tooltip"
                    title="{% for key, value in orderPromotions %}<div>{{ key }}: {{ money.convertAndFormat(value) }}</div>{% endfor %}"
            >
            </i>
        {% endif %}
        {{ 'sylius.ui.discount'|trans }}: <span class="price-sm">{{ money.convertAndFormat(order.orderPromotionTotal)  }}</span>
    </td>
</tr>
<tr>
    {% include '@SyliusShop/Common/Order/Table/_shipping.html.twig' with {'order': order} %}
</tr>
<tr class="cart-totals-tr-total">
    <td colspan="4" class="text-right" id="total" {{ sylius_test_html_attribute('order-total') }}>
        <strong class="h4">{{ 'sylius.ui.total'|trans }}:</strong> <span class="cart-totals-total-amount"></span>{{ money.convertAndFormat(order.total) }}
    </td>
</tr>
<tr class="cart-totals-tr-tax {% if taxIncluded and not taxExcluded %}tax-disabled{% endif %}">
    <td colspan="4" class="text-right" id="tax-total">
        <div style="display: flex; justify-content: flex-end; align-items: center">
            <div>{{ 'sylius.ui.taxes_total'|trans }}:&nbsp;</div>
            <div data-test="tax-total" {{ sylius_test_html_attribute('tax-total') }}>
                {% if not taxIncluded and not taxExcluded %}
                    <div id="sylius-cart-tax-none" class="price-sm">{{ money.convertAndFormat(0) }}</div>
                {% endif %}
                {% if taxExcluded %}
                    <div id="sylius-cart-tax-excluded" class="price-sm">{{ money.convertAndFormat(taxExcluded) }}</div>
                {% endif %}
                {% if taxIncluded %}
                    <div class="tax-disabled">
                        <small>({{ 'sylius.ui.included_in_price'|trans }})</small>
                        <span id="sylius-cart-tax-included" class="price-sm">{{ money.convertAndFormat(taxIncluded) }}</span>
                    </div>
                {% endif %}
            </div>
        </div>
    </td>
</tr>
{% if order.currencyCode is not same as(sylius.currencyCode) %}
    <tr>
        <td colspan="4" class="text-right" id="base-total" {{ sylius_test_html_attribute('summary-order-total') }}>
            {{ 'sylius.ui.total_in_base_currency'|trans }}: <span class="price-sm">{{ money.format(order.total, order.currencyCode) }}</span>
        </td>
    </tr>
{% endif %}
