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

{% block component_product_box_price_reference_unit %}
{% endblock %}

{% block component_product_box_price %}
    <div class="product-price-wrapper">
        {% set price = real %}

        <div class="product-cheapest-price">
            {% if cheapest.unitPrice != real.unitPrice %}
                <div>{{ "listing.cheapestPriceLabel"|trans|sw_sanitize }}<span class="product-cheapest-price-price"> {{ cheapest.unitPrice|currency }}{{ "general.star"|trans|sw_sanitize }}</span></div>
            {% endif %}
        </div>

        {% if displayFrom %}
            {{ "listing.listingTextFrom"|trans|sw_sanitize }}
        {% endif %}

        {% set isListPrice = price.listPrice.percentage > 0 %}

        <span class="product-price{% if isListPrice and not displayFrom %} with-list-price{% endif %}">
            {{ price.unitPrice|currency }}{{ "general.star"|trans|sw_sanitize }}

            {% if isListPrice and not displayFrom %}
                {% 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-price">{{ price.listPrice.price|currency }}{{ "general.star"|trans|sw_sanitize }}</span>

                    {% if afterListPriceSnippetExists %}{{ "listing.afterListPrice"|trans|trim|sw_sanitize }}{% endif %}

                    <span class="list-price-percentage">{{ "detail.listPricePercentage"|trans({'%price%': price.listPrice.percentage })|sw_sanitize }}</span>
                </span>
            {% endif %}
        </span>
        {% set weekProductCount = 0 %}
        {% if (product.customFields.custom_weightlossplan_day1_image != null) %}{% set weekProductCount = weekProductCount + 1 %}{% endif %}
        {% if (product.customFields.custom_weightlossplan_day2_image != null) %}{% set weekProductCount = weekProductCount + 1 %}{% endif %}
        {% if (product.customFields.custom_weightlossplan_day3_image != null) %}{% set weekProductCount = weekProductCount + 1 %}{% endif %}
        {% if (product.customFields.custom_weightlossplan_day4_image != null) %}{% set weekProductCount = weekProductCount + 1 %}{% endif %}
        {% if (product.customFields.custom_weightlossplan_day5_image != null) %}{% set weekProductCount = weekProductCount + 1 %}{% endif %}
        {% if (product.customFields.custom_weightlossplan_day6_image != null) %}{% set weekProductCount = weekProductCount + 1 %}{% endif %}
        {% if weekProductCount >= 1 %}
            <span class="spwn-week-count"><small>{{ (price.unitPrice / weekProductCount) | json_encode() | round(2) | number_format(2, ',', '.') }} € pro Tag</small></span>
        {% endif %}

        {% if referencePrice is not null %}
            <span class="price-unit-reference">
                <small>({{ referencePrice.price|currency }}{{ "general.star"|trans|sw_sanitize }} / {{ referencePrice.referenceUnit }} {{ referencePrice.unitName }})</small>
            </span>
        {% endif %}
    </div>
    {% if product.translated.customFields.deposittype %}
        <div class="product-deposittype">
            {{ product.translated.customFields.deposittype }}
        </div>
    {% endif %}
    {% if product.translated.customFields.deposit %}
        {% set deposit = product.translated.customFields.deposit|currency %}
        <div class="product-deposit">
            <small>
                {{ "FlowsiteDepositSystemBasic.plusDeposit"|trans({
                    '%deposit%': deposit
                })|sw_sanitize }}
            </small>
        </div>
    {% endif %}

{% endblock %}