{% extends "pretixcontrol/items/base.html" %}
{% load i18n %}
{% block title %}{% trans "Products" %}{% endblock %}
{% block inside %}
    <h1>{% trans "Products" %}</h1>
    <p>
        {% blocktrans trimmed %}
            Below, you find a list of all available products. You can click on a product name to inspect and change
            product details. You can also use the buttons on the right to change the order of products within a
            give category.
        {% endblocktrans %}
    </p>
    {% if items|length == 0 %}
        <div class="empty-collection">
            <p>
                {% blocktrans trimmed %}
                    You haven't created any products yet.
                {% endblocktrans %}
            </p>

            <a href="{% url "control:event.items.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 product" %}</a>
        </div>
    {% else %}
        <p>
            <a href="{% url "control:event.items.add" organizer=request.event.organizer.slug event=request.event.slug %}"
                    class="btn btn-default"><i class="fa fa-plus"></i> {% trans "Create a new product" %}</a>
        </p>
        <form method="post">
            {% csrf_token %}
        <div class="table-responsive">
            <table class="table table-condensed table-hover">
                <thead>
                <tr>
                    <th>{% trans "Product name" %}</th>
                    <th></th>
                    <th class="iconcol"></th>
                    <th class="iconcol"></th>
                    <th class="iconcol"></th>
                    <th>{% trans "Category" %}</th>
                    <th class="action-col-2"><span class="sr-only">Move</span></th>
                    <th class="action-col-2"><span class="sr-only">Edit</span></th>
                </tr>
                </thead>
                {% regroup items by category as cat_list %}
                {% for c in cat_list %}
                    <tbody data-dnd-url="{% url "control:event.items.reorder" organizer=request.event.organizer.slug event=request.event.slug %}">
                    {% for i in c.list %}
                        {% if forloop.counter0 == 0 and i.category %}<tr class="sortable-disabled"><th colspan="8" scope="colgroup" class="text-muted">{{ i.category }}</th></tr>{% endif %}
                        <tr data-dnd-id="{{ i.id }}" {% if not i.active %}class="row-muted"{% endif %}>
                            <td><strong>
                                {% if not i.active %}<strike>{% endif %}
                                <a href="{% url "control:event.item" organizer=request.event.organizer.slug event=request.event.slug item=i.id %}">{{ i }}</a>
                                {% if not i.active %}</strike>{% endif %}
                                </strong>
                                <br>
                                <small class="text-muted">
                                    #{{ i.pk }}
                                    {% for k, c in sales_channels.items %}
                                        {% if k in i.sales_channels %}
                                            <span class="fa fa-fw fa-{{ c.icon }} text-muted"
                                                  data-toggle="tooltip" title="{% trans c.verbose_name %}"></span>
                                        {% else %}
                                        {% endif %}
                                    {% endfor %}
                                </small>
                            </td>
                            <td>
                                {% if i.available_from or i.available_until %}
                                    {% if not i.is_available_by_time %}
                                        <span class="label label-danger" data-toggle="tooltip"
                                                title="{% trans "Currently unavailable since a limited timeframe for this product has been set" %}">
                                            <span class="fa fa-clock-o fa-fw" data-toggle="tooltip">
                                            </span>
                                        </span>
                                    {% else %}
                                        <span class="fa fa-clock-o fa-fw text-muted" data-toggle="tooltip" title="{% trans "Only available in a limited timeframe" %}">
                                        </span>
                                    {% endif %}
                                {% endif %}
                            </td>
                            <td>
                                {% if i.admission %}
                                    {% if i.personalized %}
                                        <span class="fa fa-id-card-o fa-fw text-muted" data-toggle="tooltip" title="{% trans "Personalized admission ticket" %}"></span>
                                    {% else %}
                                        <span class="fa fa-user fa-fw text-muted" data-toggle="tooltip" title="{% trans "Admission ticket without personalization" %}"></span>
                                    {% endif %}
                                {% elif i.issue_giftcard %}
                                    <span class="fa fa-gift fa-fw text-muted" data-toggle="tooltip" title="{% trans "Gift card" %}"></span>
                                {% endif %}
                            </td>
                            <td>
                                {% if i.var_count %}
                                    <span class="fa fa-th-large fa-fw text-muted" data-toggle="tooltip" title="{% trans "Product with variations" %}"></span>
                                {% endif %}
                            </td>
                            <td>
                                {% if i.category.is_addon %}
                                    <span class="fa fa-puzzle-piece fa-fw text-muted" data-toggle="tooltip"
                                            title="{% trans "Only available as an add-on product" %}"></span>
                                {% elif i.require_bundling %}
                                    <span class="fa fa-puzzle-piece fa-fw text-muted" data-toggle="tooltip"
                                          title="{% trans "Only available as part of a bundle" %}"></span>
                                {% elif i.hide_without_voucher %}
                                    <span class="fa fa-tags fa-fw text-muted" data-toggle="tooltip"
                                            title="{% trans "Only visible with a voucher" %}"></span>
                                {% elif i.require_voucher %}
                                    <span class="fa fa-tags fa-fw text-muted" data-toggle="tooltip"
                                            title="{% trans "Can only be bought using a voucher" %}"></span>
                                {% endif %}
                            </td>
                            <td>{% if i.category %}{{ i.category.name }}{% endif %}</td>
                            <td>
                                <button formaction="{% url "control:event.items.up" organizer=request.event.organizer.slug event=request.event.slug item=i.id %}" class="btn btn-default btn-sm sortable-up"{% if forloop.counter0 == 0 %} disabled{% endif %}><i class="fa fa-arrow-up"></i></button>
                                <button formaction="{% url "control:event.items.down" organizer=request.event.organizer.slug event=request.event.slug item=i.id %}" class="btn btn-default btn-sm sortable-down"{% if forloop.revcounter0 == 0 %} disabled{% endif %}><i class="fa fa-arrow-down"></i></button>
                                <span class="dnd-container"></span>
                            </td>
                            <td class="text-right flip col-actions">
                                <a href="{% url "control:event.item" organizer=request.event.organizer.slug event=request.event.slug item=i.id %}" class="btn btn-default btn-sm"><i class="fa fa-edit"></i></a>
                                <a href="{% url "control:event.items.add" organizer=request.event.organizer.slug event=request.event.slug %}?copy_from={{ i.id }}" class="btn btn-default btn-sm" title="{% trans "Clone" %}" data-toggle="tooltip"><i class="fa fa-copy"></i></a>
                                <a href="{% url "control:event.items.delete" organizer=request.event.organizer.slug event=request.event.slug item=i.id %}" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></a>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                {% endfor %}
            </table>
        </div>
        </form>
        {% include "pretixcontrol/pagination.html" %}
    {% endif %}
{% endblock %}
