{% extends "pretixcontrol/event/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load staticfiles %}
{% block title %}{% trans "pretixdroid configuration" %}{% endblock %}
{% block content %}
    <h1>{% trans "pretixdroid configuration" %}</h1>
    <p>{% blocktrans trimmed %}
        pretixdroid is an Android app that you can use to control tickets at the entrance of your event.
    {% endblocktrans %}</p>

    {% if not configs or "create" in request.GET %}
        <h2>{% trans "Create app configuration" %}</h2>
        <p>
            {% blocktrans trimmed %}
                To start scanning tickets with our Android app, first create a configuration code here:
            {% endblocktrans %}
        </p>
        <form action="?add" method="post" class="form-horizontal">
            {% csrf_token %}
            {% bootstrap_form_errors add_form %}
            {% bootstrap_field add_form.list layout="horizontal" %}
            {% bootstrap_field add_form.all_items layout="horizontal" %}
            {% bootstrap_field add_form.items layout="horizontal" %}
            {% bootstrap_field add_form.show_info layout="horizontal" %}
            {% bootstrap_field add_form.allow_search layout="horizontal" %}
            <div class="form-group">
                <div class="col-md-offset-3 col-md-9">
                    <button type="submit" class="btn btn-primary btn-save" name="add" value="1">
                        {% trans "Create configuration" %}
                    </button>
                </div>
            </div>
        </form>
    {% endif %}


    {% if configs and "create" not in request.GET %}
        <h2>{% trans "Existing app configurations" %}</h2>
        <a href="?create=1" class="btn btn-default">
            {% trans "Create a new configuration" %}
        </a>
        <form action="?" method="post" class="form-horizontal">
            {% csrf_token %}
            <table class="table">
                <thead>
                <tr>
                    <th>{% trans "ID" %}</th>
                    <th>{% trans "Check-in list" %}</th>
                    <th>{% trans "Items" %}</th>
                    <th>{% trans "Show info" %}</th>
                    <th>{% trans "Allow search" %}</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                {% for ac in configs %}
                    <tr>
                        <td>{{ ac.key|slice:"0:8" }}…</td>
                        <td>
                            <a href="{% url "control:event.orders.checkinlists.show" organizer=request.event.organizer.slug event=request.event.slug list=ac.list.id %}">{{ ac.list }}</a>
                        </td>
                        <td>
                            {% if ac.all_items %}
                                {% trans "All" %}
                            {% else %}
                                {% for item in ac.items.all %}
                                    <a href="{% url "control:event.item" organizer=request.event.organizer.slug event=request.event.slug item=item.id %}">{{ item.name }}</a>
                                    {% if forloop.revcounter0 > 0 %}<br>{% endif %}
                                {% endfor %}
                            {% endif %}
                        </td>
                        <td>{% if ac.show_info %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}</td>
                        <td>{% if ac.allow_search %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}</td>
                        <td class="text-right">
                            <a href="{% url "plugins:pretixdroid:config.code" organizer=request.event.organizer.slug event=request.event.slug config=ac.pk %}" class="btn btn-default">
                                <span class="fa fa-qrcode"></span> {% trans "Show QR code" %}
                            </a>
                            <button class="btn btn-danger" name="delete" value="{{ ac.pk }}">
                                <span class="fa fa-trash"></span>
                            </button>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </form>
    {% endif %}
{% endblock %}

