{% extends "oscar/basket/partials/basket_content.html" %}
{% load i18n %}
{% load thumbnail %}
{% load currency_filters %}
{% load purchase_info_tags %}
{% load widget_tweaks %}
{% load ocyanjson %}

    {% block basket_form_main %}
        {% ocyanjson "oscar" "show_tax_everywhere" False as show_tax %}
        <form method="post" class="basket_summary" id="basket_formset">
            {% csrf_token %}
            {{ formset.management_form }}

            {% for form in formset %}
                {% with line=form.instance product=form.instance.product %}
                    {% purchase_info_for_line request line as session %}
                    <div class="basket-items">
                        <div class="row">
                            <div class="col-sm-2">
                                {{ form.id }}
                                {% with image=product.primary_image %}
                                    {% thumbnail image.original "100x100" upscale=False as thumb %}
                                        <a href="{{ product.get_absolute_url }}">
                                            <img class="thumbnail" src="{{ thumb.url }}" alt="{{ product.get_title }}"/>
                                        </a>
                                    {% endthumbnail %}
                                {% endwith %}
                            </div>
                            <div class="col-sm-4">
                                <h3><a href="{{ product.get_absolute_url }}">{{ line.description }}</a></h3>
                                <p class="availability {{ session.availability.code }}">{{ session.availability.message }}</p>
                            </div>
                            <div class="col-sm-3">
                                <div class="checkout-quantity">
                                    <div class="input-group  {% if form.errors %}error{% endif %}">
                                        {% render_field form.quantity class+="form-control" %}
                                    <span class="input-group-btn">
                                        <button class="btn btn-default" type="submit" data-loading-text="{% trans 'Updating...' %}">{% trans "Update" %}</button>
                                    </span>
                                    </div>
                                </div>
                                    <div>
                                        <a href="#" data-id="{{ forloop.counter0 }}" data-behaviours="remove" class="inline">{% trans "Remove" %}</a>
                                        {% if user.is_authenticated %}
                                            | <a href="#" data-id="{{ forloop.counter0 }}" data-behaviours="save" class="inline">{% trans "Save for later" %}</a>
                                        {% endif %}
                                        <div style="display:none">
                                            {{ form.save_for_later }}
                                            {{ form.DELETE }}
                                        </div>
                                        {% for field_errors in form.errors.values %}
                                            {% for error in field_errors %}
                                                <span class="error-block"><i class="icon-exclamation-sign"></i> {{ error }}</span>
                                            {% endfor %}

                                        {% endfor %}
                                    </div>

                            </div>
                            <div class="col-sm-1">
                                {% if not line.unit_price_incl_tax and not line.unit_tax_excl_tax %}
                                    <p class="align-right">&mdash;</p>
                                {% else %}
                                    <p class="price_color align-right">
                                        {% if line.is_tax_known %}
                                            {{ line.unit_price_incl_tax|currency:line.price_currency }}{% if show_tax %}<br/>
                                            {% with line.unit_price_excl_tax|currency:line.price_currency as price_excl_tax %}
                                            <small>{% blocktrans %}Excl. tax {{ price_excl_tax }}{% endblocktrans %}</small>
                                            {% endwith %}{% endif %}
                                        {% else %}
                                            {{ line.unit_price_excl_tax|currency:line.price_currency }}
                                        {% endif %}
                                    </p>
                                {% endif %}
                            </div>
                            <div class="col-sm-2">
                                {% if not line.line_price_incl_tax and not line_price_excl_tax %}
                                    <p class="align-right">&mdash;</p>
                                {% else %}
                                    <p class="price_color align-right">
                                        {% if line.is_tax_known %}
                                            {{ line.line_price_incl_tax|currency:line.price_currency }}{% if show_tax %}<br/>
                                            {% with line.line_price_excl_tax|currency:line.price_currency as price_excl_tax %}
                                            <small>{% blocktrans %}Excl. tax {{ price_excl_tax }}{% endblocktrans %}</small>
                                            {% endwith %}{% endif %}
                                        {% else %}
                                            {{ line.line_price_excl_tax|currency:line.price_currency }}
                                        {% endif %}
                                    </p>
                                {% endif %}
                            </div>
                        </div>
                    </div>
                {% endwith %}
            {% endfor %}
        </form>
    {% endblock %}
