{% import "@CoreShopFrontend/Common/Macro/currency.html.twig" as currency %}
{% form_theme form 'bootstrap_4_layout.html.twig' %}

{% set productUrl = pimcore_object_path(item.product) %}

<tr class="shopping-cart-item" {% if item.hasUnitDefinition %}{{ coreshop_test_html_attribute('cart-item-row-unit-' ~ item.unitDefinition.id, item.name) }}{% endif %}{{ coreshop_test_html_attribute('cart-item-row', item.name) }}>
    <td class="text-center">
        {% if item.product and item.product.image is pimcore_asset_image %}
            <a href="{{ productUrl }}">
                {{ item.product.image|pimcore_image_thumbnail_html('coreshop_productCart', {'imgAttributes': {'class': 'img-fluid'}, 'alt': item.product.name, 'title': item.product.name}) }}
            </a>
        {% endif %}
    </td>
    <td class="text-center">
        <a href="{{ productUrl }}" {{ coreshop_test_html_attribute('cart-item-name', item.name) }}>
            {{ item.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>
            {% if item.hasUnitDefinition %}
                <span class="unit-definition unit-name">{{ item.unitDefinition.unit.name }}</span>
            {% endif %}
        {% else %}
            <div class="input-group">
                {{ form_widget(form.quantity, coreshop_test_form_attribute('cart-item-quantity-input', item.name)) }}
                {% if item.hasUnitDefinition %}
                    <div class="input-group-append">
                        <span class="input-group-text" {{ coreshop_test_html_attribute('cart-item-unit-' ~ item.unitDefinition.id, item.name) }}>
                            {{ item.unitDefinition.unit.name }}
                        </span>
                    </div>
                {% endif %}

                {{ form_errors(form.quantity) }}
            </div>
        {% endif %}
    </td>
    <td class="text-right cart-item-price">
        {% set price = item.itemPrice %}
        {% set discount = item.itemDiscount %}
        {% set discountPrice = item.itemDiscountPrice %}
        {% set retailPrice = item.itemRetailPrice %}

        <span class="price-new" {{ coreshop_test_html_attribute('cart-item-unit-price', item.name) }}>{{ currency.convertAndFormat(price) }}</span>
        {% if price < retailPrice %}
            {% if discountPrice > 0 %}
                <span class="price-old">{{ currency.convertAndFormat(retailPrice) }}</span>
            {% endif %}
            {% if discount < 0 %}
                <span class="price-discount">(-{{ currency.convertAndFormat(discount) }})</span>
            {% endif %}
        {% endif %}
    </td>
    <td class="text-right cart-item-total-price" {{ coreshop_test_html_attribute('cart-item-total-price', item.name) }}>
        {% if item.discount < 0 %}
            <span>({{ currency.convertAndFormat(item.discount) }})</span>
        {% endif %}
        {{ currency.convertAndFormat(item.total) }}
    </td>
    <td class="text-center">
        {% if not item.isGiftItem and is_granted('CORESHOP_CART_REMOVE_ITEM') %}
            <a
                href="{{ path('coreshop_cart_remove', {cartItem: item.id|coreshop_string}) }}"
                title="{{ 'coreshop.ui.remove'|trans }}"
                class="btn btn-danger tool-tip"
                data-id="{{ item.id }}"
                {{ coreshop_test_html_attribute('cart-remove-button', item.name) }}
            >
                <i class="fa fa-times-circle"></i>
            </a>
        {% endif %}
    </td>
</tr>
