{% 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>
    <th colspan="4" class="text-right" id="subtotal" {{ sylius_test_html_attribute('subtotal') }}>
        {{ 'sylius.ui.items_total'|trans }}: {{ money.convertAndFormat(itemsSubtotal) }}
    </th>
</tr>
<tr{% if taxIncluded and not taxExcluded %}class="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">{{ money.convertAndFormat(0) }}</div>
            {% endif %}
            {% if taxExcluded %}
                <div id="sylius-cart-tax-excluded">{{ 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">{{ money.convertAndFormat(taxIncluded) }}</span>
                </div>
            {% endif %}
            </div>
        </div>
    </td>
</tr>
<tr>
    <td colspan="4" id="promotion-total" class="text-right" {{ sylius_test_html_attribute('promotion-total') }}>
        {{ 'sylius.ui.discount'|trans }}: {{ money.convertAndFormat(order.orderPromotionTotal)  }}
        {% 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>
    <td colspan="4" class="text-right" style="font-size: 1.5em;" id="total" {{ sylius_test_html_attribute('order-total') }}>
        {{ 'sylius.ui.total'|trans }}: {{ money.convertAndFormat(order.total) }}
    </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 }}: {{ money.format(order.total, order.currencyCode) }}
        </td>
    </tr>
{% endif %}
