{% sw_extends '@Storefront/storefront/component/buy-widget/buy-widget.html.twig' %}

{% block buy_widget %}
    <div class="product-detail-buy{% if elementId %}-{{ elementId }}{% endif %} js-magnifier-zoom-image-container">
        {% block buy_widget_rich_snippets %}
            {% block buy_widget_rich_snippets_brand %}
                {% if product.manufacturer %}
                    <meta itemprop="brand"
                          content="{{ product.manufacturer.translated.name }}"/>
                {% endif %}
            {% endblock %}

            {% block buy_widget_rich_snippets_gtin13 %}
                {% if product.ean %}
                    <meta itemprop="gtin13"
                          content="{{ product.ean }}"/>
                {% endif %}
            {% endblock %}

            {% block buy_widget_rich_snippets_mpn %}
                {% if product.manufacturerNumber %}
                    <meta itemprop="mpn"
                          content="{{ product.manufacturerNumber }}"/>
                {% endif %}
            {% endblock %}

            {% block buy_widget_rich_snippets_weight %}
                {% if product.weight %}
                    <meta itemprop="weight"
                          content="{{ product.weight }} kg"/>
                {% endif %}
            {% endblock %}

            {% block buy_widget_rich_snippets_height %}
                {% if product.height %}
                    <meta itemprop="height"
                          content="{{ product.height }} mm"/>
                {% endif %}
            {% endblock %}

            {% block buy_widget_rich_snippets_width %}
                {% if product.width %}
                    <meta itemprop="width"
                          content="{{ product.width }} mm"/>
                {% endif %}
            {% endblock %}

            {% block buy_widget_rich_snippets_depth %}
                {% if product.length %}
                    <meta itemprop="depth"
                          content="{{ product.length }} mm"/>
                {% endif %}
            {% endblock %}

            {% block buy_widget_rich_snippets_release_date %}
                <meta itemprop="releaseDate"
                      content="{{ product.releaseDate|format_date(pattern="Y-MM-dd", locale=app.request.locale) }}"/>
            {% endblock %}
        {% endblock %}

        {% if not feature('FEATURE_NEXT_16992') %}
            {# @deprecated tag:v6.5.0 tag:)(FEATURE_NEXT_16992) - Block will be removed in v6.5.0 #}
            {% block buy_widget_not_available %}
            {% endblock %}
        {% endif %}

        {% block buy_widget_buy_container %}
            <div itemprop="offers"
                 itemscope
                 itemtype="{% if product.calculatedPrices|length > 1 %}http://schema.org/AggregateOffer{% else %}http://schema.org/Offer{% endif %}">
                {% block buy_widget_data %}
                    {% block buy_widget_data_rich_snippet_url %}
                        <meta itemprop="url"
                              content="{{ seoUrl('frontend.detail.page', { productId: product.id }) }}"/>
                    {% endblock %}

                    {% block buy_widget_data_rich_snippet_price_range %}
                        {% if product.calculatedPrices|length > 1 %}
                            {% set lowestPrice = false %}
                            {% set highestPrice = false %}

                            {% for price in product.calculatedPrices %}
                                {% if not lowestPrice or price.unitPrice < lowestPrice %}
                                    {% set lowestPrice = price.unitPrice %}
                                {% endif %}
                                {% if not highestPrice or price.unitPrice > highestPrice %}
                                    {% set highestPrice = price.unitPrice %}
                                {% endif %}
                            {% endfor %}

                            <meta itemprop="lowPrice" content="{{ lowestPrice }}"/>
                            <meta itemprop="highPrice" content="{{ highestPrice }}"/>
                            <meta itemprop="offerCount" content="{{ product.calculatedPrices|length }}"/>
                        {% endif %}
                    {% endblock %}

                    {% block buy_widget_data_rich_snippet_price_currency %}
                        <meta itemprop="priceCurrency"
                              content="{{ context.currency.translated.shortName }}"/>
                    {% endblock %}

                    {% block buy_widget_price %}
                        <div class="product-detail-price-container">
                            {% sw_include '@Storefront/storefront/component/buy-widget/buy-widget-price.html.twig' %}
                        </div>
                    {% endblock %}

                    {% block buy_widget_tax %}
                        <div class="product-detail-tax-container">
                            {% if context.taxState == "gross" %}
                                {% set taxText = "general.grossTaxInformation"|trans|sw_sanitize %}
                            {% else %}
                                {% set taxText = "general.netTaxInformation"|trans|sw_sanitize %}
                            {% endif %}

                            <p class="product-detail-tax">
                                {% block buy_widget_tax_link %}
                                    <a class="product-detail-tax-link"
                                       href="{{ path('frontend.cms.page',{ id: config('core.basicInformation.shippingPaymentInfoPage') }) }}"
                                       title="{{ taxText }}"
                                       data-toggle="modal"
                                       data-url="{{ path('frontend.cms.page',{ id: config('core.basicInformation.shippingPaymentInfoPage') }) }}">
                                        {{ taxText }}
                                    </a>
                                {% endblock %}
                            </p>
                        </div>
                    {% endblock %}

                    {% block buy_widget_deposit %}
                        {% if page.product.translated.customFields.deposit %}
                            {% set deposit = page.product.translated.customFields.deposit|currency %}

                            <div class="product-detail-deposit">
                                {{ "FlowsiteDepositSystemBasic.plusDeposit"|trans({
                                    '%deposit%': deposit
                                })|sw_sanitize }}
                            </div>
                        {% endif %}
                    {% endblock %}

                    {% set remoteClickOptions = {
                        selector: "#review-tab-" ~ product.id,
                        scrollToElement: true
                    } %}

                    {% set reviewTabHref = "#review-tab-" ~ product.id ~ "-pane" %}

                    {% block buy_widget_reviews %}
                        {% if product.ratingAverage > 0 and totalReviews > 0 and config('core.listing.showReview') %}
                            <div class="product-detail-reviews">

                                {% sw_include '@Storefront/storefront/component/review/rating.html.twig' with {
                                    points: product.ratingAverage,
                                    style: 'text-primary'
                                } %}
                                <a data-toggle="tab"
                                   class="product-detail-reviews-link"
                                   data-offcanvas-tabs="true"
                                   data-remote-click="true"
                                   data-remote-click-options='{{ remoteClickOptions|json_encode }}'
                                   href="{{ reviewTabHref }}"
                                   aria-controls="review-tab-pane">
                                    {{ totalReviews }}
                                    {{ "detail.reviewLinkText"|trans({'%count%': totalReviews})|sw_sanitize }}
                                </a>
                            </div>
                        {% endif %}
                    {% endblock %}
                {% endblock %}

                {% block buy_widget_configurator_include %}
                    {% if product.parentId and configuratorSettings|length > 0 %}
                        <div class="product-detail-configurator-container">
                            {% sw_include '@Storefront/storefront/component/buy-widget/configurator.html.twig' %}
                        </div>
                    {% endif %}
                {% endblock %}

                {% block buy_widget_buy_form %}
                    {% if product.active %}
                        <div class="product-detail-form-container">
                            {% sw_include '@Storefront/storefront/component/buy-widget/buy-widget-form.html.twig' %}
                        </div>
                    {% endif %}
                {% endblock %}
            </div>
        {% endblock %}

        {% block buy_widget_delivery_informations %}
            <div class="product-detail-delivery-information">
                {% sw_include '@Storefront/storefront/component/delivery-information.html.twig' %}
            </div>
        {% endblock %}

        {% if config('core.cart.wishlistEnabled') %}
            {% block buy_widget_wishlist %}
                {% sw_include '@Storefront/storefront/component/product/card/wishlist.html.twig' with {
                    showText: true,
                    size: 'md',
                    productId: product.id
                } %}
            {% endblock %}
        {% endif %}

        {% block buy_widget_ordernumber_container %}
        {% endblock %}
    </div>
{% endblock %}