{% extends "pretixcontrol/event/settings_base.html" %}
{% load i18n %}
{% load formset_tags %}
{% load bootstrap3 %}
{% block title %}
    {% if rule %}
        {% blocktrans with name=rule.name %}Tax rule: {{ name }}{% endblocktrans %}
    {% else %}
        {% trans "Tax rule" %}
    {% endif %}
{% endblock %}
{% block inside %}
    {% if rule %}
        <h1>{% blocktrans with name=rule.name %}Tax rule: {{ name }}{% endblocktrans %}</h1>
    {% else %}
        <h1>{% trans "Tax rule" %}</h1>
    {% 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">
                <div class="tabbed-form">
                    <fieldset>
                        <legend>{% trans "General" %}</legend>
                        {% bootstrap_field form.name layout="control" %}
                        {% bootstrap_field form.internal_name layout="control" %}
                        {% bootstrap_field form.rate addon_after="%" layout="control" %}
                        {% bootstrap_field form.price_includes_tax layout="control" %}
                    </fieldset>
                    <fieldset>
                        <legend>{% trans "Advanced" %}</legend>
                        <div class="alert alert-legal">
                            {% blocktrans trimmed with docs="https://docs.pretix.eu/en/latest/user/events/taxes.html" %}
                                These settings are intended for advanced users. See the
                                <a href="{{ docs }}">documentation</a>
                                for more information. Note that we are not responsible for the correct handling
                                of taxes in your ticket shop. If in doubt, please contact a lawyer or tax consultant.
                            {% endblocktrans %}
                        </div>
                        {% bootstrap_field form.eu_reverse_charge layout="control" %}
                        {% bootstrap_field form.home_country layout="control" %}
                        {% bootstrap_field form.keep_gross_if_rate_changes layout="control" %}
                        <h3>{% trans "Custom taxation rules" %}</h3>
                        <div class="alert alert-warning">
                            {% blocktrans trimmed %}
                                These settings are intended for professional users with very specific taxation situations.
                                If you create any rule here, the reverse charge settings above will be ignored. The rules will be
                                checked in order and once the first rule matches the order, it will be used and all further rules will
                                be ignored. If no rule matches, tax will be charged.
                            {% endblocktrans %}
                            {% trans "All of these rules will only apply if an invoice address is set." %}
                        </div>

                        <div class="formset tax-rules-formset" data-formset data-formset-prefix="{{ formset.prefix }}">
                            {{ formset.management_form }}
                            {% bootstrap_formset_errors formset %}
                            <script type="form-template" data-formset-empty-form>
                                {% escapescript %}
                                    <div class="row tax-rule-line" data-formset-form>
                                        <div class="sr-only">
                                            {{ formset.empty_form.id }}
                                            {% bootstrap_field formset.empty_form.DELETE form_group_class="" layout="inline" %}
                                            {% bootstrap_field formset.empty_form.ORDER form_group_class="" layout="inline" %}
                                        </div>
                                        <div class="col-sm-6 col-md-3 col-lg-3">
                                            {% bootstrap_field formset.empty_form.country layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-sm-6 col-md-3 col-lg-4">
                                            {% bootstrap_field formset.empty_form.address_type layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-sm-6 col-md-3 col-lg-3">
                                            {% bootstrap_field formset.empty_form.action layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-sm-6 col-md-3 col-lg-2 text-right flip">
                                            <button type="button" class="btn btn-default" data-formset-move-up-button>
                                                <i class="fa fa-arrow-up"></i></button>
                                            <button type="button" class="btn btn-default" 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 class="col-sm-6 col-md-3 col-lg-4 col-md-offset-3">
                                            {% bootstrap_field formset.empty_form.invoice_text layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-sm-6 col-md-3 col-lg-3">
                                            {% bootstrap_field formset.empty_form.rate layout='inline' form_group_class="" %}
                                        </div>
                                    </div>
                                {% endescapescript %}
                            </script>
                            <div data-formset-body class="tax-rule-lines">
                                {% for form in formset %}
                                    {% bootstrap_form_errors form %}
                                    <div class="row tax-rule-line" 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-sm-6 col-md-3 col-lg-3">
                                            {% bootstrap_field form.country layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-sm-6 col-md-3 col-lg-4">
                                            {% bootstrap_field form.address_type layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-sm-6 col-md-3 col-lg-3">
                                            {% bootstrap_field form.action layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-sm-6 col-md-3 col-lg-2 text-right flip">
                                            <button type="button" class="btn btn-default" data-formset-move-up-button>
                                                <i class="fa fa-arrow-up"></i></button>
                                            <button type="button" class="btn btn-default" 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 class="col-sm-6 col-md-3 col-lg-4 col-md-offset-3">
                                            {% bootstrap_field form.invoice_text layout='inline' form_group_class="" %}
                                        </div>
                                        <div class="col-sm-6 col-md-3 col-lg-3">
                                            {% bootstrap_field form.rate layout='inline' form_group_class="" %}
                                        </div>
                                    </div>
                                {% endfor %}
                            </div>
                            <div class="row tax-rule-line" data-formset-form>
                                <div class="col-sm-12">
                                    <button type="button" class="btn btn-default" data-formset-add>
                                        <i class="fa fa-plus"></i> {% trans "Add a new rule" %}</button>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                </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 "Change history" %}
                        </h3>
                    </div>
                    {% include "pretixcontrol/includes/logs.html" with obj=rule %}
                </div>
            </div>
        </div>
    </form>
{% endblock %}
