{% extends "pretixcontrol/items/base.html" %}
{% load i18n %}
{% block title %}{% trans "Quotas" %}{% endblock %}
{% block inside %}
    <h1>{% trans "Quotas" %}</h1>
    <p>
        {% blocktrans trimmed %}
            To make your products actually available, you also need quotas. Quotas define, how many instances of
            your product pretix will sell. This way, you can configure whether your event can take an unlimited
            number of attendees or the number of attendees is limited. You can assign a product to multiple quotas
            to fulfil more complex requirements, e.g. if you want to limit the total number of tickets sold and the
            number of a specific ticket type at the same time.
        {% endblocktrans %}
    </p>
    {% if request.event.has_subevents %}
        <form class="form-inline helper-display-inline" action="" method="get">
            <p>
                {% if request.event.has_subevents %}
                    <select name="subevent" class="form-control">
                        <option value="">{% trans "All dates" context "subevent" %}</option>
                        {% for se in request.event.subevents.all %}
                            <option value="{{ se.id }}"
                                    {% if request.GET.subevent|add:0 == se.id %}selected="selected"{% endif %}>
                                {{ se.name }} – {{ se.get_date_range_display }}
                            </option>
                        {% endfor %}
                    </select>
                {% endif %}
                <button class="btn btn-primary" type="submit">{% trans "Filter" %}</button>
            </p>
        </form>
    {% endif %}
    {% if quotas|length == 0 %}
        <div class="empty-collection">
            <p>
                {% if request.GET.subevent %}
                    {% trans "Your search did not match any quotas." %}
                {% else %}
                    {% blocktrans trimmed %}
                        You haven't created any quotas yet.
                    {% endblocktrans %}
                {% endif %}
            </p>

            <a href="{% url "control:event.items.quotas.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 quota" %}</a>
        </div>
    {% else %}
        <p>
            <a href="{% url "control:event.items.quotas.add" organizer=request.event.organizer.slug event=request.event.slug %}" class="btn btn-default"><i class="fa fa-plus"></i> {% trans "Create a new quota" %}
            </a>
        </p>
        <div class="table-responsive">
            <table class="table table-hover table-quotas">
                <thead>
                <tr>
                    <th>{% trans "Quota name" %}</th>
                    <th>{% trans "Products" %}</th>
                    {% if request.event.has_subevents %}
                        <th>{% trans "Date" context "subevent" %}</th>
                    {% endif %}
                    <th>{% trans "Total capacity" %}</th>
                    <th>{% trans "Capacity left" %}</th>
                    <th class="action-col-2"></th>
                </tr>
                </thead>
                <tbody>
                {% for q in quotas %}
                    <tr>
                        <td>
                            <strong><a href="{% url "control:event.items.quotas.show" organizer=request.event.organizer.slug event=request.event.slug quota=q.id %}">{{ q.name }}</a></strong>
                        </td>
                        <td>
                            <ul>
                                {% for item in q.items.all %}
                                    <li><a href="{% url "control:event.item" organizer=request.event.organizer.slug event=request.event.slug item=item.id %}">{{ item.name }}</a></li>
                                {% endfor %}
                            </ul>
                        </td>
                        {% if request.event.has_subevents %}
                            <td>{{ q.subevent.name }} – {{ q.subevent.get_date_range_display }}</td>
                        {% endif %}
                        <td>{% if q.size == None %}Unlimited{% else %}{{ q.size }}{% endif %}</td>
                        <td>{% include "pretixcontrol/items/fragment_quota_availability.html" with availability=q.availability %}</td>
                        <td class="text-right">
                            <a href="{% url "control:event.items.quotas.edit" organizer=request.event.organizer.slug event=request.event.slug quota=q.id %}" class="btn btn-default btn-sm"><i class="fa fa-edit"></i></a>
                            <a href="{% url "control:event.items.quotas.delete" organizer=request.event.organizer.slug event=request.event.slug quota=q.id %}" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    {% endif %}
    {% include "pretixcontrol/pagination.html" %}
{% endblock %}
