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

{% block title %}
  {% trans "Koszyk na zakupy" %}
{% endblock %}

{% block content %}
  <h1>{% trans "Koszyk na zakupy" %}</h1>
  <table class="cart">
    <thead>
      <tr>
        <th>{% trans "Obraz" %}</th>
        <th>{% trans "Produkt" %}</th>
        <th>{% trans "Ilość" %}</th>
        <th>{% trans "Usuń" %}</th>
        <th>{% trans "Cena jednostkowa" %}</th>
        <th>{% trans "Kwota" %}</th>
      </tr>
    </thead>
    <tbody>
      {% for item in cart %}
        {% with product=item.product %}
          <tr>
            <td>
              <a href="{{ product.get_absolute_url }}">
                <img src="{% if product.image %}{{ product.image.url }}{% else %}{% static "img/no_image.png" %}{% endif %}">
              </a>
            </td>
            <td>{{ product.name }}</td>
            <td>
              <form action="{% url "cart:cart_add" product.id %}" method="post">
                {{ item.update_quantity_form.quantity }}
                {{ item.update_quantity_form.update }}
                <input type="submit" value="Zmień">
                {% csrf_token %}
              </form>
            </td>
            <td><a href="{% url "cart:cart_remove" product.id %}">{% trans "Usuń" %}</a></td>
            <td class="num">${{ item.price }}</td>
            <td class="num">${{ item.total_price }}</td>
          </tr>
        {% endwith %}
      {% endfor %}
      {% if cart.coupon %}
        <tr class="subtotal">
          <td>{% trans "Wartość całkowita" %}</td>
          <td colspan="4"></td>
          <td class="num">${{ cart.get_total_price|floatformat:"2" }}</td>
        </tr>
        <tr>
          {% blocktrans with code=cart.coupon.code discount=cart.coupon.discount %}
              <td>"{{ code }}" coupon ({{ discount }}% off)</td>
          {% endblocktrans %}
          <td colspan="4"></td>
          <td class="num neg">
            - ${{ cart.get_discount|floatformat:"2" }}
          </td>
        </tr>
      {% endif %}
      <tr class="total">
        <td>{% trans "Kwota do zapłaty" %}</td>
        <td colspan="4"></td>
        <td class="num">
          ${{ cart.get_total_price_after_discount|floatformat:"2" }}
        </td>
      </tr>
    </tbody>
  </table>
  {% if recommended_products %}
    <div class="recommendations cart">
      <h3>{% trans "Z tym produktem klienci kupowali również:" %}</h3>
      {% for p in recommended_products %}
        <div class="item">
          <a href="{{ p.get_absolute_url }}">
            <img src="{% if p.image %}{{ p.image.url }}{% else %}{% static "img/no_image.png" %}{% endif %}">
          </a>
          <p><a href="{{ p.get_absolute_url }}">{{ p.name }}</a></p>
        </div>
      {% endfor %}
    </div>
  {% endif %}
  <p>{% trans "Kupon rabatowy" %}:</p>
  <form action="{% url "coupons:apply" %}" method="post">
    {{ coupon_apply_form }}
    <input type="submit" value="{% trans "Wprowadź" %}">
    {% csrf_token %}
  </form>
  <p class="text-right">
    <a href="{% url "shop:product_list" %}" class="button light">{% trans "Kontynuuj zakupy" %}</a>
    <a href="{% url "orders:order_create" %}" class="button">
      {% trans "Do kasy" %}
    </a>
  </p>
{% endblock %}