{% load i18n %}
{% load lfs_tags %}

{% if cart.items %}

    <h1 class="first-heading">
        {% trans "Voucher" %}
    </h1>
    <input data="{% url lfs_check_voucher_cart %}"
           type="text"
           id="voucher"
           name="voucher"
           value="{{ voucher_number }}"
           size="30" />

    {% if voucher_number and voucher_message %}
        <span class="voucher-message">
            {{ voucher_message }}
        </span>
    {% endif %}

    <h1 class="title">
        {% trans 'Your Cart' %}
    </h1>

    <form id="cart-form"
          action="{% url lfs.cart.views.refresh_cart %}"
          onsubmit="return false;">

        <table class="lfs-default">
            <tr>
                <th colspan="2">
                    {% trans 'Product' %}
                </th>
                <th class="number">
                    {% trans 'Amount' %}
                </th>
                <th class="number">
                    {% trans 'Price' %}
                </th>
                <th class="number">
                    {% trans 'Included VAT' %}
                </th>
                <th class="number">
                    {% trans 'Total' %}
                </th>
                <th></th>
            </tr>
            {% for cart_item in cart.items %}
                <tr>
                    <td class="image">
                        {% if cart_item.product.get_image.url_60x60 %}
                            <a href="{{ cart_item.product.get_absolute_url }}">
                                <img src="{{ cart_item.product.get_image.url_60x60 }}"
                                     alt="{{ cart_item.product.get_name }}"/>
                            </a>
                        {% endif %}
                    </td>
                    <td>
                        <span class="product-title">
                            <a href="{{ cart_item.product.get_absolute_url }}">
                                {{ cart_item.product.get_name }}
                            </a>
                        </span>
                        {% for property in cart_item.product.get_variant_properties %}
                            <div>
                                {{ property.title }}: {{ property.value }} {{ property.unit|safe }}
                            </div>
                        {% endfor %}

                        {% for property in cart_item.product.get_displayed_properties %}
                            <div>
                                {{ property.title }}: {{ property.value }} {{ property.unit|safe }}
                            </div>
                        {% endfor %}

                        {% if cart_item.product.is_configurable_product %}
                            {% for property in cart_item.get_properties %}
                                <div>
                                    {{ property.title }}: {{ property.value }} {{ property.unit|safe }}
                                    {% if property.display_price %}
                                        ({{ property.price|currency }})
                                    {% endif %}
                                </div>
                            {% endfor %}
                        {% endif %}

                    </td>
                    <td class="number">
                        <input class="number cart-amount"
                               type="text"
                               name="amount-cart-item_{{ cart_item.id }}"
                               size="6"
                               value="{{ cart_item.amount }}" />
                               {% if cart_item.product.unit %}
                                    {{ cart_item.product.unit }}
                               {% endif %}

                        {% if cart_item.product.active_packing_unit %}
                            <span class="packing-unit">
                                ({{ cart_item|packages }} {{ cart_item.product.packing_unit_unit }})
                            </span>
                        {% endif %}
                    </td>
                    <td class="number"
                        nowrap="nowrap">
                        {{ cart_item.product.get_price|currency }}
                        {# {{ cart_item.product.get_price|currency }} #}
                        {% if cart_item.product.price_unit %}
                            / {{ cart_item.product.price_unit }}
                        {% endif %}
                    </td>
                    <td class="number"
                        nowrap="nowrap">
                        ({{ cart_item.get_tax|currency }})
                    </td>
                    <td class="number"
                        nowrap="nowrap">
                        {{ cart_item.get_price|currency }}
                    </td>
                    <td class="right">
                        <a href="{% url lfs_delete_cart_item cart_item.id %}"
                           title="{% trans 'Delete item' %}"
                           class="delete-button delete-cart-item">X</a>
                    </td>
                </tr>
            {% endfor %}
            {% for discount in discounts %}
                <tr id="discounts-display">
                    <td></td>
                    <td class="left">
                        {{ discount.name }}
                    </td>
                    <td class="number">
                        1
                    </td>
                    <td class="number">

                    </td>
                    <td class="number">
                        {% if discount.tax %}
                            ({{ discount.tax|currency }})
                        {% endif %}
                    </td>
                    <td class="number">
                        - {{ discount.price|currency }}
                    </td>
                    <td></td>
                </tr>
            {% endfor %}

            {% if display_voucher %}
                <tr id="voucher-display">
                    <td></td>
                    <td class="product-title left">
                        {% trans "Voucher" %}
                    </td>
                    <td class="number">
                        1
                    </td>
                    <td class="number">
                        - {{ voucher_value|currency }}
                    </td>
                    <td class="number">
                        ({{ voucher_tax|currency }})
                    </td>
                    <td class="number">
                        - {{ voucher_value|currency }}
                    </td>
                    <td></td>
                </tr>
            {% endif %}

            <tr>
                <td></td>
                <td></td>
                <td class="left">
                    {% trans 'Country' %}:
                </td>
                <td>
                    <select class="cart-country"
                            name="country">
                        {% for country in countries %}
                            <option {% ifequal country.id selected_country.id  %}selected="selected"{% endifequal %}
                                    value="{{ country.id }}">
                                {{ country.name }}
                            </option>
                        {% endfor %}
                    </select>
                </td>
                <td colspan="2"></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td class="left">
                    {% trans 'Shipping' %}:
                </td>
                <td>
                    <select class="cart-shipping-method"
                            name="shipping_method">
                        {% for shipping_method in shipping_methods %}
                            <option {% ifequal shipping_method.id selected_shipping_method.id  %}selected="selected"{% endifequal %}
                                    value="{{ shipping_method.id }}">
                                {{ shipping_method.name }}
                            </option>
                        {% endfor %}
                    </select>
                </td>
                <td></td>
                <td class="number"
                    nowrap="nowrap">
                    {{ shipping_price|currency }}
                </td>
                <td></td>
            </tr>

            <tr>
                <td></td>
                <td></td>
                <td class="left">
                    {% trans 'Payment' %}:
                </td>
                <td>
                    <select class="cart-payment-method"
                            name="payment_method">
                        {% for payment_method in payment_methods %}
                            <option {% ifequal payment_method.id selected_payment_method.id  %}selected="selected"{% endifequal %}
                                    value="{{ payment_method.id }}">
                                {{ payment_method.name }}
                            </option>
                        {% endfor %}
                    </select>
                </td>
                <td></td>
                <td class="number"
                    nowrap="nowrap">
                    {{ payment_price|currency }}
                </td>
                <td></td>
            </tr>

            <tr>
                <td></td>
                <td></td>
                <td colspan="3"
                    class="total left padding-top">
                    {% trans 'Total' %}:
                </td>
                <td class="total number padding-top"
                    nowrap="nowrap">
                    {{ cart_price|currency }}
                </td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td colspan="3"
                    class="discreet left">
                    {% trans 'Inclusive VAT' %}:
                </td>
                <td class="discreet number"
                    nowrap="nowrap">
                    {{ cart_tax|currency }}
                </td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td colspan="5"
                    class="discreet left padding-top">
                    {% trans 'Total delivery time' %}: {{ max_delivery_time }}
                </td>
            </tr>
            <tr>
                <td colspan="7">
                    <div class="buttons">
                        <a class="button checkout-button emphasized"
                           href="{% url lfs_checkout_dispatcher %}">
                           {% trans 'Checkout' %}
                        </a>
                        <a class="button shopping-button"
                           href="{{ shopping_url }}">
                            {% trans 'Go on shopping' %}
                        </a>
                    </div>
                </td>
            </tr>
        </table>
    </form>
{% else %}
    <h1 class="title">
        {% trans 'Your Cart is empty' %}
    </h1>
    <a class="button emphasized left"
       href="{{ shopping_url }}">
       {% trans 'Go on shopping' %}
    </a>
{% endif %}
