{% load basket_tags %}
{% load display_tags %}
{% load i18n %}
{% load purchase_info_tags %}
{% load ocyan_main %}

{% basket_form request product 'multiple' as basket_form %}
{% purchase_info_for_product request product as session %}
<div class="add-to-basket-wrapper">
    {% block availability_message %}
    <div class="availability-message {% if not session.availability.is_available_to_buy %}alert alert-danger{% elif session.stockrecord.is_below_threshold or session.availability.is_backorder %}alert alert-warning{% else %}alert alert-success{% endif %}" aria-live="polite">
        <small><i class="fa {% if not session.availability.is_available_to_buy %}fa-times{% elif session.stockrecord.is_below_threshold or session.availability.is_backorder %}fa-exclamation-triangle{% else %}fa-check{% endif %}"></i> {{session.availability.message}}</small>
    </div>
    {% endblock %}
    {% if session.availability.is_available_to_buy %}
    <form id="add_to_basket_form" action="{% url 'basket:add' pk=product.pk  %}" method="post" class="add-to-basket-form">
        {% csrf_token %}
        <div {% if product.has_options %}class="product-options"{% endif %}>
            {% include "oscar/partials/basket_form_fields.html" with form=basket_form class=ok %}
        </div>
        <div class="basket-button-wrapper">
            <div class="basket-inline">
                <label for="#id_quantity">
                {% include 'oscar/partials/form_field.html' with field=basket_form.quantity nolabel=True %}
                </label>
                <button type="submit" class="btn btn-primary btn-add-to-basket" accesskey="b" value="{% trans "Add to basket" %}" data-loading-text="{% trans 'Adding...' %}">
                    <i class="fa fa-shopping-cart-solid"></i> {% trans "Basket" %}
                </button>
            </div>
            {% iffeature "wishlists" %}
            {% esi_fragment "oscar/catalogue/partials/add_to_wishlist.html" with sessionid=True name="wishlist" user=user product=product csrf_token=csrf_token only %}
            {% endiffeature %}
        </div>
    </form>
    {% else %}
    {% if not has_active_alert %}
    <div class="col-12">
        <form id="alert_form" method="post" action="{% url 'customer:alert-create' pk=product.id %}" class="add-to-basket-form product-unavailable">
            {% csrf_token %}
            <div class="stock-alert">
                {% trans "You can get an email alert when this product is back in stock." %}
                {% include "oscar/partials/form_fields.html" with form=alert_form %}
            </div>
            
            <div class="basket-button-wrapper">
                <button type="submit" class="btn btn-secondary btn-notify" accesskey="n" data-loading-text="{% trans 'Submitting...' %}">
                    <i class="fa fa-envelope"></i> {% trans "Notify me" %}
                </button>
                {% iffeature "wishlists" %}
                {% esi_fragment "oscar/catalogue/partials/add_to_wishlist.html" with sessionid=True name="wishlist" user=user product=product csrf_token=csrf_token only %}
                {% endiffeature %}
            </div>
        </form>
    </div>
    {% else %}
    <div class="stock-alert stock-alert-active" aria-live="assertive">
        {% trans "You have an active stock alert for this product." %}
    </div>

    <div class="basket-button-wrapper">
        
        {% iffeature "wishlists" %}
        {% esi_fragment "oscar/catalogue/partials/add_to_wishlist.html" with sessionid=True name="wishlist" user=user product=product csrf_token=csrf_token only %}
        {% endiffeature %}
    </div>
    {% endif %}
    {% endif %}
</div>