{% extends "pretixcontrol/event/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load static %}
{% block title %}{% trans "Check-in device configuration" %}{% endblock %}
{% block content %}
    <h1>{% trans "Check-in device configuration" %}</h1>

    {% if not configs or "create" in request.GET %}
        <div class="alert alert-info pretixscan-migration">
            <h2 class="mar">{% trans "We've got a new app!" %}</h2>
            <p>
                {% blocktrans trimmed %}
                    We've retired pretixdesk and pretixdroid in favor of our new app pretixSCAN that works on all major
                    platforms, allows convenient switching between events, has better performance when dealing with large
                    events and supports printing badges. We suggest that you switch to pretixSCAN for your events, but you
                    can continue using pretixdesk for at least all of 2019, if you like.
                {% endblocktrans %}
            </p>
            <div class="row">
                <div class="col-md-6 col-sm-12 text-center">
                    <h3>{% trans "Our new app: pretixSCAN" %}</h3>
                    <img src="{% static "pretixbase/img/pretixscan.svg" %}">
                    <p>{% trans "Available on Android, iOS, Windows, and Linux." %}</p>
                    <p>{% trans "Configuration is available in your organizer account's device list." %}</p>
                    <a href="{% url "control:organizer.devices" organizer=request.organizer.slug %}"
                            class="btn btn-primary btn-lg">
                        {% trans "Switch to my device list" %}
                    </a>
                </div>
                <div class="col-md-6 col-sm-12 text-center">
                    <h3>{% trans "Our old apps: pretixdesk and pretixdroid" %}</h3>
                    <img src="{% static "pretixbase/img/pretixdroid.png" %}">
                    <p>{% trans "Available on Android, Windows, and Linux." %}</p>
                    <p><strong>{% trans "Scroll down to create a configuration" %}</strong></p>
                </div>
            </div>
        </div>
    {% endif %}

    {% if not configs or "create" in request.GET %}
        <h2>{% trans "Create app configuration" %}</h2>
        <p>
            {% blocktrans trimmed %}
                To start scanning tickets with our apps, 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" %}
            {% bootstrap_field add_form.app 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>
                            {% if ac.app == "pretixdroid" %}
                                <span class="fa fa-fw fa-android"></span>
                            {% elif ac.app == "pretixdesk" %}
                                <span class="fa fa-fw fa-desktop"></span>
                            {% endif %}
                            {{ 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 "Configure device" %}
                            </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 %}

