{# @deprecated tag:v6.7.0 - File will be removed as it is no longer loaded by default. #}
{# Extend `src/Storefront/Resources/views/storefront/component/buy-widget/buy-widget-form.html.twig` instead #}

{% set formAction = path('frontend.checkout.line-item.add') %}

{% block page_product_detail_buy_form_inner %}
    {# @var page \Shopware\Storefront\Page\Product\ProductPage #}

    {# @var product \Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity #}
    {% set product = page.product %}

    <form
        id="productDetailPageBuyProductForm"
        action="{{ formAction }}"
        method="post"
        class="buy-widget"
        data-add-to-cart="true">
        {% set DOWNLOAD_STATE = constant('Shopware\\Core\\Content\\Product\\State::IS_DOWNLOAD') %}
        {% set showQuantitySelect = not product.states is defined or DOWNLOAD_STATE not in product.states or (DOWNLOAD_STATE in product.states and product.maxPurchase !== 1) %}
        {% set buyable = product.available and product.childCount <= 0 and product.calculatedMaxPurchase > 0 %}

        {% block page_product_detail_buy_container %}
            {% if buyable %}
                <div class="row g-2 buy-widget-container">
                    {% block page_product_detail_buy_quantity_container %}
                        {% if showQuantitySelect %}
                            <fieldset class="col-4 d-flex justify-content-end">
                                {# @deprecated tag:v6.7.0 - Unused variable selectQuantityThreshold will be removed without replacement #}
                                {% set selectQuantityThreshold = 100 %}

                                {% block page_product_detail_buy_quantity %}
                                    {% block page_product_detail_buy_quantity_input_group %}
                                        <legend class="form-label visually-hidden">
                                            {{ 'component.product.quantitySelect.legend'|trans|striptags }}
                                        </legend>

                                        <div id="product-detail-quantity-group-{{ product.id }}" class="input-group product-detail-quantity-group quantity-selector-group" data-quantity-selector="true">
                                            {% block page_product_detail_buy_quantity_input %}
                                                <button type="button" class="btn btn-outline-light btn-minus js-btn-minus" aria-label="{{ 'component.product.quantitySelect.decrease'|trans|striptags }}">
                                                    {% sw_icon 'minus' style {size: 'xs'} %}
                                                </button>
                                                <input
                                                    type="number"
                                                    name="lineItems[{{ product.id }}][quantity]"
                                                    class="form-control js-quantity-selector quantity-selector-group-input product-detail-quantity-input"
                                                    min="{{ product.minPurchase }}"
                                                    max="{{ product.calculatedMaxPurchase }}"
                                                    step="{{ product.purchaseSteps }}"
                                                    value="{{ product.minPurchase }}"
                                                    aria-label="{{ 'component.product.quantitySelect.label'|trans|striptags }}"
                                                />
                                                <button type="button" class="btn btn-outline-light btn-plus js-btn-plus" aria-label="{{ 'component.product.quantitySelect.increase'|trans|striptags }}">
                                                    {% sw_icon 'plus' style {size: 'xs'} %}
                                                </button>
                                            {% endblock %}

                                            {% block page_product_detail_buy_quantity_input_unit %}
                                                {% if product.translated.packUnit %}
                                                    <span class="input-group-text">
                                                        {% if product.minPurchase > 1 and product.translated.packUnitPlural %}
                                                            {{ product.translated.packUnitPlural }}
                                                        {% elseif product.translated.packUnit %}
                                                            {{ product.translated.packUnit }}
                                                        {% endif %}
                                                    </span>
                                                {% endif %}
                                            {% endblock %}
                                        </div>

                                        {# Aria live region to tell the screen reader what quantity amount is selected when changing the quantity. #}
                                        {% block page_product_detail_buy_quantity_live_area %}
                                            <div
                                                class="quantity-area-live visually-hidden"
                                                aria-live="polite"
                                                aria-atomic="true"
                                                data-aria-live-text="{{ 'component.product.quantitySelect.areaLiveText'|trans|striptags }}"
                                                data-aria-live-product-name="{{ product.translated.name }}">
                                                {# The live region content is generated by the `QuantitySelectorPlugin` #}
                                            </div>
                                        {% endblock %}
                                    {% endblock %}
                                {% endblock %}
                            </fieldset>
                        {% endif %}
                    {% endblock %}

                    {% block page_product_detail_buy_redirect_input %}
                        {# fallback redirect back to detail page is deactivated via js #}
                        <input type="hidden"
                               name="redirectTo"
                               value="frontend.detail.page">

                        <input type="hidden"
                               name="redirectParameters"
                               data-redirect-parameters="true"
                               value="{{ {productId: product.id}|json_encode }}">
                    {% endblock %}

                    {% block page_product_detail_buy_product_buy_info %}
                        <input type="hidden"
                               name="lineItems[{{ product.id }}][id]"
                               value="{{ product.id }}">
                        <input type="hidden"
                               name="lineItems[{{ product.id }}][type]"
                               value="product">
                        <input type="hidden"
                               name="lineItems[{{ product.id }}][referencedId]"
                               value="{{ product.id }}">
                        <input type="hidden"
                               name="lineItems[{{ product.id }}][stackable]"
                               value="1">
                        <input type="hidden"
                               name="lineItems[{{ product.id }}][removable]"
                               value="1">
                    {% endblock %}

                    {% block page_product_detail_product_buy_meta %}
                        <input type="hidden"
                               name="product-name"
                               value="{{ product.translated.name }}">
                        <input type="hidden"
                               name="brand-name"
                               value="{{ product.manufacturer.getName() }}">
                    {% endblock %}

                    {% block page_product_detail_buy_button_container %}
                        <div class="{% if showQuantitySelect %}col-8{% else %}col-12{% endif %}">
                            {% block page_product_detail_buy_button %}
                                <div class="d-grid">
                                    <button class="btn btn-primary btn-buy"
                                            title="{{ 'detail.addProduct'|trans|striptags }}"
                                            aria-label="{{ 'detail.addProduct'|trans|striptags }}">
                                        {{ 'detail.addProduct'|trans|sw_sanitize }}
                                    </button>
                                </div>
                            {% endblock %}
                        </div>
                    {% endblock %}
                </div>
            {% endif %}
        {% endblock %}
    </form>
{% endblock %}
