{% 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="cart-totals-price">{{ money.convertAndFormat(itemsSubtotal) }}</span>
    </td>
</tr>
<tr>
    <td colspan="4" id="promotion-total" class="text-right" {{ sylius_test_html_attribute('promotion-total') }}>
        {{ 'sylius.ui.discount'|trans }}: <span class="cart-totals-price">{{ money.convertAndFormat(order.orderPromotionTotal)  }}</span>
        {% if order.orderPromotionTotal != 0 %}
            <i
                id="order-promotions-details" class="question circle icon popup-js"
                {{ sylius_test_html_attribute('order-promotions-details') }}
                data-html="{% for key, value in orderPromotions %}<div>{{ key }}: {{ money.convertAndFormat(value) }}</div>{% endfor %}"
            >
            </i>
        {% endif %}
    </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="cart-totals-price">{{ money.convertAndFormat(0) }}</div>
                {% endif %}
                {% if taxExcluded %}
                    <div id="sylius-cart-tax-excluded" class="cart-totals-price">{{ 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="cart-totals-price">{{ 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="cart-totals-price">{{ money.format(order.total, order.currencyCode) }}</span>
        </td>
    </tr>
{% endif %}
