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

{% set product_variant = item.variant %}

{% set quantityFieldFormValue = not is_valid ? form.quantity.vars.originalValue|default(item.quantity) : item.quantity %}
{% set quantityFieldFormAttributes = sylius_test_form_attribute('cart-item-quantity-input', item.productName)|sylius_merge_recursive({'value' : quantityFieldFormValue, 'attr': {'form': main_form, 'class': 'input-number' }}) %}

<tr {{ sylius_test_html_attribute('cart-product-row', item.productName) }}>
    <td {{ sylius_test_html_attribute('cart-item', loop_index|default(null) ) }}>
        {% include '@SyliusShop/Product/_info.html.twig' with {'variant': product_variant} %}
    </td>

    <td class="text-right cart-price-wrapper">
        <span class="title-mobile">{{ 'sylius.ui.unit_price'|trans }}</span>
        <div class="price-wrapper-vertical inline">
            {% if item.unitPrice != item.originalUnitPrice %}
                <span class="price-old">{{ money.convertAndFormat(item.originalUnitPrice) }}</span>
            {% endif %}
            <span class="price {% if item.unitPrice != item.originalUnitPrice %}promo{% endif %}" {{ sylius_test_html_attribute('cart-product-unit-price', item.productName) }}>{{ money.convertAndFormat(item.discountedUnitPrice) }}</span>
        </div>
    </td>

    <td>
        <span class="sylius-quantity ui form">
            {{ form_widget(
                form.quantity,
                quantityFieldFormAttributes
            ) }}
        </span>
    </td>

    <td class="text-right">
        <span class="title-mobile">{{ 'sylius.ui.total'|trans }}</span>
        <span class="price" {{ sylius_test_html_attribute('cart-product-subtotal') }}>{{ money.convertAndFormat(item.subtotal) }}</span>
    </td>

    <td class="text-center">
        <form action="{{ path('sylius_shop_cart_item_remove', {'id': item.id}) }}" method="post">
            <input type="hidden" name="_method" value="DELETE" />
            <input type="hidden" name="_csrf_token" value="{{ csrf_token(item.id) }}" />
            <button type="submit" class="cart-item-delete" {{ sylius_test_html_attribute('cart-remove-button', item.productName) }}>
                {% include '@SyliusShop/Icons/cross.html.twig' %}
            </button>
        </form>
    </td>
</tr>
