{% 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 %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">
                    {% trans "Filter" %}
                </h3>
            </div>
            <form class="panel-body filter-form" action="" method="get">
                <div class="row">
                    <div class="col-lg-2 col-md-6 col-sm-6 col-xs-12">
                        {% bootstrap_field filter_form.query %}
                    </div>
                    <div class="col-lg-2 col-md-6 col-md-2 col-sm-6 col-xs-12">
                        {% bootstrap_field filter_form.status %}
                    </div>
                    <div class="col-lg-2 col-md-3 col-sm-6 col-xs-12">
                        {% bootstrap_field filter_form.date_from %}
                    </div>
                    <div class="col-lg-2 col-md-3 col-sm-6 col-xs-12">
                        {% bootstrap_field filter_form.date_until %}
                    </div>
                    <div class="col-lg-2 col-md-3 col-sm-6 col-xs-12">
                        {% bootstrap_field filter_form.time_from %}
                    </div>
                    <div class="col-lg-2 col-md-3 col-sm-6 col-xs-12">
                        {% bootstrap_field filter_form.time_until %}
                    </div>
                    <div class="col-xs-12 one-line-checkboxes">
                        {% bootstrap_field filter_form.weekday %}
                    </div>
                    {% for mf in meta_fields %}
                        <div class="col-md-3 col-sm-6 col-xs-12">
                            {% bootstrap_field mf %}
                        </div>
                    {% endfor %}
                </div>

                <div class="text-right flip">
                    <button class="btn btn-primary btn-lg" type="submit">
                        <span class="fa fa-filter"></span>
                        {% trans "Filter" %}
                    </button>
                </div>
            </form>
        </div>
        {% if "can_change_event_settings" in request.eventpermset %}
            <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>
        {% endif %}
        <form action="{% url "control:event.subevents.bulkaction"  organizer=request.event.organizer.slug event=request.event.slug %}" method="post">
            {% csrf_token %}
            {% for field in filter_form %}
                {{ field.as_hidden }}
            {% endfor %}
            <div class="table-responsive">
                <table class="table table-hover table-quotas">
                    <thead>
                    <tr>
                        <th>
                            {% if "can_change_event_settings" in request.eventpermset %}
                                <label aria-label="{% trans "select all rows for batch-operation" %}" class="batch-select-label"><input type="checkbox" data-toggle-table/></label>
                            {% endif %}
                        </th>
                        <th>
                            {% trans "Name" %}
                        </th>
                        <th>
                            {% trans "Begin" %}
                            <a href="?{% url_replace request 'filter-ordering' '-date_from' %}"><i class="fa fa-caret-down"></i></a>
                            <a href="?{% url_replace request 'filter-ordering' 'date_from' %}"><i class="fa fa-caret-up"></i></a>
                        </th>
                        <th>
                            {% trans "Paid tickets per quota" %}
                        </th>
                        <th>
                            {% trans "Status" %}
                            <a href="?{% url_replace request 'filter-ordering' '-active' %}"><i class="fa fa-caret-down"></i></a>
                            <a href="?{% url_replace request 'filter-ordering' 'active' %}"><i class="fa fa-caret-up"></i></a>
                        </th>
                        <th></th>
                    </tr>
                    {% if "can_change_event_settings" in request.eventpermset and page_obj.paginator.num_pages > 1 %}
                        <tr class="table-select-all warning hidden">
                            <td>
                                <input type="checkbox" name="__ALL" id="__all" data-results-total="{{ page_obj.paginator.count }}">
                            </td>
                            <td colspan="5">
                                <label for="__all">
                                    {% trans "Select all results on other pages as well" %}
                                </label>
                            </td>
                        </tr>
                    {% endif %}
                    </thead>
                    <tbody>
                    {% for s in subevents %}
                        <tr>
                            <td>
                                {% if "can_change_event_settings" in request.eventpermset %}
                                    <label aria-label="{% trans "select row for batch-operation" %}" class="batch-select-label"><input type="checkbox" name="subevent" class="batch-select-checkbox" value="{{ s.pk }}"/></label>
                                {% 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><br>
                                <small class="text-muted">
                                    #{{ s.pk }}
                                    {% for k, v in s.meta_data.items %}
                                        {% if v %}
                                            <small class="text-muted">&middot; {{ k }}: {{ v }}</small>
                                        {% endif %}
                                    {% endfor %}
                                    {% if s.comment %}
                                        <br>{{ s.comment|linebreaksbr }}
                                    {% endif %}
                                </small>
                            </td>
                            <td>
                                {{ s.get_date_from_display }}<br>
                                <span class="text-muted">
                                   {{ s.date_from|date:"l" }}
                                </span>
                            </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 %}
                <div class="batch-select-actions">
                    <button type="submit" class="btn btn-danger btn-save" name="action" value="delete">
                        <i class="fa fa-trash"></i>{% trans "Delete selected" %}
                    </button>
                    <button type="submit" class="btn btn-primary btn-save" name="action" value="edit"
                            formaction="{% url "control:event.subevents.bulkedit"  organizer=request.event.organizer.slug event=request.event.slug %}">
                        <i class="fa fa-edit"></i>{% trans "Edit selected" %}
                    </button>
                    <button type="submit" class="btn btn-default btn-save" name="action" value="enable">
                        <i class="fa fa-check"></i>{% trans "Activate selected" %}
                    </button>
                    <button type="submit" class="btn btn-default btn-save" name="action" value="disable">
                        <i class="fa fa-ban"></i>{% trans "Deactivate selected" %}
                    </button>
                </div>
            {% endif %}
        </form>
        {% include "pretixcontrol/pagination.html" %}
    {% endif %}
{% endblock %}
