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

{% set variant = product|sylius_resolve_variant %}
{% set hasDiscount = variant ? variant|sylius_has_discount({'channel': sylius.channel}) : null %}
{% set complementaryName = product.getComplementaryName is defined ? product.getComplementaryName() : null %}
{% set appliedPromotions = variant ? variant.getAppliedPromotionsForChannel(sylius.channel) : [] %}

<div class="product-box-container" {{ sylius_test_html_attribute('product') }}>
    {% include '@SyliusShop/Product/Show/_catalogPromotionLabels.html.twig' with {'appliedPromotions': appliedPromotions, 'withDescription': false} %}

    <a href="{{ path('sylius_shop_product_show', {'slug': product.slug, '_locale': product.translation.locale}) }}" class="product-box-image-wrapper">
        {% include '@SyliusShop/Product/_mainImage.html.twig' with {'product': product} %}
    </a>

    <div class="product-box-text-wrapper">
        <a href="{{ path('sylius_shop_product_show', {'slug': product.slug, '_locale': product.translation.locale}) }}" class="product-box-name" {{ sylius_test_html_attribute('product-name', product.name) }}>
            <h2 class="product-box-title">{{ product.name }}</h2>

            {% if complementaryName is not null %}
                <p class="product-box-complementary-name">{{ complementaryName }}</p>
            {% endif %}
        </a>

        {% if product.acceptedReviews|length > 0 %}
            <a href="{{ path('sylius_shop_product_show', {'slug': product.slug, '_locale': product.translation.locale}) }}#product-reviews" class="product-box-review review-rating">
                {% include '@SyliusShop/Product/_starRating.html.twig' %}
                <span class="product-box-review-nb">({{ product.acceptedReviews|length }})</span>
            </a>
        {% endif %}

        {% if not product.variants.empty() %}
            <div class="product-box-price-wrapper price-wrapper right" {{ sylius_test_html_attribute('product-price') }}>
                <span class="price {% if hasDiscount %}promo{% endif %}">{{ money.calculatePrice(product|sylius_resolve_variant) }}</span>
                {% if hasDiscount %}
                    <span class="price-old">{{ money.calculateOriginalPrice(product|sylius_resolve_variant) }}</span>
                {% endif %}
            </div>
        {% endif %}
    </div>
</div>
