{% 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) %}

<div class="ui segment">
    <table class="ui very basic table" id="sylius-checkout-subtotal" {{ sylius_test_html_attribute('checkout-subtotal') }}>
        <thead>
        <tr>
            <th class="sylius-table-column-item">{{ 'sylius.ui.item'|trans }}</th>
            <th class="sylius-table-column-qty">{{ 'sylius.ui.qty'|trans }}</th>
            <th class="sylius-table-column-subtotal">{{ 'sylius.ui.subtotal'|trans }}</th>
        </tr>
        </thead>
        <tbody>
        {% for item in order.items %}
            <tr>
                <td>{{ item.getVariant.product.name }}</td>
                <td class="center aligned">
                    {{ item.quantity }}
                </td>
                <td class="right aligned" id="sylius-item-{{ item.variant.product.slug }}-subtotal" {{ sylius_test_html_attribute('item-subtotal', item.variant.product.slug) }}>
                    {{ money.convertAndFormat(item.subtotal) }}
                </td>
            </tr>
        {% endfor %}
        </tbody>
        <tfoot>
            <tr>
                <td colspan="1" style="border-top: 2px solid #ddd;">
                    <strong>{{ 'sylius.ui.items_total'|trans }}:</strong>
                </td>
                <td colspan="2" id="sylius-summary-items-subtotal" class="right aligned" style="border-top: 2px solid #ddd;">
                    {{ money.convertAndFormat(itemsSubtotal) }}
                </td>
            </tr>
            <tr {% if taxIncluded and not taxExcluded %}class="tax-disabled" {% endif %}>
                <td colspan="1">
                    <strong>{{ 'sylius.ui.taxes_total'|trans }}:</strong>
                </td>
                <td colspan="2" class="right aligned">
                    {% if not taxIncluded and not taxExcluded %}
                        <div id="sylius-summary-tax-none">{{ money.convertAndFormat(0) }}</div>
                    {% endif %}
                    {% if taxExcluded %}
                        <div id="sylius-summary-tax-excluded">{{ money.convertAndFormat(taxExcluded) }}</div>
                    {% endif %}
                    {% if taxIncluded %}
                        <div class="tax-disabled">
                            <span id="sylius-summary-tax-included">{{ money.convertAndFormat(taxIncluded) }}</span>
                            <div><small>({{ 'sylius.ui.included_in_price'|trans }})</small></div>
                        </div>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td colspan="1">
                    <strong>{{ 'sylius.ui.discount'|trans }}:</strong>
                </td>
                <td colspan="2" id="sylius-summary-promotion-total" class="right aligned">
                    {{ money.convertAndFormat(order.orderPromotionTotal) }}
                </td>
            </tr>
            {% if order.shipments is not empty %}
                <tr>
                    <td colspan="1">
                        <strong>{{ 'sylius.ui.shipping_estimated_cost'|trans }}:</strong>
                    </td>
                    <td colspan="2" class="right aligned">
                        {% if order.getAdjustmentsTotal('shipping') > order.shippingTotal %}
                            <div class="old-price">{{ money.convertAndFormat(order.getAdjustmentsTotal('shipping')) }}</div>
                        {% endif %}
                        <span id="sylius-summary-shipping-total">{{ money.convertAndFormat(order.shippingTotal) }}</span>
                    </td>
                </tr>
            {% endif %}
            <tr class="ui large header">
                <td colspan="1">
                    <strong>{{ 'sylius.ui.order_total'|trans }}:</strong>
                </td>
                <td colspan="2" id="sylius-summary-grand-total" class="right aligned">
                    {{ money.convertAndFormat(order.total) }}
                </td>
            </tr>
        </tfoot>
    </table>
</div>
