{% extends "pretixcontrol/event/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load urlreplace %}
{% block title %}{% trans "Dates" context "subevent" %}{% endblock %}
{% block content %}
    <h1>{% trans "Dates" context "subevent" %}</h1>
    {% if subevents|length == 0 and not filter_form.filtered %}
        <div class="empty-collection">
            <p>
                {% blocktrans trimmed %}
                    You haven't created any dates for this event series yet.
                {% endblocktrans %}
            </p>

            <a href="{% url "control:event.subevents.add" organizer=request.event.organizer.slug event=request.event.slug %}"
                    class="btn btn-primary btn-lg"><i class="fa fa-plus"></i>
                {% trans "Create a new date" context "subevent" %}</a>
            <a href="{% url "control:event.subevents.bulk" organizer=request.event.organizer.slug event=request.event.slug %}"
                    class="btn btn-primary btn-lg"><i class="fa fa-plus"></i>
                {% trans "Create many new dates" context "subevent" %}</a>
        </div>
    {% else %}
        <form class="row filter-form" action="" method="get">
            <div class="col-md-3 col-sm-6 col-xs-12">
                {% bootstrap_field filter_form.query layout='inline' %}
            </div>
            <div class="col-md-3 col-sm-6 col-xs-12">
                {% bootstrap_field filter_form.status layout='inline' %}
            </div>
            <div class="col-md-2 col-sm-6 col-xs-12">
                {% bootstrap_field filter_form.date layout='inline' %}
            </div>
            <div class="col-md-2 col-sm-6 col-xs-12">
                {% bootstrap_field filter_form.weekday layout='inline' %}
            </div>
            <div class="col-md-2 col-sm-6 col-xs-12">
                <button class="btn btn-primary btn-block" type="submit">
                    <span class="fa fa-filter"></span>
                    <span class="hidden-md">
                    {% trans "Filter" %}
                </span>
                </button>
            </div>
        </form>
        <p>
            <a href="{% url "control:event.subevents.add" organizer=request.event.organizer.slug event=request.event.slug %}"
                    class="btn btn-default"><i class="fa fa-plus"></i>
                {% trans "Create a new date" context "subevent" %}</a>
            <a href="{% url "control:event.subevents.bulk" organizer=request.event.organizer.slug event=request.event.slug %}"
                    class="btn btn-default"><i class="fa fa-plus"></i>
                {% trans "Create many new dates" context "subevent" %}</a>
        </p>
        <form action="{% url "control:event.subevents.bulkaction"  organizer=request.event.organizer.slug event=request.event.slug %}" method="post">
            {% csrf_token %}
            <div class="table-responsive">
                <table class="table table-hover table-quotas">
                    <thead>
                    <tr>
                        <th>
                            {% if "can_change_event_settings" in request.eventpermset %}
                                <input type="checkbox" data-toggle-table/>
                            {% endif %}
                        </th>
                        <th>
                            {% trans "Name" %}
                        </th>
                        <th>
                            {% trans "Begin" %}
                            <a href="?{% url_replace request 'ordering' '-date_from' %}"><i class="fa fa-caret-down"></i></a>
                            <a href="?{% url_replace request 'ordering' 'date_from' %}"><i class="fa fa-caret-up"></i></a>
                        </th>
                        <th>
                            {% trans "Paid tickets per quota" %}
                            <a href="?{% url_replace request 'ordering' '-sum_tickets_paid' %}"><i class="fa fa-caret-down"></i></a>
                            <a href="?{% url_replace request 'ordering' 'sum_tickets_paid' %}"><i class="fa fa-caret-up"></i></a>
                        </th>
                        <th>
                            {% trans "Status" %}
                            <a href="?{% url_replace request 'ordering' '-active' %}"><i class="fa fa-caret-down"></i></a>
                            <a href="?{% url_replace request 'ordering' 'active' %}"><i class="fa fa-caret-up"></i></a>
                        </th>
                        <th></th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for s in subevents %}
                        <tr>
                            <td>
                                {% if "can_change_event_settings" in request.eventpermset %}
                                    <input type="checkbox" name="subevent" class="" value="{{ s.pk }}"/>
                                {% endif %}
                            </td>
                            <td>
                                <strong><a href="{% url "control:event.subevent" organizer=request.event.organizer.slug event=request.event.slug subevent=s.id %}?returnto={{ request.GET.urlencode|urlencode }}">
                                    {{ s.name }}</a></strong>
                            </td>
                            <td>{{ s.get_date_from_display }}</td>
                            <td>
                                {% for q in s.first_quotas|slice:":3" %}
                                    {% include "pretixcontrol/fragment_quota_box_paid.html" with quota=q %}
                                {% endfor %}
                                {% if s.first_quotas|length > 3 %}
                                    <a href="{% url "control:event.items.quotas" organizer=request.event.organizer.slug event=request.event.slug %}?subevent={{ s.id }}"
                                            class="quotabox-more" data-toggle="tooltip" title="{% trans "More quotas" %}"
                                            data-placement="top">
                                        &middot;&middot;&middot;
                                    </a>
                                {% endif %}
                            </td>
                            <td>
                                {% if not s.active %}
                                    <span class="label label-danger">{% trans "Disabled" %}</span>
                                {% elif s.presale_has_ended %}
                                    <span class="label label-warning">{% trans "Presale over" %}</span>
                                {% elif not s.presale_is_running %}
                                    <span class="label label-warning">{% trans "Presale not started" %}</span>
                                {% else %}
                                    <span class="label label-success">{% trans "On sale" %}</span>
                                {% endif %}
                            </td>
                            <td class="text-right flip">
                                <a href="{% url "control:event.subevent" organizer=request.event.organizer.slug event=request.event.slug subevent=s.id %}?returnto={{ request.GET.urlencode|urlencode }}" class="btn btn-default btn-sm"><i class="fa fa-edit"></i></a>
                                <div class="btn-group {% if forloop.revcounter0 < 2 %}dropup{% endif %}">
                                    <button type="button" class="btn btn-default btn-sm dropdown-toggle"
                                            data-toggle="dropdown">
                                        <span class="fa fa-copy"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right">
                                        <li>
                                            <a href="{% url "control:event.subevents.add" organizer=request.event.organizer.slug event=request.event.slug %}?copy_from={{ s.id }}">
                                                {% trans "Use as a template for a new date" context "subevent" %}
                                            </a>
                                        </li>
                                        <li>
                                            <a href="{% url "control:event.subevents.bulk" organizer=request.event.organizer.slug event=request.event.slug %}?copy_from={{ s.id }}">
                                                {% trans "Use as a template for many new dates" context "subevent" %}
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                                <a href="{% url "control:event.subevent.delete" organizer=request.event.organizer.slug event=request.event.slug subevent=s.id %}?returnto={{ request.GET.urlencode|urlencode }}" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></a>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
            {% if "can_change_event_settings" in request.eventpermset %}
                <button type="submit" class="btn btn-default btn-save" name="action" value="delete">
                    {% trans "Delete selected" %}
                </button>
                <button type="submit" class="btn btn-default btn-save" name="action" value="enable">
                    {% trans "Enable selected" %}
                </button>
                <button type="submit" class="btn btn-default btn-save" name="action" value="disable">
                    {% trans "Disable selected" %}
                </button>
            {% endif %}
        </form>
        {% include "pretixcontrol/pagination.html" %}
    {% endif %}
{% endblock %}
