{% extends '@CoreShopFrontend/layout-full.html.twig' %}
{% import "@CoreShopFrontend/Common/Macro/currency.html.twig" as currency %}

{% block center %}
    {% if quote.hasItems %}
    <div class="table-responsive shopping-cart-table">
        <table class="table table-bordered">
            <thead>
            <tr>
                <td class="text-center">
                    {{ 'coreshop.ui.image'|trans }}
                </td>
                <td class="text-center">
                    {{ 'coreshop.ui.product_details'|trans }}
                </td>
                <td class="text-center">
                    {{ 'coreshop.ui.quantity'|trans }}
                </td>
                <td class="text-center">
                    {{ 'coreshop.ui.price'|trans }}
                </td>
                <td class="text-center">
                    {{ 'coreshop.ui.total'|trans }}
                </td>
            </tr>
            </thead>
            <tbody>
            {% for item in quote.items %}
                {% set productUrl = pimcore_object_path(item.product) %}
                <tr class="shopping-cart-item shopping-cart-item-{{ item.id }}">
                    <td class="text-center">
                        {% if item.product and item.product.image is pimcore_asset_image %}
                            <a class="" href="{{ productUrl }}">
                                {{ item.product.image|pimcore_image_thumbnail_html('coreshop_productQuote', {'imgAttributes': {'class': 'img-fluid'}, 'alt': item.product.name, 'title': item.product.name}) }}
                            </a>
                        {% endif %}
                    </td>
                    <td class="text-center">
                        <a href="{{ productUrl }}">
                            {{ item.product.name }}
                        </a>
                        {% if item.isGiftItem %}
                            <br/><span>{{ 'coreshop.ui.gift_item'|trans }}</span>
                        {% endif %}
                    </td>
                    <td class="text-center">
                        {% if item.isGiftItem %}
                            <span>{{ item.quantity }}</span>
                        {% endif %}
                    </td>
                    <td class="text-right cart-item-price">
                        {% set price = item.itemPrice %}
                        {% set retailPrice = item.itemRetailPrice %}

                        {% if price != retailPrice %}
                            <span class="price-old">{{ currency.convertAndFormat(retailPrice) }}</span>
                        {% endif %}

                        {{ currency.convertAndFormat(price) }}
                    </td>
                    <td class="text-right cart-item-total-price">
                        {{ currency.convertAndFormat(item.total) }}
                    </td>
                </tr>
            {% endfor %}
            {% if quote.hasPriceRules %}
                {% for priceRule in quote.priceRuleItems %}
                    <tr>
                        <td colspan="2" class="text-center">
                            {{ priceRule.cartPriceRule.label ?: priceRule.cartPriceRule.name }}
                        </td>
                        <td class="text-center">

                        </td>
                        <td class="text-right">
                            -{{ currency.convertAndFormat(priceRule.discount(true)) }}
                        </td>
                        <td class="text-right">
                            -{{ currency.convertAndFormat(priceRule.discount(false)) }}
                        </td>
                    </tr>
                {% endfor %}
            {% endif %}

            </tbody>
            <tfoot>
            {% set shipping = quote.shipping(false) %}
            {% set shippingIt = quote.shipping(true) %}
            {% set discount = quote.discount(false) %}
            {% set discountIt = quote.discount(true) %}
            {% set taxes = quote.taxes %}
            {% set rowspan = 10 + taxes|length %}

            {% if shipping == 0 %}
                {% set rowspan = rowspan - 1 %}
            {% endif %}

            {% if discount == 0 %}
                {% set rowspan = rowspan - 2 %}
            {% endif %}

            <tr>
                <td colspan="3" rowspan="{{ rowspan }}">

                </td>
                <td class="text-right">
                    <strong>{{ 'coreshop.ui.subtotal_inc'|trans }}:</strong>
                </td>
                <td colspan="1" class="text-right cart-sub-total">
                    {{ currency.convertAndFormat(quote.subtotal(true)) }}
                </td>
            </tr>
            <tr>
                <td class="text-right">
                    <strong>{{ 'coreshop.ui.subtotal_excl'|trans }}:</strong>
                </td>
                <td colspan="1" class="text-right cart-discount">
                    {{ currency.convertAndFormat(quote.subtotal(false)) }}
                </td>
            </tr>
            {% if discount > 0 %}
                <tr>
                    <td class="text-right">
                        <strong>{{ 'coreshop.ui.discount_incl'|trans }}:</strong>
                    </td>
                    <td colspan="1" class="text-right cart-discount">
                        -{{ currency.convertAndFormat(discountIt) }}
                    </td>
                </tr>
                <tr>
                    <td class="text-right">
                        <strong>{{ 'coreshop.ui.discount_excl'|trans }}:</strong>
                    </td>
                    <td colspan="1" class="text-right cart-discount">
                        -{{ currency.convertAndFormat(discount) }}
                    </td>
                </tr>
            {% endif %}
            {% if shipping > 0 %}
                <tr>
                    <td class="text-right">
                        <strong>{{ 'coreshop.ui.shipping_incl'|trans }}:</strong>
                    </td>
                    <td colspan="1" class="text-right cart-shipping">
                        {{ currency.convertAndFormat(shippingIt) }}
                    </td>
                </tr>
                <tr>
                    <td class="text-right">
                        <strong>{{ 'coreshop.ui.shipping_excl'|trans }}:</strong>
                    </td>
                    <td colspan="1" class="text-right cart-shipping">
                        {{ currency.convertAndFormat(shipping) }}
                    </td>
                </tr>
            {% endif %}

            {% for taxItem in taxes %}
                 <tr>
                    <td class="text-right cart-tax-detail">
                        <strong>{{ 'coreshop.ui.tax_name'|trans|format(taxItem.name) }}:</strong>
                    </td>
                    <td colspan="1" class="text-right cart-tax-detail">
                        {{ currency.convertAndFormat(taxItem.amount) }}
                    </td>
                </tr>
            {% endfor %}
            {#TODO
            <?php foreach($taxes as $tax) { ?>
                <tr>
                    <td class="text-right cart-tax-detail">
                        <strong><?=$this->translate(sprintf("Tax (%s)", $tax['tax']->getName()))?>:</strong>
                    </td>
                    <td colspan="1" class="text-right cart-tax-detail">
                        <?=$this->cart->formatPrice($tax['amount'])?>
                    </td>
                </tr>
            <?php } ?>
            #}
           <tr>
                <td class="text-right">
                    <strong>{{ 'coreshop.ui.total_tax'|trans }}:</strong>
                </td>
                <td colspan="1" class="text-right cart-tax">
                    {{ currency.convertAndFormat(quote.totalTax) }}
                </td>
            </tr>
            <tr>
                <td class="text-right">
                    <strong>{{ 'coreshop.ui.total'|trans }}:</strong>
                </td>
                <td colspan="1" class="text-right cart-total-price">
                    {{ currency.convertAndFormat(quote.total) }}
                </td>
            </tr>
            </tfoot>
        </table>
    </div>
    {% else %}
        <p>{{ 'coreshop.ui.quote_empty'|trans }}</p>
    {% endif %}
{% endblock %}
