{% extends "shop/base.html" %}
{% load i18n %}
{% load satchmo_cart %}
{% load satchmo_currency %}
{% load satchmo_util %}
{% load satchmo_product %}
{% load satchmo_discounts %}
{% load normalize_decimal %}

{% block navbar %}
    <li class="first"><a href="{{shop_base}}/">{% trans "Home" %}</a></li>
    <li>{% trans "Cart" %}</li>
{% endblock %}

{% block content %}

{% if error_message %}
<div class="error">{{ error_message }}</div>
{% endif %}
{% if messages %}
<ul class="messages">
    {% for message in messages %}
    <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
    {% endfor %}
</ul>
{% endif %}

{% if not cart|length %}
    <h4>{% trans "Your cart is empty." %}</h4>
{% else %}
    <h4>{% trans "Your Cart" %}</h4>
    <table><tr><th></th>
    <th align="left">{% trans "Quantity" %}</th>
    <th>{% trans "Item" %}</th>
    {% if sale %}
		<th>{% trans "Regular Price" %}</th>
		<th>{% trans "Sale Price" %}
	{% else %}
		<th>{% trans "Price" %}</th>
	{% endif %}
    <th align="center">{% if default_view_tax %}{% trans "Total<br/>(incl.&nbsp;tax)" %}{% else %}{% trans "Total" %}{% endif %}</th>
    </tr>

    {% for cartitem in cart %}
        <tr><td>
            <form action="{% url satchmo_cart_remove %}" method="post">{% csrf_token %}
                <input type="hidden" name="cartitem" value="{{ cartitem.id }}" />
                <input type="submit" value="{% trans 'Remove' %}" />
            </form>
            </td>
            <td align="center">
                <form class="qtyform" id="form-{{ cartitem.id }}" action="{% url satchmo_cart_set_qty %}" method="post">{% csrf_token %}
                    <input type="hidden" name="cartitem" value="{{ cartitem.id }}" />
					<input type="text" name="quantity" id="id_quantity" value="{{ cartitem.quantity|normalize_decimal }}" />
                    <input type="submit" id="id_update_submit" value="{% trans 'update amount' %}" />
                </form>
            </td>
            <td><a href="{{cartitem.product.get_absolute_url}}">{{ cartitem.description }}</a></td>
			{% if sale %}<td align="center">{{ cartitem.unit_price|currency }}</td>{% endif %}
			<td align="center">{{ cartitem|discount_line_unit_price:sale|currency }}</td>
            <td align="center">{{ cartitem|discount_line_total:sale|currency }}</td>
        </tr>
		{% cartitem_custom_details cartitem %}
		{% cartitem_subscription_details cartitem %}
    {% endfor %}
    <tr><td colspan="{% if sale %}5{% else %}4{% endif %}" align="right">{% trans "Cart Total" %}:</td>
        <td>{{ cart|discount_cart_total:sale|currency }}</td></tr>
    </table>
    {% if sale %}
	{% include "product/some_discount_eligible.html" %}
	{% endif %}

    <a href="{% url satchmo_checkout-step1 %}">{% trans "Check out" %}</a>
{% endif %}
{% endblock %}
