{% extends "shop/base.html" %}
{% load i18n %}

{% block body %}
  <h1>{% trans "Your shopping cart" %}</h1>
  {% if cart_items %}

      <form method="post" action="{% url cart_update %}">
        {% csrf_token %}
        {{ formset.management_form }}
        {% for form in formset %}
          {{ form.id }}
        {% endfor %}
        <table border="1">
          <thead>
            <tr>
            <th>{% trans "Product name" %}</th>
            <th>{% trans "Unit price" %}</th>
            <th>{% trans "Quantity" %}</th>
            <th>&nbsp;</th>
            </tr>
          </thead>

          <tbody>
            {% for form in formset %}
              {% with form.quantity as field %}
                <tr>
                  <td>{{ form.instance.product.get_name }}</td>
                  <td>{{ form.instance.product.get_price }}</td>
                  <td>
                      {{ field.errors }}
                      {{ field }}</td>
                  <td>{{ form.instance.line_subtotal }}</td>
                </tr>
                {% for extra_price_field in form.instance.extra_price_fields %}
                  <tr>
                    <td colspan="2">&nbsp;</td>
                    <td>{{ extra_price_field.0 }}</td>
                    <td>{{ extra_price_field.1 }}</td>
                  </tr>
                {% endfor %}
                <tr><td colspan="2">&nbsp;</td><td>{% trans "Line Total" %}:</td><td>{{ form.instance.line_total }}</td></tr>
              {% endwith %}
            {% endfor %}
          </tbody>

          <tfoot>
            <tr><td colspan="2">&nbsp;</td><td>{% trans "Cart Subtotal" %}</td><td>{{cart.subtotal_price}}</td></tr>
            {% for extra_price_field in cart.extra_price_fields %}
              <tr>
                <td colspan="2">&nbsp;</td>
                <td>{{ extra_price_field.0 }}</td>
                <td>{{ extra_price_field.1 }}</td>
              </tr>
            {% endfor %}
            <tr><td colspan="2">&nbsp;</td><td><b>{% trans "Cart Total" %}</b></td><td><b>{{cart.total_price}}</b></td></tr>
          </tfoot>
        </table>

        <p><input type="submit" value="{% trans "Update Shopping Cart" %}"/></p>
      </form>

      <form action="{% url cart_delete %}" method="post">
        {% csrf_token %}
        <p><input type="submit" value="{% trans "Empty Shopping Cart" %}"/></p>
      </form>

      <p>
        <a href="{% url checkout_selection %}">{% trans "Proceed to checkout" %}</a>
      </p>

  {% else %}
  <p>
    {% trans "Shopping cart is empty" %}
  </p>
  {% endif %}
{% endblock %}
