{% extends "pretixcontrol/event/settings_base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load static %}
{% load hierarkey_form %}
{% load formset_tags %}
{% block title %}{% trans "General settings" %}{% endblock %}
{% block custom_header %}
    {{ block.super }}
    <link type="text/css" rel="stylesheet" href="{% url "control:pdf.css" organizer=request.organizer.slug event=request.event.slug %}">
{% endblock %}
{% block inside %}
    <h1>{% trans "General settings" %}</h1>

    <form action="" method="post" class="form-horizontal" enctype="multipart/form-data">
        {% csrf_token %}
        {% bootstrap_form_errors form %}
        {% bootstrap_form_errors sform %}
        <div class="tabbed-form">
            <fieldset>
                <legend>{% trans "Basics" %}</legend>
                {% bootstrap_field form.name layout="control" %}
                {% bootstrap_field form.slug layout="control" %}
                {% if form.domain %}
                    {% bootstrap_field form.domain layout="control" %}
                {% endif %}
                {% bootstrap_field form.date_from layout="control" %}
                {% bootstrap_field form.date_to layout="control" %}
                {% include "pretixcontrol/event/fragment_geodata.html" %}
                {% bootstrap_field form.date_admission layout="control" %}
                {% bootstrap_field form.currency layout="control" %}
                {% bootstrap_field sform.contact_mail layout="control" %}
                {% bootstrap_field sform.imprint_url layout="control" %}
                {% bootstrap_field form.is_public layout="control" %}
                {% bootstrap_field form.sales_channels 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 "Localization" %}</legend>
                {% bootstrap_field sform.locales layout="control" %}
                {% bootstrap_field sform.locale layout="control" %}
                {% bootstrap_field sform.timezone layout="control" %}
                {% bootstrap_field sform.region layout="control" %}
            </fieldset>
            <fieldset>
                <legend>{% trans "Customer and attendee data" %}</legend>
                <h4>{% trans "Customer data (once per order)" %}</h4>
                <div class="form-group">
                    <label class="control-label col-md-3">
                        {% trans "E-mail" %}
                    </label>
                    <div class="col-md-9">
                        <div class="checkbox">
                            <label><input type="checkbox" checked="checked"
                                          disabled="disabled"> {% trans "Ask and require input" %}</label>
                        </div>
                    </div>
                </div>
                {% bootstrap_field sform.order_email_asked_twice layout="control" %}
                {% bootstrap_field sform.order_phone_asked_required layout="control" %}
                <div class="form-group">
                    <label class="control-label col-md-3">
                        {% trans "Name and address" %}
                    </label>
                    <div class="col-md-9 static-form-row">
                        <p>
                            <a href="{% url "control:event.settings.invoice" event=request.event.slug organizer=request.organizer.slug %}#tab-0-1-open"
                               target="_blank">
                                {% trans "See invoice settings" %}
                            </a>
                        </p>
                    </div>
                </div>

                <h4>{% trans "Attendee data (once per personalized ticket)" %}</h4>

                {% bootstrap_field sform.attendee_names_asked_required layout="control" %}
                {% bootstrap_field sform.attendee_emails_asked_required layout="control" %}
                {% bootstrap_field sform.attendee_company_asked_required layout="control" %}
                {% bootstrap_field sform.attendee_addresses_asked_required layout="control" %}

                <div class="form-group">
                    <label class="control-label col-md-3">
                        {% trans "Custom fields" %}
                    </label>
                    <div class="col-md-9 static-form-row">
                        <p>
                            <a href="{% url "control:event.items.questions" event=request.event.slug organizer=request.organizer.slug %}"
                               target="_blank">
                                {% trans "Manage questions" %}
                            </a>
                        </p>
                    </div>
                </div>
                {% bootstrap_field sform.attendee_data_explanation_text layout="control" %}

                <h4>{% trans "Other settings" %}</h4>
                {% bootstrap_field sform.name_scheme layout="control" %}
                {% bootstrap_field sform.name_scheme_titles layout="control" %}
                {% bootstrap_field sform.checkout_show_copy_answers_button layout="control" %}
            </fieldset>
            <fieldset>
                <legend>{% trans "Texts" %}</legend>
                {% bootstrap_field sform.frontpage_text layout="control" %}
                {% bootstrap_field sform.presale_has_ended_text layout="control" %}
                {% bootstrap_field sform.voucher_explanation_text layout="control" %}

                <div class="form-group">
                    <label class="col-md-3 control-label">
                        {% trans "Confirmation text" %}<br>
                        <span class="optional">{% trans "Optional" %}</span>
                    </label>
                    <div class="col-md-9">
                        <div class="help-block">
                            {% blocktrans trimmed %}
                                These texts need to be confirmed by the user before a purchase is possible. You could
                                for example link your terms of service here. If you use the Pages feature to publish
                                your terms of service, you don't need this setting since you can configure it there.
                            {% endblocktrans %}
                        </div>
                        <div class="formset" data-formset data-formset-prefix="{{ confirm_texts_formset.prefix }}">
                            {{ confirm_texts_formset.management_form }}
                            {% bootstrap_formset_errors confirm_texts_formset %}
                            <div data-formset-body>
                                {% for form in confirm_texts_formset %}
                                    <div class="row formset-row" data-formset-form>
                                        <div class="sr-only">
                                            {{ form.id }}
                                            {% bootstrap_field form.DELETE form_group_class="" layout="inline" %}
                                            {% bootstrap_field form.ORDER form_group_class="" layout="inline" %}
                                        </div>
                                        <div class="col-md-10">
                                            {% bootstrap_form_errors form %}
                                            {% bootstrap_field form.text layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-md-2 text-right flip">
                                            <button type="button" class="btn" data-formset-move-up-button>
                                                <i class="fa fa-arrow-up"></i></button>
                                            <button type="button" class="btn" data-formset-move-down-button>
                                                <i class="fa fa-arrow-down"></i></button>
                                            <button type="button" class="btn btn-danger" data-formset-delete-button>
                                                <i class="fa fa-trash"></i></button>
                                        </div>
                                    </div>
                                {% endfor %}
                            </div>
                            <script type="form-template" data-formset-empty-form>
                                {% escapescript %}
                                    <div class="row formset-row" data-formset-form>
                                        <div class="sr-only">
                                            {{ confirm_texts_formset.empty_form.id }}
                                            {% bootstrap_field confirm_texts_formset.empty_form.DELETE form_group_class="" layout="inline" %}
                                            {% bootstrap_field confirm_texts_formset.empty_form.ORDER form_group_class="" layout="inline" %}
                                        </div>
                                        <div class="col-md-10">
                                            {% bootstrap_field confirm_texts_formset.empty_form.text layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-md-2 text-right flip">

                                            <button type="button" class="btn" data-formset-move-up-button>
                                                <i class="fa fa-arrow-up"></i></button>
                                            <button type="button" class="btn" data-formset-move-down-button>
                                                <i class="fa fa-arrow-down"></i></button>
                                            <button type="button" class="btn btn-danger" data-formset-delete-button>
                                                <i class="fa fa-trash"></i></button>
                                        </div>
                                    </div>
                                {% endescapescript %}
                            </script>
                            <p>
                                <button type="button" class="btn btn-default" data-formset-add>
                                    <i class="fa fa-plus"></i> {% trans "Add confirmation text" %}</button>
                            </p>
                        </div>
                    </div>
                </div>

                {% bootstrap_field sform.checkout_success_text layout="control" %}
                {% bootstrap_field sform.checkout_email_helptext layout="control" %}
                {% bootstrap_field sform.checkout_phone_helptext layout="control" %}
                {% bootstrap_field sform.banner_text layout="control" %}
                {% bootstrap_field sform.banner_text_bottom layout="control" %}
                {% bootstrap_field sform.event_info_text layout="control" %}
            </fieldset>
            <fieldset>
                <legend>{% trans "Shop design" %}</legend>
                {% bootstrap_field sform.logo_image layout="control" %}
                {% bootstrap_field sform.logo_image_large layout="control" %}
                {% bootstrap_field sform.logo_show_title layout="control" %}
                {% bootstrap_field sform.og_image layout="control" %}
                {% url "control:organizer.edit" organizer=request.organizer.slug as org_url %}
                {% with org_url|add:"#tab-0-4-open" as org_url_tab %}
                    {% propagated request.event org_url_tab "primary_color" "primary_font" "theme_color_success" "theme_color_danger" "theme_color_background" "theme_round_borders" %}
                        {% bootstrap_field sform.primary_color layout="control" %}
                        {% bootstrap_field sform.theme_color_success layout="control" %}
                        {% bootstrap_field sform.theme_color_danger layout="control" %}
                        {% bootstrap_field sform.theme_color_background layout="control" %}
                        {% bootstrap_field sform.theme_round_borders layout="control" %}
                        {% bootstrap_field sform.primary_font layout="control" %}
                    {% endpropagated %}
                {% endwith %}
            </fieldset>
            <fieldset>
                <legend>{% trans "Timeline" %}</legend>
                {% bootstrap_field form.presale_start layout="control" %}
                {% bootstrap_field sform.presale_start_show_date layout="control" %}
                {% bootstrap_field form.presale_end layout="control" %}
                {% bootstrap_field sform.show_items_outside_presale_period layout="control" %}
                {% bootstrap_field sform.last_order_modification_date layout="control" %}
                {% bootstrap_field sform.allow_modifications_after_checkin layout="control" %}
                {% bootstrap_field sform.show_checkin_number_user layout="control" %}
            </fieldset>
            <fieldset>
                <legend>{% trans "Display" %}</legend>
                {% bootstrap_field sform.show_dates_on_frontpage layout="control" %}
                {% bootstrap_field sform.show_date_to layout="control" %}
                {% bootstrap_field sform.show_times layout="control" %}
                {% bootstrap_field sform.show_quota_left layout="control" %}
                {% bootstrap_field sform.display_net_prices layout="control" %}
                {% bootstrap_field sform.hide_prices_from_attendees layout="control" %}
                {% bootstrap_field sform.show_variations_expanded layout="control" %}
                {% bootstrap_field sform.hide_sold_out layout="control" %}

                <div class="form-group">
                    <label class="col-md-3 control-label">
                        {% trans "Footer links" %}<br>
                        <span class="optional">{% trans "Optional" %}</span>
                    </label>
                    <div class="col-md-9">
                        <p class="help-block">
                            {% blocktrans trimmed %}
                                These links will be shown in the footer of your ticket shop. You could
                                for example link your terms of service here. Your contact address, imprint, and privacy
                                policy will be linked automatically (if you configured them), so you do not need to add
                                them here.
                            {% endblocktrans %}
                        </p>
                        <div class="formset" data-formset data-formset-prefix="{{ footer_links_formset.prefix }}">
                            {{ footer_links_formset.management_form }}
                            {% bootstrap_formset_errors footer_links_formset %}
                            <div data-formset-body>
                                {% for form in footer_links_formset %}
                                    <div class="row formset-row" data-formset-form>
                                        <div class="sr-only">
                                            {{ form.id }}
                                            {% bootstrap_field form.DELETE form_group_class="" layout="inline" %}
                                        </div>
                                        <div class="col-md-5">
                                            {% bootstrap_form_errors form %}
                                            {% bootstrap_field form.label layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-md-5">
                                            {% bootstrap_field form.url layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-md-2 text-right flip">
                                            <button type="button" class="btn btn-danger" data-formset-delete-button>
                                                <i class="fa fa-trash"></i></button>
                                        </div>
                                    </div>
                                {% endfor %}
                            </div>
                            <script type="form-template" data-formset-empty-form>
                                {% escapescript %}
                                    <div class="row formset-row" data-formset-form>
                                        <div class="sr-only">
                                            {{ footer_links_formset.empty_form.id }}
                                            {% bootstrap_field footer_links_formset.empty_form.DELETE form_group_class="" layout="inline" %}
                                        </div>
                                        <div class="col-md-5">
                                            {% bootstrap_field footer_links_formset.empty_form.label layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-md-5">
                                            {% bootstrap_field footer_links_formset.empty_form.url layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-md-2 text-right flip">

                                            <button type="button" class="btn btn-danger" data-formset-delete-button>
                                                <i class="fa fa-trash"></i></button>
                                        </div>
                                    </div>
                                {% endescapescript %}
                            </script>
                            <p>
                                <button type="button" class="btn btn-default" data-formset-add>
                                    <i class="fa fa-plus"></i> {% trans "Add link" %}</button>
                            </p>
                        </div>
                    </div>
                </div>
                
                {% if sform.frontpage_subevent_ordering %}
                    {% bootstrap_field sform.frontpage_subevent_ordering layout="control" %}
                {% endif %}
                {% if sform.event_list_type %}
                    {% bootstrap_field sform.event_list_type layout="control" %}
                {% endif %}
                {% if sform.event_list_available_only %}
                    {% bootstrap_field sform.event_list_available_only layout="control" %}
                {% endif %}
                {% if sform.event_list_filters %}
                    {% bootstrap_field sform.event_list_filters layout="control" %}
                {% endif %}
                {% if sform.event_calendar_future_only %}
                    {% bootstrap_field sform.event_calendar_future_only layout="control" %}
                {% endif %}
                {% bootstrap_field sform.low_availability_percentage layout="control" addon_after="%" %}

                {% url "control:organizer.edit" organizer=request.organizer.slug as org_url %}
                {% propagated request.event org_url "meta_noindex" %}
                    {% bootstrap_field sform.meta_noindex layout="control" %}
                {% endpropagated %}
            </fieldset>
            <fieldset>
                <legend>{% trans "Cart" %}</legend>
                {% bootstrap_field sform.reservation_time layout="control" %}
                {% bootstrap_field sform.max_items_per_order layout="control" %}
                {% bootstrap_field sform.redirect_to_checkout_directly layout="control" %}
            </fieldset>
            <fieldset id="waiting-list">
                <legend>{% trans "Waiting list" %}</legend>
                <div class="alert alert-info">
                    {% blocktrans trimmed %}
                        The waiting list currently is not compatible with some advanced features of pretix such as
                        hidden products, add-on products or product bundles.
                    {% endblocktrans %}
                </div>
                <div class="alert alert-info">
                    {% blocktrans trimmed %}
                        The waiting list determines availability mainly based on quotas. If you use a seating plan and
                        your
                        number of available seats is less than the available quota, you might run into situations where
                        people are sent an email from the waiting list but still are unable to book a seat.
                    {% endblocktrans %}
                    <strong>
                        {% blocktrans trimmed %}
                            Specifically, this means the waiting list is not safe to use together with the minimum
                            distance
                            feature of our seating plan module.
                        {% endblocktrans %}
                    </strong>
                </div>
                {% bootstrap_field sform.waiting_list_enabled layout="control" %}
                {% bootstrap_field sform.waiting_list_auto layout="control" %}
                {% bootstrap_field sform.waiting_list_hours layout="control" %}
                {% bootstrap_field sform.waiting_list_auto_disable layout="control" %}
                {% bootstrap_field sform.waiting_list_names_asked_required layout="control" %}
                {% bootstrap_field sform.waiting_list_phones_asked_required layout="control" %}
                {% bootstrap_field sform.waiting_list_phones_explanation_text layout="control" %}
                {% bootstrap_field sform.waiting_list_limit_per_user layout="control" %}
            </fieldset>
            <fieldset>
                <legend>{% trans "Item metadata" %}</legend>
                <p>
                    {% blocktrans trimmed %}
                        You can here define a set of metadata properties (i.e. variables) that you can later set for
                        your items and re-use in places like ticket layouts. This is an useful timesaver if you create
                        lots and lots of items.
                    {% endblocktrans %}
                </p>
                <div class="formset" data-formset
                     data-formset-prefix="{{ item_meta_property_formset.prefix }}">
                    {{ item_meta_property_formset.management_form }}
                    {% bootstrap_formset_errors item_meta_property_formset %}
                    <div data-formset-body>
                        {% for form in item_meta_property_formset %}
                            <div class="panel panel-default" data-formset-form>
                                <div class="sr-only">
                                    {{ form.id }}
                                    {% bootstrap_field form.DELETE form_group_class="" layout="inline" %}
                                </div>
                                <div class="panel-heading">
                                    <div class="row">
                                        <div class="col-sm-8">
                                            <h3 class="panel-title">{% trans "Property" %}</h3>
                                        </div>
                                        <div class="col-sm-4 text-right flip">
                                            <button type="button" class="btn btn-xs btn-danger" data-formset-delete-button>
                                                <i class="fa fa-trash"></i></button>
                                        </div>
                                    </div>
                                </div>
                                <div class="panel-body form-horizontal">
                                    {% bootstrap_form_errors form %}
                                    {% bootstrap_field form.name layout="control" %}
                                    {% bootstrap_field form.default layout="control" %}
                                    {% bootstrap_field form.required layout="control" %}
                                    {% bootstrap_field form.allowed_values layout="control" %}
                                </div>
                            </div>
                        {% endfor %}
                    </div>
                    <script type="form-template" data-formset-empty-form>
                        {% escapescript %}
                            <div class="panel panel-default" data-formset-form>
                                <div class="sr-only">
                                    {{ item_meta_property_formset.empty_form.id }}
                                    {% bootstrap_field item_meta_property_formset.empty_form.DELETE form_group_class="" layout="inline" %}
                                </div>
                                <div class="panel-heading">
                                    <div class="row">
                                        <div class="col-sm-8">
                                            <h3 class="panel-title">{% trans "Property" %}</h3>
                                        </div>
                                        <div class="col-sm-4 text-right flip">
                                            <button type="button" class="btn btn-xs btn-danger" data-formset-delete-button>
                                                <i class="fa fa-trash"></i></button>
                                        </div>
                                    </div>
                                </div>
                                <div class="panel-body form-horizontal">
                                    {% bootstrap_field item_meta_property_formset.empty_form.name layout="control" %}
                                    {% bootstrap_field item_meta_property_formset.empty_form.default layout="control" %}
                                    {% bootstrap_field item_meta_property_formset.empty_form.required layout="control" %}
                                    {% bootstrap_field item_meta_property_formset.empty_form.allowed_values layout="control" %}
                                </div>
                            </div>
                        {% endescapescript %}
                    </script>
                    <p>
                        <button type="button" class="btn btn-default" data-formset-add>
                            <i class="fa fa-plus"></i> {% trans "Add property" %}</button>
                    </p>
                </div>
            </fieldset>
        </div>
        <div class="form-group submit-group">
            <button type="submit" class="btn btn-primary btn-save">
                {% trans "Save" %}
            </button>
            <div class="pull-left">
                <a href="{% url "control:event.dangerzone" organizer=request.organizer.slug event=request.event.slug %}"
                   class="btn btn-danger btn-lg">
                    <span class="fa fa-trash"></span>
                    {% trans "Cancel or delete event" %}
                </a>
                <a href="{% url "control:events.add" %}?clone={{ request.event.pk }}"
                   class="btn btn-default btn-lg">
                    <span class="fa fa-copy"></span>
                    {% trans "Clone event" %}
                </a>
            </div>
        </div>
    </form>
{% endblock %}
