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

{% set product_variant = item.variant %}

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

<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.discountedUnitPrice %}
                <span class="price-old">{{ money.convertAndFormat(item.unitPrice) }}</span>
            {% endif %}
            <span class="price {% if item.unitPrice != item.discountedUnitPrice %}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-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>

    <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>
</tr>
