{% sw_extends '@Storefront/storefront/component/product/card/price-unit.html.twig' %}

{% block component_product_box_price_info %}
    {% set cheapest = product.calculatedCheapestPrice %}

    {% set real = product.calculatedPrice %}
    {% if product.calculatedPrices.count > 0 %}
        {% set real = product.calculatedPrices.last %}
    {% endif %}

    {% set referencePrice = real.referencePrice %}

    {% set displayFrom = product.calculatedPrices.count > 1 %}
    {% set displayParent = product.variantListingConfig.displayParent and product.parentId === null %}

    {% if displayParent %}
        {% set displayFromVariants = displayParent and real.unitPrice !== cheapest.unitPrice %}
        {% set real = cheapest %}
        {% set totalVariants = product.cheapestPriceContainer.value %}
        {% set hasDifferentPrice = totalVariants|filter(variant => variant.default != null)|length > 0 %}
        {% set hasRange = product.cheapestPrice.hasRange %}
    {% endif %}

    <div class="product-price-info">
        {#
        Main price display. Always used, can also include list prices.
        Example: $150.00"
        Example with list price: €400.00 <s>€500.00</s> (20% saved)"
        #}
        {% block component_product_box_price %}
            {{ parent() }}
        {% endblock %}

        {% block component_product_box_price_unit %}
            <p class="product-price-unit">
                {# Price is based on the purchase unit #}
                {% block component_product_box_price_purchase_unit %}
                    {% if referencePrice and referencePrice.unitName %}
                        <span class="price-unit-content">
                            {{ referencePrice.purchaseUnit }} {{ referencePrice.unitName }}
                        </span>
                    {% endif %}
                {% endblock %}
                <span> | </span>
                {# Item price is based on a reference unit #}
                {% block component_product_box_price_reference_unit %}
                    {% if referencePrice is not null %}
                        <span class="price-unit-reference">
                        {% if referencePrice.referenceUnit == '1' and referencePrice.unitName =='Liter' %}
                            {{ referencePrice.price|currency }}/l
                        {% else %}
                            ({{ referencePrice.price|currency }} / {{ referencePrice.referenceUnit }} {{ referencePrice.unitName }})
                        {% endif %}
                    </span>
                    {% endif %}
                {% endblock %}
            </p>
        {% endblock %}

        <p class="price-taxInfo">{{ "general.grossTaxInformation"|trans }}</p>
    </div>

{% endblock %}


{#
Main price display. Always used, can also include list prices.
Example: $150.00"
Example with list price: €400.00 <s>€500.00</s> (20% saved)"
#}
{% block component_product_box_main_price %}
    <span class="product-price{% if isListPrice and not displayFrom and not displayFromVariants %} with-list-price{% endif %}">

        {% if isListPrice and not displayFrom and not displayFromVariants %}
            {% set afterListPriceSnippetExists = 'listing.afterListPrice'|trans|length > 0 %}
            {% set beforeListPriceSnippetExists = 'listing.beforeListPrice'|trans|length > 0 %}
            {% set hideStrikeTrough = beforeListPriceSnippetExists or afterListPriceSnippetExists %}

            <span class="list-price{% if hideStrikeTrough %} list-price-no-line-through{% endif %}">
                {% if beforeListPriceSnippetExists %}{{ 'listing.beforeListPrice'|trans|trim|sw_sanitize }}{% endif %}

                <span class="list-price-label">{{ 'listing.regularPriceLabel'|trans|sw_sanitize }} </span
                ><span class="list-price-price">{{ price.listPrice.price|currency }}</span>

                {% if afterListPriceSnippetExists %}{{ 'listing.afterListPrice'|trans|trim|sw_sanitize }}{% endif %}
            </span>
        {% endif %}
        <span class="product-price-inner">{{ price.unitPrice|currency }}</span>
    </span>
{% endblock %}