{% extends "pretixpresale/event/base.html" %}
{% load i18n %}
{% load l10n %}
{% load eventurl %}
{% load cache_large %}
{% load money %}
{% load thumb %}
{% load eventsignal %}
{% load rich_text %}

{% block title %}
    {% if "year" in request.GET %}
        {% if list_type == "calendar" %}
            {% blocktrans with datetime=date|date:"F Y" %}
                Calendar for {{ datetime }}
            {% endblocktrans %} ::
        {% elif list_type == "week" %}
            {% blocktrans with datetime=date|date:week_format %}
                Calendar for {{ datetime }}
            {% endblocktrans %} ::
        {% endif %}
    {% elif subevent %}
        {{ subevent.get_date_range_display }} ::
    {% endif %}
{% endblock %}

{% block custom_header %}
    {{ block.super }}
    <meta property="og:title" content="{{ ev.name }}" />
    {% if request.event.has_subevents and not subevent %}
        <meta property="og:description" content="{% trans "Event series" %}" />
    {% else %}
        <meta property="og:description" content="{{ ev.get_date_range_display }}" />
    {% endif %}
    {% if subevent %}
        <meta property="og:url" content="{% abseventurl request.event "presale:event.index" subevent=subevent.pk %}" />
    {% else %}
        <meta property="og:url" content="{% abseventurl request.event "presale:event.index" %}" />
    {% endif %}
{% endblock %}
{% block content %}

    {% autoescape off %}
        <script type="application/ld+json">
            {{ ev.event_microdata }}
        </script>
    {% endautoescape %}
    <main aria-label="{% if show_cart %}{% trans "Your cart, general information, add products to your cart" %}{% else %}{% trans "General information, add products to your cart" %}{% endif %}">
    {% if show_cart %}
        {% include "pretixpresale/event/fragment_cart_box.html" with open=1 %}
    {% endif %}

    {% if request.event.has_subevents %}
        {% if not subevent %}
            {% if event_logo and event_logo_show_title %}
                <h2 class="content-header">
                    {{ event.name }}
                </h2>
            {% endif %}
            {% if frontpage_text %}
                <div>
                    {{ frontpage_text|rich_text }}
                </div>
            {% endif %}

            {% if request.GET.voucher %}
                <div class="alert alert-info">
                    <p>{% trans "Please select a date to redeem your voucher." %}</p>
                </div>
            {% endif %}
        {% endif %}

        {% if subevent and "date" not in request.GET and "filtered" not in request.GET %}
            <p>
            {% if show_cart %}
                <button class="subevent-toggle btn btn-primary btn-block btn-lg" aria-expanded="false">
                    <span class="fa fa-reply" aria-hidden="true"></span>
                    {% trans "Add tickets for a different date" %}
                </button>
            {% else %}
                <button class="subevent-toggle btn btn-default btn-block" aria-expanded="false">
                    {% trans "View other date" %}
                </button>
            {% endif %}
            </p>
        {% else %}
            <h3>{% trans "Choose date to book a ticket" %}</h3>
        {% endif %}
        <div class="panel panel-default subevent-list" id="subevent-list">
            <div class="panel-heading">
                {% if subevent %}
                    {% trans "Other dates" context "subevent" %}
                {% else %}
                    {% trans "Dates" context "subevent" %}
                {% endif %}
            </div>
            <div class="panel-body">
                <div>
                    {% cache_large 15 subevent_list subevent_list_cache_key %}
                        {% if subevent_list.list_type == "calendar" %}
                            {% include "pretixpresale/event/fragment_subevent_calendar.html" %}
                        {% elif subevent_list.list_type == "week" %}
                            {% include "pretixpresale/event/fragment_subevent_calendar_week.html" %}
                        {% else %}
                            {% include "pretixpresale/event/fragment_subevent_list.html" %}
                        {% endif %}
                    {% endcache_large %}
                </div>
            </div>
        </div>
        {% if subevent %}
            <h2 class="subevent-head">{{ subevent.name }}</h2>
            {% if frontpage_text %}
                <div>
                    {{ frontpage_text|rich_text }}
                </div>
            {% endif %}
        {% endif %}
    {% else %}
        {% if event_logo and event_logo_show_title %}
            <h2 class="content-header">
                {{ event.name }}
                {% if request.event.settings.show_dates_on_frontpage %}
                    <small>{{ event.get_date_range_display_as_html }}</small>
                {% endif %}
            </h2>
        {% endif %}
        {% if frontpage_text %}
            <div>
                {{ frontpage_text|rich_text }}
            </div>
        {% endif %}
    {% endif %}

    {% if subevent or not event.has_subevents %}
        {% if not ev.presale_is_running %}
            <div class="alert alert-info">
                {% if ev.presale_has_ended %}
                    {% if event.settings.presale_has_ended_text %}
                        {{ event.settings.presale_has_ended_text|rich_text }}
                    {% else %}
                        {% blocktrans trimmed %}
                            The booking period for this event is over.
                        {% endblocktrans %}
                    {% endif %}
                {% elif event.settings.presale_start_show_date %}
                    {% with date=ev.effective_presale_start|date:"SHORT_DATE_FORMAT" date_normalized=ev.effective_presale_start|date:"Y-m-d" %}
                    {% with time=ev.effective_presale_start|time:"TIME_FORMAT" time_24h=ev.effective_presale_start|time:"H:i" %}
                        <span data-time="{{ ev.effective_presale_start.isoformat }}" data-timezone="{{ request.event.timezone }}">
                            {% blocktrans trimmed with date="<time datetime='"|add:date_normalized|add:"'>"|add:date|add:"</time>"|safe time="<time datetime='"|add:time_24h|add:"'>"|add:time|add:"</time>"|safe %}
                                The booking period for this event will start on {{ date }} at {{ time }}.
                            {% endblocktrans %}
                        </span>
                    {% endwith %}
                    {% endwith %}
                {% else %}
                    {% blocktrans trimmed %}
                        The booking period for this event has not yet started.
                    {% endblocktrans %}
                {% endif %}
            </div>
        {% endif %}
        {% if not cart_namespace or subevent %}
            <div>
                {% include "pretixpresale/event/fragment_event_info.html" with event=request.event subevent=subevent ev=ev show_location=True %}
            </div>
            {% eventsignal event "pretix.presale.signals.front_page_top" request=request subevent=subevent %}
        {% endif %}

        {% if ev.presale_is_running or event.settings.show_items_outside_presale_period %}
            <form method="post" data-asynctask
                    data-asynctask-headline="{% trans "We're now trying to reserve this for you!" %}"
                    data-asynctask-text="{% blocktrans with time=event.settings.reservation_time %}Once the items are in your cart, you will have {{ time }} minutes to complete your purchase.{% endblocktrans %}"
                    class="{% if event.seating_plan_id %}has-seating{% endif %}"
                    action="{% eventurl request.event "presale:event.cart.add" cart_namespace=cart_namespace %}?next={{ cart_redirect|urlencode }}&next_error={{ request.path|urlencode }}">
                {% csrf_token %}
                <input type="hidden" name="subevent" value="{{ subevent.id|default_if_none:"" }}" />
                {% if ev.seating_plan_id and event.settings.seating_choice %}
                    {% if event.has_subevents %}
                        {% eventsignal event "pretix.presale.signals.render_seating_plan" request=request subevent=subevent %}
                    {% else %}
                        {% eventsignal event "pretix.presale.signals.render_seating_plan" request=request %}
                    {% endif %}
                {% endif %}

                {% if waitinglist_seated %}
                    <aside class="front-page" aria-labelledby="waiting-list">
                        <h3 id="waiting-list">{% trans "Waiting list" %}</h3>
                        <div class="row">
                            <div class="col-md-8 col-sm-6 col-xs-12">
                                <p>
                                    {% blocktrans trimmed %}
                                        Some of the categories in the seating plan above are currently sold out. If you want, you can add yourself to the
                                        waiting list. We will then notify if seats are available again.
                                    {% endblocktrans %}
                                </p>
                            </div>
                            <div class="col-md-4 col-sm-6 col-xs-12">
                                <a href="{% eventurl event "presale:event.waitinglist" cart_namespace=cart_namespace|default_if_none:"" %}{% if subevent %}?subevent={{ subevent.pk }}{% endif %}" class="btn btn-default btn-block">
                                    <span class="fa fa-plus-circle" aria-hidden="true"></span>
                                    {% trans "Join waiting list" %}
                                </a>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </aside>
                {% endif %}

                {% include "pretixpresale/event/fragment_product_list.html" %}
                {% if ev.presale_is_running and display_add_to_cart %}
                    <div class="front-page">
                        <div class="row">
                            <div class="col-md-4 col-md-offset-8 col-xs-12">
                                <button class="btn btn-block btn-primary btn-lg" type="submit" id="btn-add-to-cart">
                                    {% if request.event.settings.redirect_to_checkout_directly %}
                                        {% if allfree %}
                                            <i class="fa fa-check" aria-hidden="true"></i> {% trans "Register" context "free_tickets" %}
                                        {% else %}
                                           <i class="fa fa-shopping-cart" aria-hidden="true"></i> {% trans "Proceed with checkout" %}
                                        {% endif %}
                                    {% else %}
                                        <i class="fa fa-shopping-cart" aria-hidden="true"></i> {% trans "Add to cart" %}
                                    {% endif %}
                                </button>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </div>
                {% endif %}
            </form>
        {% endif %}
    {% endif %}
    </main>
    {% if show_vouchers %}
        <aside class="front-page" aria-labelledby="redeem-a-voucher">
            <h3 id="redeem-a-voucher">{% trans "Redeem a voucher" %}</h3>
            {% include "pretixpresale/event/fragment_voucher_form.html" %}
        </aside>
    {% endif %}
    {% if not cart_namespace %}
        {% eventsignal event "pretix.presale.signals.front_page_bottom" subevent=subevent request=request %}
        <aside class="front-page" aria-labelledby="if-you-already-ordered-a-ticket">
            <h3 id="if-you-already-ordered-a-ticket">{% trans "If you already ordered a ticket" %}</h3>
            <div class="row">
                <div class="col-md-8 col-xs-12">
                    <p>
                        {% blocktrans trimmed %}
                            If you want to see or change the status and details of your order, click on the link in one of the
                            emails we sent you during the order process. If you cannot find the link, click on the
                            following button to request the link to your order to be sent to you again.
                        {% endblocktrans %}
                    </p>
                </div>
                <div class="col-md-4 col-xs-12">
                    <a class="btn btn-block btn-default" href="{% eventurl event "presale:event.resend_link" %}">
                        {% trans "Resend order link" %}
                    </a>
                </div>
                <div class="clearfix"></div>
            </div>
        </aside>
    {% else %}
        {% eventsignal event "pretix.presale.signals.front_page_bottom_widget" subevent=subevent request=request %}
    {% endif %}
{% endblock %}
