{% extends "pretixpresale/event/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load money %}
{% load eventurl %}
{% load eventsignal %}
{% block title %}{% trans "Review order" %}{% endblock %}
{% block content %}
<main aria-label="{% trans "Review order" %}">
    <h2>{% trans "Review order" %}</h2>
    {% include "pretixpresale/event/fragment_checkoutflow.html" %}
    <p>{% trans "Please review the details below and confirm your order." %}</p>
    <form method="post" data-asynctask
            data-asynctask-headline="{% trans "Please hang tight, we're finalizing your order!" %}">
        {% csrf_token %}
        <div class="panel panel-primary cart">
            <div class="panel-heading panel-heading-flex">
                <h3 class="panel-title">
                    <i class="fa fa-shopping-cart" aria-hidden="true"></i>
                    {% trans "Your cart" %}
                    <a href="{% eventurl request.event "presale:event.index" cart_namespace=cart_namespace|default_if_none:"" %}" class="h6">
                        <span class="fa fa-edit" aria-hidden="true"></span>{% trans "Add or remove tickets" %}
                    </a>
                </h3>
                <span class="panel-heading-flex-gap"></span>
                <strong class="helper-display-block" id="cart-deadline-short" data-expires="{{ cart.first_expiry|date:"Y-m-d H:i:sO" }}">
                    {% if cart.minutes_left > 0 or cart.seconds_left > 0 %}
                        {{ cart.minutes_left|stringformat:"02d" }}:{{ cart.seconds_left|stringformat:"02d" }}
                    {% else %}
                        {% trans "Cart expired" %}
                    {% endif %}
                </strong>
            </div>
            <div class="panel-body">
                {% include "pretixpresale/event/fragment_cart.html" with cart=cart event=request.event editable=False %}
            </div>
        </div>
        {% if payments %}
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        {% trans "Payment" %}
                        {% if payment_provider.identifier != "free" %}
                                <a href="{% eventurl request.event "presale:event.checkout" step="payment" cart_namespace=cart_namespace|default_if_none:"" %}" aria-label="{% trans "Modify payment" %}" class="h6">
                                    <span class="fa fa-edit" aria-hidden="true"></span>{% trans "Modify" %}
                                </a>
                        {% endif %}
                    </h3>
                </div>
                <ul class="list-group">
                    {% for payment, rendered_block in payments %}
                        <li class="list-group-item payment">
                            {% if payments|length > 1 %}
                                <div class="row">
                                    <div class="col-sm-10 col-xs-12">
                                        <h4>{{ payment.provider_name }}</h4>
                                        {{ rendered_block }}
                                    </div>
                                    <div class="col-sm-2 col-xs-12 text-right">
                                        <h4>{{ payment.payment_amount|money:request.event.currency }}</h4>
                                    </div>
                                </div>
                            {% else %}
                                {{ rendered_block }}
                            {% endif %}
                        </li>
                    {% endfor %}
                </ul>
            </div>
        {% endif %}
        {% eventsignal event "pretix.presale.signals.checkout_confirm_page_content" request=request %}
        <div class="row">
            {% if invoice_address_asked %}
                <div class="col-md-6 col-xs-12">
                    <div class="panel panel-default panel-contact">
                        <div class="panel-heading">
                            <h3 class="panel-title">
                                {% trans "Invoice information" %}
                                <a href="{% eventurl request.event "presale:event.checkout" step="questions" cart_namespace=cart_namespace|default_if_none:"" %}?invoice=1#invoice-details" aria-label="{% trans "Modify invoice information" %}" class="h6">
                                    <span class="fa fa-edit" aria-hidden="true"></span>{% trans "Modify" %}
                                </a>
                            </h3>
                        </div>
                        <div class="panel-body">
                            <dl class="dl-horizontal">
                                {% if addr.company %}
                                    <dt>{% trans "Company" %}</dt>
                                    <dd>{{ addr.company }}</dd>
                                {% endif %}
                                <dt>{% trans "Name" %}</dt>
                                <dd>{{ addr.name }}</dd>
                                <dt>{% trans "Address" %}</dt>
                                <dd>{{ addr.street|linebreaksbr }}</dd>
                                <dt>{% trans "ZIP code and city" %}</dt>
                                <dd>{{ addr.zipcode }} {{ addr.city }}</dd>
                                <dt>{% trans "Country" %}</dt>
                                <dd>{{ addr.country.name }}</dd>
                                {% if addr.state %}
                                    <dt>{% trans "State" context "address" %}</dt>
                                    <dd>{{ addr.state_name }}</dd>
                                {% endif %}
                                {% if request.event.settings.invoice_address_vatid and addr.vat_id %}
                                    <dt>{% trans "VAT ID" %}</dt>
                                    <dd>{{ addr.vat_id }}</dd>
                                {% endif %}
                                {% if addr.beneficiary %}
                                    <dt>{% trans "Beneficiary" %}</dt>
                                    <dd>{{ addr.beneficiary|linebreaksbr }}</dd>
                                {% endif %}
                                {% if request.event.settings.invoice_address_custom_field and addr.custom_field %}
                                    <dt>{{ request.event.settings.invoice_address_custom_field }}</dt>
                                    <dd>{{ addr.custom_field }}</dd>
                                {% endif %}
                                {% if addr.internal_reference %}
                                    <dt>{% trans "Internal reference" %}</dt>
                                    <dd>{{ addr.internal_reference }}</dd>
                                {% endif %}
                            </dl>
                        </div>
                    </div>
                </div>
            {% endif %}
            <div class="{% if invoice_address_asked %}col-md-6{% endif %} col-xs-12">
                <div class="panel panel-default panel-contact">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            {% trans "Contact information" %}
                            <a href="{% eventurl request.event "presale:event.checkout" step="questions" cart_namespace=cart_namespace|default_if_none:"" %}" aria-label="{% trans "Modify contact information" %}" class="h6">
                                <span class="fa fa-edit" aria-hidden="true"></span>{% trans "Modify" %}
                            </a>
                        </h3>
                    </div>
                    <div class="panel-body">
                        {% if customer %}
                        <dl class="dl-horizontal">
                            <dt>{% trans "Customer account" %}</dt>
                            <dd>{{ customer.email }}<br>{{ customer.name }}<br>#{{ customer.identifier }}</dd>
                        </dl>
                        {% endif %}
                        {% if not asked and event.settings.invoice_name_required %}
                            <dl class="dl-horizontal">
                                <dt>{% trans "Name" %}</dt>
                                <dd>{{ addr.name }}</dd>
                            </dl>
                        {% endif %}
                        {% for l, v in contact_info %}
                            {% if v is False %}
                                {# do not show #}
                            {% elif v is True %}
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox" class="checkbox" checked disabled>
                                        {{ l }}
                                    </label>
                                </div>
                            {% else %}
                                <dl class="dl-horizontal">
                                    <dt>{{ l }}</dt>
                                    <dd>{{ v }}</dd>
                                </dl>
                            {% endif %}
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>
        {% if confirm_messages %}
            <div class="panel panel-primary panel-confirm" role="group" aria-labelledby="confirm_heading">
                <div class="panel-heading">
                    <h3 class="panel-title" id="confirm_heading">
                        {% trans "Confirmations" %}
                    </h3>
                </div>
                <div class="panel-body">
                    {% for key, desc in confirm_messages.items %}
                        <div class="checkbox">
                            <label for="input_confirm_{{ key }}">
                                <input type="checkbox" class="checkbox" value="yes" name="confirm_{{ key }}" id="input_confirm_{{ key }}" required>
                                {{ desc|safe }}
                            </label>
                        </div>
                    {% endfor %}
                </div>
            </div>
        {% endif %}
        {% if require_approval %}
            <div class="alert alert-warning">
                <strong>
                    {% trans "After you submitted your order using the button below, it will require approval by the event organizer before it can be confirmed and forms a valid contract." %}
                </strong>
                {% blocktrans trimmed %}
                    We will send you an email as soon as the event organizer approved or rejected your order.
                {% endblocktrans %}
                {% if cart.total > 0 %}
                    {% blocktrans trimmed %}
                         If your order was approved, we will send you a link that you can use to pay.
                    {% endblocktrans %}
                {% endif %}
            </div>
        {% endif %}
        <div class="row checkout-button-row clearfix">
            <div class="col-md-4 col-sm-6">
                <a class="btn btn-block btn-default btn-lg"
                        href="{{ prev_url }}">
                    {% trans "Go back" %}
                </a>
            </div>
            <div class="col-md-4 col-md-offset-4 col-sm-6">
                <button class="btn btn-block btn-primary btn-lg" type="submit">
                    {% if cart.total > 0 %}
                        {% trans "Place binding order" %}
                    {% else %}
                        {% trans "Submit registration" %}
                    {% endif %}
                </button>
            </div>
            <div class="clearfix"></div>
        </div>
    </form>
</main>
{% endblock %}
