{% extends "pretixcontrol/item/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load formset_tags %}
{% block inside %}
    <form action="" method="post" class="form-horizontal" enctype="multipart/form-data">
        {% bootstrap_form_errors form layout="control" %}
        {% csrf_token %}
        <div class="row">
            <div class="col-xs-12 col-lg-10">
                <div class="tabbed-form">
                    <fieldset>
                        <legend>{% trans "General" %}</legend>
                        {% bootstrap_field form.active layout="control" %}
                        {% bootstrap_field form.name layout="control" %}
                        <div class="internal-name-wrapper">
                            {% bootstrap_field form.internal_name layout="control" %}
                        </div>
                        {% bootstrap_field form.category layout="control" %}

                        <div class="form-group">
                            <label class="col-md-3 control-label">{% trans "Product type" %}</label>
                            <div class="col-md-9">
                                {% for e in form.errors.admission %}
                                    <div class="alert alert-danger has-error">
                                        {{ e }}
                                    </div>
                                {% endfor %}
                                <div class="big-radio radio">
                                    <label>
                                        <input type="radio" value="on" name="{{ form.admission.html_name }}" {% if form.admission.value %}checked{% endif %} id="admission_on">
                                        <span class="fa fa-fw fa-user"></span>
                                        <strong>{% trans "Admission product" %}</strong><br>
                                        <div class="help-block">
                                            {% blocktrans trimmed %}
                                                Every purchase of this product represents one person who is allowed to enter your event.
                                                By default, we will only offer ticket downloads for these products.
                                            {% endblocktrans %}
                                        </div>
                                        <div class="help-block">
                                            {% blocktrans trimmed %}
                                                Only purchases of such products will be considered "attendees" for most statistical
                                                purposes or within some plugins.
                                            {% endblocktrans %}
                                        </div>
                                        <div class="help-block">
                                            {% blocktrans trimmed %}
                                                This option should be set for most things that you would call a "ticket". For product add-ons or bundles, this should
                                                be set on the main ticket, except if the add-on products or bundled products represent additional people (e.g. group bundles).
                                            {% endblocktrans %}
                                        </div>
                                    </label>
                                </div>
                                <div class="big-radio radio">
                                    <label>
                                        <input type="radio" value="" name="{{ form.admission.html_name }}" {% if not form.admission.value %}checked{% endif %}>
                                        <span class="fa fa-fw fa-cube"></span>
                                        <strong>{% trans "Non-admission product" %}</strong>
                                        <div class="help-block">
                                            {% blocktrans trimmed %}
                                                A product that does not represent a person. By default, we will not offer ticket downloads
                                                (but you can still enable ticket downloads in event settings or product settings).
                                            {% endblocktrans %}
                                        </div>
                                        <div class="help-block">
                                            {% blocktrans trimmed %}
                                                Examples: Merchandise, donations, gift cards, add-ons to a main ticket.
                                            {% endblocktrans %}
                                        </div>
                                    </label>
                                </div>
                            </div>
                        </div>

                        <div class="form-group" data-display-dependency="#admission_on">
                            <label class="col-md-3 control-label">{% trans "Personalization" %}</label>
                            <div class="col-md-9">
                                {% for e in form.errors.personalized %}
                                    <div class="alert alert-danger has-error">
                                        {{ e }}
                                    </div>
                                {% endfor %}
                                <div class="big-radio radio">
                                    <label>
                                        <input type="radio" value="on" name="{{ form.personalized.html_name }}" {% if form.personalized.value %}checked{% endif %}>
                                        <span class="fa fa-fw fa-id-card-o"></span>
                                        <strong>{% trans "Personalized ticket" %}</strong><br>
                                        <div class="help-block">
                                            {% blocktrans trimmed %}
                                                When this ticket is purchased, the system will ask for a name or other details according
                                                to your event settings.
                                            {% endblocktrans %}
                                            {% if not request.event.settings.attendee_names_asked and not request.event.settings.attendee_emails_asked and not request.event.settings.attendee_company_asked and not request.event.settings.attendee_addresses_asked %}
                                                <br>
                                                <span class="text-warning">
                                                    <span class="fa fa-warning" aria-hidden="true"></span>
                                                    {% trans "This will currently have no effect since all data fields are turned off in event settings." %}
                                                </span>
                                                <a href="{% url "control:event.settings" organizer=request.event.organizer.slug event=request.event.slug %}#tab-0-2-open"
                                                   class="btn btn-default btn-xs" target="_blank">{% trans "Change settings" %}</a>
                                            {% endif %}
                                        </div>
                                    </label>
                                </div>
                                <div class="big-radio radio">
                                    <label>
                                        <input type="radio" value="" name="{{ form.personalized.html_name }}" {% if not form.personalized.value %}checked{% endif %}>
                                        <span class="fa fa-fw fa-file-text-o"></span>
                                        <strong>{% trans "Non-personalized ticket" %}</strong>
                                        <div class="help-block">
                                            {% blocktrans trimmed %}
                                                The system will not ask for a name or other attendee details. This only affects
                                                system-provided fields, you can still add your own questions.
                                            {% endblocktrans %}
                                        </div>
                                    </label>
                                </div>
                            </div>
                        </div>

                        {% bootstrap_field form.description layout="control" %}
                        {% bootstrap_field form.picture layout="control" %}
                        {% bootstrap_field form.require_approval layout="control" %}

                        {% if meta_forms %}
                            <div class="form-group metadata-group">
                                <label class="col-md-3 control-label">{% trans "Meta data" %}</label>
                                <div class="col-md-9">
                                    {% for form in meta_forms %}
                                        <div class="row">
                                            <div class="col-md-4">
                                                <label for="{{ form.value.id_for_label }}">
                                                    {{ form.property.name }}
                                                </label>
                                            </div>
                                            <div class="col-md-8">
                                                {% bootstrap_form form layout="inline" error_types="all" %}
                                            </div>
                                        </div>
                                    {% endfor %}
                                </div>
                            </div>
                        {% endif %}
                    </fieldset>
                    <fieldset>
                        <legend>{% trans "Price" %}</legend>
                        {% bootstrap_field form.default_price addon_after=request.event.currency layout="control" %}
                        {% bootstrap_field form.tax_rule layout="control" %}
                        {% bootstrap_field form.free_price layout="control" %}
                        {% bootstrap_field form.free_price_suggestion addon_after=request.event.currency layout="control" %}
                        {% bootstrap_field form.original_price addon_after=request.event.currency layout="control" %}
                    </fieldset>
                    <fieldset>
                        <legend>{% trans "Availability" %}</legend>


                        {% bootstrap_field form.sales_channels layout="control" horizontal_field_class="col-md-7" %}
                        {% bootstrap_field form.available_from visibility_field=form.available_from_mode layout="control_with_visibility"  %}
                        {% bootstrap_field form.available_until visibility_field=form.available_until_mode layout="control_with_visibility" %}
                        {% bootstrap_field form.max_per_order layout="control" horizontal_field_class="col-md-7" %}
                        {% bootstrap_field form.min_per_order layout="control" horizontal_field_class="col-md-7" %}
                        {% bootstrap_field form.require_voucher visibility_field=form.hide_without_voucher layout="control_with_visibility" %}
                        {% bootstrap_field form.require_bundling layout="control" horizontal_field_class="col-md-7" %}
                        {% if form.require_membership %}
                            {% bootstrap_field form.require_membership layout="control" %}
                            <div data-display-dependency="#{{ form.require_membership.id_for_label }}">
                                {% bootstrap_field form.require_membership_types layout="control" horizontal_field_class="col-md-7" %}
                                {% bootstrap_field form.require_membership_hidden layout="control" horizontal_field_class="col-md-7" %}
                            </div>
                        {% endif %}
                        {% bootstrap_field form.allow_cancel layout="control" horizontal_field_class="col-md-7" %}
                        {% bootstrap_field form.allow_waitinglist layout="control" horizontal_field_class="col-md-7" %}
                        {% if form.hidden_if_available %}
                            {% bootstrap_field form.hidden_if_available layout="control" horizontal_field_class="col-md-7" %}
                        {% endif %}
                        {% bootstrap_field form.hidden_if_item_available layout="control" horizontal_field_class="col-md-7" %}
                    </fieldset>
                    {% for v in formsets.values %}
                        <fieldset>
                            <legend>{{ v.title }}</legend>
                            {% include v.template with formset=v %}
                        </fieldset>
                    {% endfor %}
                    <fieldset>
                        <legend>{% trans "Tickets & Badges" %}</legend>
                        {% bootstrap_field form.generate_tickets layout="control" %}
                        {% if form.media_policy %}
                            {% bootstrap_field form.media_policy layout="control" %}
                        {% endif %}
                        {% if form.media_type %}
                            {% bootstrap_field form.media_type layout="control" %}
                        {% endif %}
                        {% for f in plugin_forms %}
                            {% if f.is_layouts and not f.title %}
                                {% if f.template and not "template" in f.fields %}
                                    {% include f.template with form=f %}
                                {% else %}
                                    {% bootstrap_form f layout="control" %}
                                {% endif %}
                            {% endif %}
                        {% endfor %}
                    </fieldset>
                    <fieldset>
                        <legend>{% trans "Check-in & Validity" %}</legend>
                        {% bootstrap_field form.checkin_attention layout="control" %}
                        {% bootstrap_field form.checkin_text layout="control" %}
                        {% bootstrap_field form.validity_mode layout="control" %}
                        <div data-display-dependency="#{{ form.validity_mode.id_for_label }}" data-display-dependency-value="fixed">
                            {% bootstrap_field form.validity_fixed_from layout="control" %}
                            {% bootstrap_field form.validity_fixed_until layout="control" %}
                        </div>
                        <div data-display-dependency="#{{ form.validity_mode.id_for_label }}" data-display-dependency-value="dynamic">
                            {% bootstrap_field form.validity_dynamic_start_choice layout="control" %}
                            <div class="form-group metadata-group">
                                <label class="col-md-3 control-label">{% trans "Duration" %}</label>
                                <div class="col-md-9">
                                    {% trans "minutes" as t_minutes %}
                                    {% trans "hours" as t_hours %}
                                    {% trans "days" as t_days %}
                                    {% trans "months" as t_months %}
                                    {% trans "years" as t_years %}
                                    {% bootstrap_field form.validity_dynamic_duration_months layout="control" addon_after=t_months horizontal_field_class="" horizontal_label_class="sr-only" %}
                                    {% bootstrap_field form.validity_dynamic_duration_days layout="control" addon_after=t_days addon_before="+" horizontal_field_class="" horizontal_label_class="sr-only" %}
                                    {% bootstrap_field form.validity_dynamic_duration_hours layout="control" addon_after=t_hours addon_before="+" horizontal_field_class="" horizontal_label_class="sr-only" %}
                                    {% bootstrap_field form.validity_dynamic_duration_minutes layout="control" addon_after=t_minutes addon_before="+" horizontal_field_class="" horizontal_label_class="sr-only" %}
                                    <div class="help-block">
                                        {% blocktrans trimmed %}
                                            If you select a duration given in days, months or years, the validity will always end at the
                                            end of a full day (midnight), plus the number of minutes and hours selected above.
                                            The start date is included in the calculation, so if you enter "1 day", the ticket
                                            will be valid until the end of the day it starts on.
                                        {% endblocktrans %}
                                    </div>
                                </div>
                            </div>
                            <div data-display-dependency="#{{ form.validity_dynamic_start_choice.id_for_label }}" data-display-dependency-value="True">
                                {% trans "days" as t_days %}
                                {% bootstrap_field form.validity_dynamic_start_choice_day_limit addon_after=t_days layout="control" %}
                            </div>
                        </div>
                    </fieldset>
                    <fieldset id="tab-item-additional-settings">
                        <legend>{% trans "Additional settings" %}</legend>
                        {% bootstrap_field form.issue_giftcard layout="control" %}
                        {% if form.grant_membership_type %}
                            {% bootstrap_field form.grant_membership_type layout="control" %}
                            <div data-display-dependency="#id_grant_membership_type">
                                {% bootstrap_field form.grant_membership_duration_like_event layout="control" %}
                                <div data-display-dependency="#id_grant_membership_duration_like_event" data-inverse class="form-group">
                                    {% blocktrans asvar days %}days{% endblocktrans %}
                                    {% blocktrans asvar months %}months{% endblocktrans %}
                                    <label class="col-md-3 col-xs-12 control-label">
                                        {% trans "Membership duration after purchase" %}
                                    </label>
                                    <div class="col-md-4 col-xs-5">
                                        {% bootstrap_field form.grant_membership_duration_months layout="" addon_after=months label_class="sr-only" form_group_class="" %}
                                    </div>
                                    <label class="col-md-1 col-xs-2 control-label text-center">
                                        +
                                    </label>
                                    <div class="col-md-4 col-xs-5">
                                        {% bootstrap_field form.grant_membership_duration_days layout="" addon_after=days label_class="sr-only" form_group_class="" %}
                                    </div>
                                </div>
                            </div>
                        {% endif %}
                        {% bootstrap_field form.show_quota_left layout="control" %}
                        {% for f in plugin_forms %}
                            {% if not f.is_layouts and not f.title %}
                                <hr />
                                {% if f.template and not "template" in f.fields %}
                                    {% include f.template with form=f %}
                                {% else %}
                                    {% bootstrap_form f layout="control" %}
                                {% endif %}
                            {% endif %}
                        {% endfor %}
                    </fieldset>
                    {% for f in plugin_forms %}
                        {% if not f.is_layouts and f.title %}
                            <fieldset>
                                <legend>{{ f.title }}</legend>
                                {% if f.template and not "template" in f.fields %}
                                    {% include f.template with form=f %}
                                {% else %}
                                    {% bootstrap_form f layout="control" %}
                                {% endif %}
                            </fieldset>
                        {% endif %}
                    {% endfor %}
                </div>
                <div class="form-group submit-group">
                    <button type="submit" class="btn btn-primary btn-save">
                        {% trans "Save" %}
                    </button>
                </div>
            </div>
            <div class="col-xs-12 col-lg-2">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            {% trans "Product history" %}
                        </h3>
                    </div>
                    {% include "pretixcontrol/includes/logs.html" with obj=item %}
                </div>
            </div>
        </div>
    </form>
{% endblock %}
