{% extends "pretixcontrol/items/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load eventsignal %}
{% load eventurl %}
{% block title %}{% trans "Voucher" %}{% endblock %}
{% block inside %}
    <h1>{% trans "Voucher" %}</h1>
    {% if voucher.redeemed %}
        <div class="alert alert-warning">
            {% trans "This voucher already has been used. It is not recommended to modify it." %}
            <ul>
                {% for order in voucher.distinct_orders %}
                    <li><a href="{% url "control:event.order" event=request.event.slug organizer=request.event.organizer.slug code=order.code %}">
                        {% blocktrans with code=order.code %}Order {{ code }}{% endblocktrans %}
                    </a></li>
                {% endfor %}
            </ul>
        </div>
    {% endif %}
    {% if redeemed_in_carts %}
        <div class="alert alert-warning">
            {% blocktrans trimmed with number=redeemed_in_carts %}
                This voucher is currently used in {{ number }} cart sessions and might not be free to use until the cart sessions
                expire.
            {% endblocktrans %}
            <p class="text-right">
                <a href="{% url "control:event.voucher.deletecarts" organizer=request.event.organizer.slug event=request.event.slug voucher=voucher.id %}" class="btn btn-default"><i class="fa fa-trash"></i> {% trans "Remove cart positions" %}</a>
            </p>
            <div class="clear"></div>
        </div>
    {% endif %}
    <form action="" method="post" class="form-horizontal">
        {% csrf_token %}
        {% bootstrap_form_errors form %}
        <div class="row">
            <div class="col-xs-12 col-lg-10">
                <fieldset>
                    <legend>{% trans "Voucher details" %}</legend>
                    {% bootstrap_field form.code layout="control" %}
                    {% if voucher.pk %}
                        <div class="form-group">
                            <label class="col-md-3 control-label" for="id_url">{% trans "Voucher link" %}</label>
                            <div class="col-md-9">
                                <div class="input-group">
                                    <input type="text" name="url"
                                            value="{{ url }}"
                                            class="form-control"
                                            id="id_url" readonly>
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" title="{% trans "Create QR code" %}" aria-haspopup="true" aria-expanded="false">
                                            <i class="fa fa-qrcode" aria-hidden="true"></i>
                                        </button>
                                        {% include "pretixcontrol/event/fragment_qr_dropdown.html" with url=url %}
                                    </div>
                                </div>
                            </div>
                        </div>
                    {% endif %}
                    {% bootstrap_field form.max_usages layout="control" %}
                    {% bootstrap_field form.valid_until layout="control" %}
                    {% bootstrap_field form.itemvar layout="control" %}
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="id_tag">{% trans "Price effect" %}</label>
                        <div class="col-md-5">
                            {% bootstrap_field form.price_mode show_label=False form_group_class="" %}
                        </div>
                        <div class="col-md-4">
                            {% bootstrap_field form.value show_label=False form_group_class="" %}
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-9 col-md-offset-3">
                            <div class="controls">
                                <div class="alert alert-info">
                                    {% blocktrans trimmed %}
                                        If you choose "any product" for a specific quota and choose to reserve quota for this
                                        voucher above, the product can still be unavailable to the voucher holder if another quota
                                        associated with the product is sold out!
                                    {% endblocktrans %}
                                </div>
                            </div>
                        </div>
                    </div>
                    {% if form.subevent %}
                        {% bootstrap_field form.subevent layout="control" %}
                    {% endif %}
                    {% if "seat" in form.fields %}
                        {% bootstrap_field form.seat layout="control" %}
                    {% endif %}
                </fieldset>
                <fieldset>
                    <legend>{% trans "Advanced settings" %}</legend>
                    {% bootstrap_field form.block_quota layout="control" %}
                    {% bootstrap_field form.allow_ignore_quota layout="control" %}
                    {% bootstrap_field form.min_usages layout="control" %}
                    {% bootstrap_field form.budget addon_after=request.event.currency layout="control" %}
                    {% bootstrap_field form.tag layout="control" %}
                    {% bootstrap_field form.comment layout="control" %}
                    {% bootstrap_field form.show_hidden_items layout="control" %}
                    {% bootstrap_field form.all_addons_included layout="control" %}
                    {% bootstrap_field form.all_bundles_included layout="control" %}
                </fieldset>
                {% eventsignal request.event "pretix.control.signals.voucher_form_html" form=form %}
            </div>
            <div class="col-xs-12 col-lg-2">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            {% trans "Voucher history" %}
                        </h3>
                    </div>
                    {% include "pretixcontrol/includes/logs.html" with obj=voucher %}
                </div>
            </div>
        </div>
        {% if "can_change_vouchers" in request.eventpermset %}
            <div class="form-group submit-group">
                <button type="submit" class="btn btn-primary btn-save">
                    {% trans "Save" %}
                </button>
            </div>
        {% endif %}
    </form>
{% endblock %}
