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

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

<div class="cart-totals card">
    <p class="cart-totals-header h4">{{ 'sylius.ui.summary'|trans }}</p>
    <div class="cart-totals-body">
        {{ sylius_template_event('sylius.shop.cart.summary.totals', {'cart': cart}) }}

        <table class="table">
            <tbody>
            <tr>
                <td>{{ 'sylius.ui.items_total'|trans }}</td>
                <td class="text-right">{{ money.convertAndFormat(itemsSubtotal) }}</td>
            </tr>
            {% if cart.orderPromotionTotal %}
                <tr>
                    <td>{{ 'sylius.ui.discount'|trans }}</td>
                    <td id="sylius-cart-promotion-total" {{ sylius_test_html_attribute('cart-promotion-total') }} class="text-right">{{ money.convertAndFormat(cart.orderPromotionTotal) }}</td>
                </tr>
            {% endif %}
            {% if cart.shipments is not empty %}
                <tr>
                    <td>{{ 'sylius.ui.shipping_estimated_cost'|trans }}</td>
                    <td class="text-right">
                        {% if cart.getAdjustmentsTotal('shipping') > cart.shippingTotal %}
                            <span class="old-price">{{ money.convertAndFormat(cart.getAdjustmentsTotal('shipping')) }}</span>
                        {% endif %}
                        <span id="sylius-cart-shipping-total" {{ sylius_test_html_attribute('cart-shipping-total') }}>{{ money.convertAndFormat(cart.shippingTotal) }}</span>
                    </td>
                </tr>
            {% endif %}

            <tr class="cart-totals-tr-total">
                <td>{{ 'sylius.ui.order_total'|trans }}</td>
                <td id="sylius-cart-grand-total" {{ sylius_test_html_attribute('cart-grand-total') }} class="cart-totals-total-amount text-right">{{ money.convertAndFormat(cart.total) }}</td>
            </tr>

            <tr class="cart-totals-tr-tax{% if taxIncluded and not taxExcluded %} tax-disabled{% endif %}">
                <td>{{ 'sylius.ui.taxes_total'|trans }}</td>
                <td class="text-right">
                    {% if not taxIncluded and not taxExcluded %}
                        <div id="sylius-cart-tax-none" {{ sylius_test_html_attribute('cart-no-tax') }}>{{ money.convertAndFormat(0) }}</div>
                    {% endif %}
                    {% if taxExcluded %}
                        <div id="sylius-cart-tax-excluded" {{ sylius_test_html_attribute('cart-tax-exluded') }}>{{ 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" {{ sylius_test_html_attribute('cart-tax-included') }}>{{ money.convertAndFormat(taxIncluded) }}</span>
                        </div>
                    {% endif %}
                </td>
            </tr>

            {% if cart.currencyCode is not same as(sylius.currencyCode) %}
                <tr class="cart-totals-tr-currency">
                    <td>{{ 'sylius.ui.base_currency_order_total'|trans }}</td>
                    <td id="sylius-cart-base-grand-total" {{ sylius_test_html_attribute('cart-base-grand-total') }} class="text-right">{{ money.format(cart.total, cart.currencyCode) }}</td>
                </tr>
            {% endif %}
            </tbody>
        </table>
    </div>
</div>
