{% extends "pretixpresale/event/base.html" %}
{% load i18n %}
{% load l10n %}
{% load money %}
{% load eventurl %}
{% load eventsignal %}
{% load thumb %}
{% load rich_text %}
{% block title %}{% trans "Voucher redemption" %}{% endblock %}

{% block content %}
    <h2>{% trans "Voucher redemption" %}</h2>
    {% if subevent %}
        <h3>{{ subevent.name }}</h3>
        {% with ev=subevent %}
            <div class="info-row">
                <span class="fa fa-clock-o fa-fw"></span>
                <p>
                    {{ ev.get_date_range_display }}
                    {% if event.settings.show_times %}
                        <br>
                        {% blocktrans trimmed with time=ev.date_from|date:"TIME_FORMAT" %}
                            Begin: {{ time }}
                        {% endblocktrans %}
                        {% if event.settings.show_date_to and ev.date_to %}
                            <br>
                            {% blocktrans trimmed with time=ev.date_to|date:"TIME_FORMAT" %}
                                End: {{ time }}
                            {% endblocktrans %}
                        {% endif %}
                    {% endif %}
                    {% if ev.date_admission %}
                        <br>
                        {% if ev.date_admission|date:"SHORT_DATE_FORMAT" == ev.date_from|date:"SHORT_DATE_FORMAT" %}
                            {% blocktrans trimmed with time=ev.date_admission|date:"TIME_FORMAT" %}
                                Admission: {{ time }}
                            {% endblocktrans %}
                        {% else %}
                            {% blocktrans trimmed with datetime=ev.date_admission|date:"SHORT_DATETIME_FORMAT" %}
                                Admission: {{ datetime }}
                            {% endblocktrans %}
                        {% endif %}
                    {% endif %}
                    <br>
                    {% if subevent %}
                        <a href="{% eventurl event "presale:event.ical.download" subevent=subevent.pk %}">
                    {% else %}
                        <a href="{% eventurl event "presale:event.ical.download" %}">
                    {% endif %}
                        {% trans "Add to Calendar" %}
                    </a>
                </p>
            </div>
        {% endwith %}
    {% endif %}

    <p>
        {% blocktrans trimmed %}
            You entered a voucher code that allows you to buy one of the following products at the specified price:
        {% endblocktrans %}
    </p>
    {% if event.presale_is_running or event.settings.show_items_outside_presale_period %}
        <form method="post"
                action="{% eventurl request.event "presale:event.cart.add" cart_namespace=cart_namespace %}?next={{ cart_redirect|urlencode }}{% if "iframe" in request.GET and not new_tab %}&iframe={{ request.GET.iframe }}{% endif %}{% if "take_cart_id" in request.GET and new_tab %}&take_cart_id={{ request.GET.take_cart_id }}{% endif %}" {% if new_tab %}target="_blank"{% else %}
                data-asynctask
                data-asynctask-headline="{% trans "We're now trying to reserve this for you!" %}"
                class="{% if voucher.seating_available %}has-seating{% endif %}"
                data-asynctask-text="{% blocktrans with time=event.settings.reservation_time %}Once the items are in your cart, you will have {{ time }} minutes to complete your purchase.{% endblocktrans %}"
            {% endif %}>
            {% csrf_token %}
            <input type="hidden" name="subevent" value="{{ subevent.id|default_if_none:"" }}" />
            <input type="hidden" name="_voucher_code" value="{{ voucher.code }}">

            {% if seating_available %}
                {% if event.has_subevents %}
                    {% eventsignal event "pretix.presale.signals.render_seating_plan" request=request subevent=subevent voucher=voucher %}
                {% else %}
                    {% eventsignal event "pretix.presale.signals.render_seating_plan" request=request voucher=voucher %}
                {% endif %}
            {% endif %}

            {% for tup in items_by_category %}
                <section>
                    {% if tup.0 %}
                        <h3>{{ tup.0.name }}</h3>
                        {% if tup.0.description %}
                            <p>{{ tup.0.description|localize|rich_text }}</p>
                        {% endif %}
                    {% endif %}
                    {% for item in tup.1 %}
                        {% if item.has_variations %}
                            <div class="item-with-variations">
                                <div class="row-fluid product-row headline">
                                    <div class="col-md-8 col-xs-12">
                                        {% if item.picture %}
                                            <a href="{{ item.picture.url }}" class="productpicture"
                                                    data-title="{{ item.name|force_escape|force_escape }}"
                                                    {# Yes, double-escape to prevent XSS in lightbox #}
                                                    data-lightbox="{{ item.id }}">
                                                <img src="{{ item.picture|thumb:'60x60^' }}"
                                                        alt="{{ item.name }}"/>
                                            </a>
                                        {% endif %}
                                        <div class="product-description {% if item.picture %}with-picture{% endif %}">
                                            <h4>
                                                {{ item.name }}
                                            </h4>
                                            {% if item.description %}
                                                <div class="product-description">
                                                    {{ item.description|localize|rich_text }}
                                                </div>
                                            {% endif %}
                                        </div>
                                    </div>
                                    <div class="col-md-2 col-xs-6 price">
                                        {% if item.min_price != item.max_price or item.free_price %}
                                            {% blocktrans trimmed with minprice=item.min_price|money:event.currency %}
                                                from {{ minprice }}
                                            {% endblocktrans %}
                                        {% elif not item.min_price and not item.max_price %}
                                            {% trans "FREE" context "price" %}
                                        {% else %}
                                            {{ item.min_price|money:event.currency }}
                                        {% endif %}
                                    </div>
                                    <div class="col-md-2 col-xs-6 availability-box">
                                    </div>
                                    <div class="clearfix"></div>
                                </div>
                                <div class="">
                                    {% for var in item.available_variations %}
                                        <div class="row-fluid product-row variation">
                                            <div class="col-md-8 col-xs-12">
                                                <h5>
                                                    <label for="variation_{{ item.id }}_{{ var.id }}">
                                                        {{ var }}
                                                    </label>
                                                </h5>
                                                {% if var.description %}
                                                    <div class="variation-description">
                                                        {{ var.description|localize|rich_text }}
                                                    </div>
                                                {% endif %}
                                            </div>
                                            <div class="col-md-2 col-xs-6 price">
                                                {% if var.original_price %}
                                                    {% if event.settings.display_net_prices %}
                                                        <del>{{ var.original_price.net|money:event.currency }}</del>
                                                    {% else %}
                                                        <del>{{ var.original_price.gross|money:event.currency }}</del>
                                                    {% endif %}
                                                    <ins>
                                                {% endif %}
                                                {% if item.free_price %}
                                                    <div class="input-group input-group-price">
                                                        <span class="input-group-addon">{{ event.currency }}</span>
                                                        <input type="number" class="form-control input-item-price"
                                                                placeholder="0"
                                                                min="{% if event.settings.display_net_prices %}{{ var.display_price.net|stringformat:"0.2f" }}{% else %}{{ var.display_price.gross|stringformat:"0.2f" }}{% endif %}"
                                                                name="price_{{ item.id }}_{{ var.id }}"
                                                                title="{% blocktrans trimmed with item=var.value %}Modify price for {{ item }}{% endblocktrans %}"
                                                                value="{% if event.settings.display_net_prices %}{{var.display_price.net|stringformat:"0.2f" }}{% else %}{{ var.display_price.gross|stringformat:"0.2f" }}{% endif %}"
                                                                step="any">
                                                    </div>
                                                {% elif not var.display_price.gross %}
                                                    {% trans "FREE" context "price" %}
                                                {% elif event.settings.display_net_prices %}
                                                    {{ var.display_price.net|money:event.currency }}
                                                {% else %}
                                                    {{ var.display_price.gross|money:event.currency }}
                                                {% endif %}
                                                {% if item.original_price or var.original_price %}
                                                    </ins>
                                                {% endif %}
                                            {% if item.includes_mixed_tax_rate %}
                                                {% if event.settings.display_net_prices %}
                                                    <small>{% trans "plus taxes" %}</small>
                                                {% else %}
                                                    <small>{% trans "incl. taxes" %}</small>
                                                {% endif %}
                                                {% elif var.display_price.rate and var.display_price.gross and event.settings.display_net_prices %}
                                                    <small>{% blocktrans trimmed with rate=var.display_price.rate|floatformat:-2 name=var.display_price.name %}
                                                        <strong>plus</strong> {{ rate }}% {{ name }}
                                                    {% endblocktrans %}</small>
                                                {% elif var.display_price.rate and var.display_price.gross %}
                                                    <small>{% blocktrans trimmed with rate=var.display_price.rate|floatformat:-2 name=var.display_price.name %}
                                                        incl. {{ rate }}% {{ name }}
                                                    {% endblocktrans %}</small>
                                                {% endif %}
                                            </div>
                                            {% if var.cached_availability.0 == 100 %}
                                                <div class="col-md-2 col-xs-6 availability-box available radio-box">
                                                    {% if max_times > 1 %}
                                                        {% if item.order_max == 1 %}
                                                            <label class="item-checkbox-label">
                                                                <input type="checkbox"
                                                                        value="1"
                                                                        id="variation_{{ item.id }}_{{ var.id }}"
                                                                        name="variation_{{ item.id }}_{{ var.id }}"
                                                                        {% if options == 1 %}checked{% endif %}
                                                                        title="{% blocktrans with item=item.name var=var.name %}Amount of {{ item }} – {{ var }} to order{% endblocktrans %}">
                                                            </label>
                                                        {% else %}
                                                            <input type="number" class="form-control input-item-count" placeholder="0" min="0"
                                                                    pattern="\d*"
                                                                    max="{{ item.order_max }}"
                                                                    id="variation_{{ item.id }}_{{ var.id }}"
                                                                    name="variation_{{ item.id }}_{{ var.id }}"
                                                                    {% if options == 1 %}value="1"{% endif %}
                                                                    title="{% blocktrans with item=item.name var=var.name %}Amount of {{ item }} – {{ var }} to order{% endblocktrans %}">
                                                        {% endif %}
                                                    {% else %}
                                                        <label>
                                                            <input type="radio" name="_voucher_item"
                                                                    {% if options == 1 %}checked="checked"{% endif %}
                                                                    id="variation_{{ item.id }}_{{ var.id }}"
                                                                    value="variation_{{ item.id }}_{{ var.id }}">
                                                        </label>
                                                    {% endif %}
                                                </div>
                                            {% else %}
                                                {% include "pretixpresale/event/fragment_availability.html" with price=var.display_price.gross avail=var.cached_availability.0 %}
                                            {% endif %}
                                            <div class="clearfix"></div>
                                        </div>
                                    {% endfor %}
                                </div>
                            </div>
                        {% else %}
                            <div class="row-fluid product-row simple">
                                <div class="col-md-8 col-xs-12">
                                    {% if item.picture %}
                                        <a href="{{ item.picture.url }}" class="productpicture"
                                                data-title="{{ item.name|force_escape|force_escape }}"
                                                {# Yes, double-escape to prevent XSS in lightbox #}
                                                data-lightbox="{{ item.id }}">
                                            <img src="{{ item.picture|thumb:'60x60^' }}"
                                                    alt="{{ item.name }}"/>
                                        </a>
                                    {% endif %}
                                    <div class="product-description {% if item.picture %}with-picture{% endif %}">
                                        <h4>
                                            <label for="item_{{ item.id }}">{{ item.name }}</label>
                                        </h4>
                                        {% if item.description %}
                                            <div class="product-description">
                                                {{ item.description|localize|rich_text }}
                                            </div>
                                        {% endif %}
                                    </div>
                                </div>
                                <div class="col-md-2 col-xs-6 price">
                                    {% if item.original_price %}
                                        {% if event.settings.display_net_prices %}
                                            <del>{{ item.original_price.net|money:event.currency }}</del>
                                        {% else %}
                                            <del>{{ item.original_price.gross|money:event.currency }}</del>
                                        {% endif %}
                                        <ins>
                                    {% endif %}
                                    {% if item.free_price %}
                                        <div class="input-group input-group-price">
                                            <span class="input-group-addon">{{ event.currency }}</span>
                                            <input type="number" class="form-control input-item-price" placeholder="0"
                                                    min="{% if event.settings.display_net_prices %}{{ item.display_price.net|stringformat:"0.2f" }}{% else %}{{ item.display_price.gross|stringformat:"0.2f" }}{% endif %}"
                                                    name="price_{{ item.id }}"
                                                    title="{% blocktrans trimmed with item=item.name %}Modify price for {{ item }}{% endblocktrans %}"
                                                    value="{% if event.settings.display_net_prices %}{{ item.display_price.net|stringformat:"0.2f" }}{% else %}{{ item.display_price.gross|stringformat:"0.2f" }}{% endif %}"
                                                    step="any">
                                        </div>
                                    {% elif not item.display_price.gross %}
                                        {% trans "FREE" context "price" %}
                                    {% elif event.settings.display_net_prices %}
                                        {{ item.display_price.net|money:event.currency }}
                                    {% else %}
                                        {{ item.display_price.gross|money:event.currency }}
                                    {% endif %}
                                    {% if item.original_price %}
                                        </ins>
                                    {% endif %}
                                    {% if item.includes_mixed_tax_rate %}
                                        {% if event.settings.display_net_prices %}
                                            <small>{% trans "plus taxes" %}</small>
                                        {% else %}
                                            <small>{% trans "incl. taxes" %}</small>
                                        {% endif %}
                                    {% elif item.display_price.rate and item.display_price.gross and event.settings.display_net_prices %}
                                        <small>{% blocktrans trimmed with rate=item.display_price.rate|floatformat:-2 name=item.display_price.name %}
                                            <strong>plus</strong> {{ rate }}% {{ name }}
                                        {% endblocktrans %}</small>
                                    {% elif item.display_price.rate and item.display_price.gross%}
                                        <small>{% blocktrans trimmed with rate=item.display_price.rate|floatformat:-2 name=item.display_price.name %}
                                            incl. {{ rate }}% {{ name }}
                                        {% endblocktrans %}</small>
                                    {% endif %}
                                </div>
                                {% if item.cached_availability.0 == 100 %}
                                    <div class="col-md-2 col-xs-6 availability-box available radio-box">
                                        {% if max_times > 1 %}
                                            {% if item.order_max == 1 %}
                                                <label class="item-checkbox-label">
                                                    <input type="checkbox"
                                                            value="1"
                                                            id="item_{{ item.id }}"
                                                            name="item_{{ item.id }}"
                                                            {% if options == 1 %}checked{% endif %}
                                                            title="{% blocktrans with item=item.name %}Amount of {{ item }} to order{% endblocktrans %}">
                                                </label>
                                            {% else %}
                                                <input type="number" class="form-control input-item-count" placeholder="0" min="0"
                                                        pattern="\d*"
                                                        max="{{ item.order_max }}"
                                                        id="item_{{ item.id }}"
                                                        name="item_{{ item.id }}"
                                                        {% if options == 1 %}value="1"{% endif %}
                                                        title="{% blocktrans with item=item.name %}Amount of {{ item }} to order{% endblocktrans %}">
                                            {% endif %}
                                        {% else %}
                                            <label>
                                                <input type="radio" name="_voucher_item"
                                                        {% if options == 1 %}checked="checked"{% endif %}
                                                        id="item_{{ item.id }}"
                                                        value="item_{{ item.id }}">
                                            </label>
                                        {% endif %}
                                    </div>
                                {% else %}
                                    {% include "pretixpresale/event/fragment_availability.html" with price=item.display_price.gross avail=item.cached_availability.0 %}
                                {% endif %}
                                <div class="clearfix"></div>
                            </div>
                        {% endif %}
                    {% endfor %}
                </section>
            {% endfor %}
            {% eventsignal event "pretix.presale.signals.voucher_redeem_info" voucher=voucher %}
            {% if event.presale_is_running %}
                <div class="row-fluid checkout-button-row">
                    <div class="col-md-4 col-md-offset-8 col-xs-12">
                        <button class="btn btn-block btn-primary btn-lg" id="btn-add-to-cart" type="submit">
                            {% if request.event.settings.redirect_to_checkout_directly %}
                                {% if allfree %}
                                    <i class="fa fa-check"></i> {% trans "Register" context "free_tickets" %}
                                {% else %}
                                    <i class="fa fa-shopping-cart"></i> {% trans "Proceed with checkout" %}
                                {% endif %}
                            {% else %}
                                <i class="fa fa-shopping-cart"></i> {% trans "Add to cart" %}
                            {% endif %}
                        </button>
                    </div>
                    <div class="clearfix"></div>
                </div>
            {% endif %}
            {% if "widget_data" in request.GET %}
                <input type="hidden" value="{{ request.GET.widget_data }}" name="widget_data">
            {% endif %}
        </form>
    {% endif %}
{% endblock %}
