{% extends "pretixcontrol/event/settings_base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load static %}
{% load hierarkey_form %}
{% load formset_tags %}
{% block custom_header %}
    {{ block.super }}
    <link type="text/css" rel="stylesheet" href="{% url "control:pdf.css" %}">
{% 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 %}
        <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" %}
                <div class="geodata-section">
                    {% bootstrap_field form.location layout="control" %}
                    <div class="form-group geodata-group"
                         data-tiles="{{ global_settings.leaflet_tiles|default_if_none:"" }}"
                         data-attrib="{{ global_settings.leaflet_tiles_attribution }}"
                         data-icon="{% static "leaflet/images/marker-icon.png" %}"
                         data-shadow="{% static "leaflet/images/marker-shadow.png" %}">
                        <label class="col-md-3 control-label">
                            {% trans "Geo coordinates" %}<br>
                            <span class="optional">{% trans "Optional" %}</span>
                        </label>
                        <div class="col-md-4">
                            {% bootstrap_field form.geo_lat layout="inline" %}
                            {% if global_settings.opencagedata_apikey %}
                                <p class="attrib">
                                    <a href="https://openstreetmap.org/" target="_blank">
                                        {% trans "Geocoding data © OpenStreetMap" %}
                                    </a>
                                </p>
                            {% endif %}
                        </div>
                        <div class="col-md-4">
                            {% bootstrap_field form.geo_lon layout="inline" %}
                        </div>
                        <div class="col-md-1">
                        </div>
                    </div>
                </div>
                {% 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" %}

                {% 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" %}
                                    </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" %}
            </fieldset>
            <fieldset>
                <legend>{% trans "Attendee data" %}</legend>
                {% bootstrap_field sform.attendee_names_asked layout="control" %}
                {% bootstrap_field sform.attendee_names_required layout="control" %}
                {% bootstrap_field sform.name_scheme layout="control" %}
                {% bootstrap_field sform.name_scheme_titles layout="control" %}
                {% bootstrap_field sform.order_email_asked_twice layout="control" %}
                {% bootstrap_field sform.attendee_emails_asked layout="control" %}
                {% bootstrap_field sform.attendee_emails_required layout="control" %}
                {% bootstrap_field sform.attendee_company_asked layout="control" %}
                {% bootstrap_field sform.attendee_company_required layout="control" %}
                {% bootstrap_field sform.attendee_addresses_asked layout="control" %}
                {% bootstrap_field sform.attendee_addresses_required 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_email_helptext layout="control" %}
                {% bootstrap_field sform.banner_text layout="control" %}
                {% bootstrap_field sform.banner_text_bottom 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 %}
                {% propagated request.event org_url "primary_color" "primary_font" "theme_color_success" "theme_color_danger" %}
                    {% 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 %}
            </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" %}
            </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.show_variations_expanded layout="control" %}
                {% bootstrap_field sform.hide_sold_out layout="control" %}
                {% bootstrap_field sform.meta_noindex layout="control" %}
                {% 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 %}
            </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>
                <legend>{% trans "Waiting list" %}</legend>
                {% bootstrap_field sform.waiting_list_enabled layout="control" %}
                {% bootstrap_field sform.waiting_list_auto layout="control" %}
                {% bootstrap_field sform.waiting_list_hours 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="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.name layout='inline' form_group_class="" %}
                                </div>
                                <div class="col-md-5 col-lg-6">
                                    {% bootstrap_field form.default layout='inline' form_group_class="" %}
                                </div>
                                <div class="col-md-2 col-lg-1 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">
                                    {{ item_meta_property_formset.empty_form.id }}
                                    {% bootstrap_field item_meta_property_formset.empty_form.DELETE form_group_class="" layout="inline" %}
                                </div>
                                <div class="col-md-5">
                                    {% bootstrap_field item_meta_property_formset.empty_form.name layout='inline' form_group_class="" %}
                                </div>
                                <div class="col-md-5 col-lg-6">
                                    {% bootstrap_field item_meta_property_formset.empty_form.default layout='inline' form_group_class="" %}
                                </div>
                                <div class="col-md-2 col-lg-1 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 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 %}
