{% extends "pretixcontrol/items/base.html" %}
{% load i18n %}
{% load money %}
{% load static %}
{% block title %}{% trans "Products" %}{% endblock %}
{% block inside %}
    {% blocktrans asvar s_taxes %}taxes{% endblocktrans %}
    <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 or move
            products to a different category.
        {% endblocktrans %}
    </p>
    {% if items|length == 0 %}
        <div class="empty-collection">
            <p>
                {% blocktrans trimmed %}
                    You haven't created any products yet.
                {% endblocktrans %}
            </p>

            {% if 'event.items:write' in request.eventpermset %}
                <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>
            {% endif %}
        </div>
    {% else %}
        {% if 'event.items:write' in request.eventpermset %}
            <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>
        {% endif %}
        <form method="post">
            {% csrf_token %}
        <div class="table-responsive">
            <table class="table table-condensed table-hover table-items">
                <thead>
                <tr>
                    <th>{% trans "Product name" %}</th>
                    <th></th>
                    <th class="iconcol"></th>
                    <th class="iconcol"></th>
                    <th class="iconcol"></th>
                    <th class="iconcol"></th>
                    <th class="text-right flip">{% trans "Default price" %}</th>
                    <th class="action-col-2"><span class="sr-only">Edit</span></th>
                </tr>
                </thead>

                {% for c, items in cat_list %}
                    {% if c %}
                        <tbody>
                            <tr class="sortable-disabled"><th colspan="9" scope="colgroup" class="text-muted">
                                {{ c.internal_name|default:c.name }}{% if c.category_type != "normal" %} <span class="font-normal">({{ c.get_category_type_display }})</span>{% endif %}
                                {% if 'event.items:write' in request.eventpermset %}
                                    <a href="{% url "control:event.items.categories.edit" organizer=request.event.organizer.slug event=request.event.slug category=c.id %}" title="{% trans "Edit" %}"><span class="fa fa-edit fa-fw"></span></a>
                                {% endif %}
                            </th></tr>
                        </tbody>
                    {% endif %}
                    <tbody data-dnd-url="{% url "control:event.items.reorder" organizer=request.event.organizer.slug event=request.event.slug category=c.id|default:0 %}"
                        data-dnd-group="items">
                    {% for i in items %}
                        {% if forloop.counter0 == 0 and i.category %}{% endif %}
                        <tr data-dnd-id="{{ i.id }}" {% if not i.active %}class="row-muted"{% endif %}>
                            <td><strong>
                                {% if not i.active %}<strike>{% endif %}
                                {% if 'event.items:write' in request.eventpermset %}
                                    <a href="{% url "control:event.item" organizer=request.event.organizer.slug event=request.event.slug item=i.id %}">{{ i }}</a>
                                {% else %}
                                    {{ i }}
                                {% endif %}
                                {% if not i.active %}</strike>{% endif %}
                                </strong>
                                <br>
                                <small class="text-muted">
                                    #{{ i.pk }}
                                    {% for c in sales_channels %}
                                        {% if i.all_sales_channels or c in i.limit_sales_channels.all %}
                                            {% if "." in c.icon %}
                                                <img src="{% static c.icon %}" class="fa-like-image"
                                                     data-toggle="tooltip" title="{{ c.label }}">
                                            {% else %}
                                                <span class="fa fa-fw fa-{{ c.icon }} text-muted"
                                                      data-toggle="tooltip" title="{{ c.label }}"></span>
                                            {% endif %}
                                        {% 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-bars fa-fw text-muted" data-toggle="tooltip" title="{% trans "Product with variations" %}"></span>
                                {% endif %}
                            </td>
                            <td>
                                {% if i.requires_seat %}
                                    <span data-toggle="tooltip"
                                          title="{% if request.event.has_subevents %}{% trans "Product assigned to seating plan for one or more dates" context "subevent" %}{% else %}{% trans "Product assigned to seating plan" %}{% endif %}">
                                        {% include "icons/seat.svg" with cls="svg-icon text-muted" %}
                                    </span>
                                {% endif %}
                            </td>
                            <td>
                                {% if i.category.is_addon %}
                                    <span class="fa fa-plus-square 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-plus-square 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 class="text-right flip">
                                {% if i.free_price %}
                                    <span class="fa fa-edit fa-fw text-muted" data-toggle="tooltip" title="{% trans "Free price input" %}">
                                    </span>
                                {% endif %}
                                {{ i.default_price|money:request.event.currency }}
                                {% if i.original_price %}<strike class="text-muted">{{ i.original_price|money:request.event.currency }}</strike>{% endif %}
                                {% if i.tax_rule %}
                                    <br/>
                                    <small class="text-muted">
                                        {% if not i.tax_rule.price_includes_tax %}
                                            {% blocktrans trimmed with rate=i.tax_rule.rate|floatformat:-2 taxname=i.tax_rule.name %}
                                                <strong>plus</strong> {{ rate }}% {{ taxname }}
                                            {% endblocktrans %}
                                        {% else %}
                                            {% blocktrans trimmed with rate=i.tax_rule.rate|floatformat:-2 taxname=i.tax_rule.name|default:s_taxes %}
                                                incl. {{ rate }}% {{ taxname }}
                                            {% endblocktrans %}
                                        {% endif %}
                                    </small>
                                {% endif %}
                            </td>
                            <td class="text-right flip col-actions">
                                {% if 'event.items:write' in request.eventpermset %}
                                    <button title="{% trans "Move up" %}" 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 title="{% trans "Move down" %}" 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" title="{% trans "Click and drag this button to reorder. Double click to show buttons for reordering." %}"></span>
                                    <a href="{% url "control:event.item" organizer=request.event.organizer.slug event=request.event.slug item=i.id %}" class="btn btn-default btn-sm" title="{% trans "Edit" %}"><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" title="{% trans "Delete" %}"><i class="fa fa-trash"></i></a>
                                {% endif %}
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                {% endfor %}
            </table>
        </div>
        </form>
        {% include "pretixcontrol/pagination.html" %}
    {% endif %}
{% endblock %}
