{% extends "pretixcontrol/items/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% block title %}{% trans "Check-in history" %}{% endblock %}
{% block inside %}
    <h1>{% trans "Check-in history" %}</h1>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">{% trans "Filter" %}</h3>
        </div>
        <form class="panel-body filter-form" action="" method="get">
            <div class="row">
                <div class="col-md-3 col-sm-6 col-xs-12">
                    {% bootstrap_field filter_form.checkin_list %}
                </div>
                <div class="col-md-3 col-sm-6 col-xs-12">
                    {% bootstrap_field filter_form.status %}
                </div>
                <div class="col-md-3 col-sm-6 col-xs-12">
                    {% bootstrap_field filter_form.type %}
                </div>
                <div class="col-md-3 col-sm-6 col-xs-12">
                    {% bootstrap_field filter_form.device %}
                </div>
                <div class="col-md-3 col-sm-6 col-xs-12">
                    {% bootstrap_field filter_form.datetime_from %}
                </div>
                <div class="col-md-3 col-sm-6 col-xs-12">
                    {% bootstrap_field filter_form.datetime_until %}
                </div>
                <div class="col-md-3 col-sm-6 col-xs-12">
                    {% bootstrap_field filter_form.gate %}
                </div>
                <div class="col-md-3 col-sm-6 col-xs-12">
                    {% bootstrap_field filter_form.itemvar %}
                </div>
            </div>
            <div class="text-right">
                <button class="btn btn-primary btn-lg" type="submit">
                    <span class="fa fa-filter"></span>
                    {% trans "Filter" %}
                </button>
            </div>
        </form>
    </div>
    {% if checkins|length == 0 %}
        <div class="empty-collection">
            <p>
                {% if request.GET %}
                    {% trans "Your search did not match any check-ins." %}
                {% else %}
                    {% blocktrans trimmed %}
                        You haven't scanned any tickets yet.
                    {% endblocktrans %}
                {% endif %}
            </p>
        </div>
    {% else %}
        <span class="table-responsive">
            <table class="table table-hover table-quotas">
                <thead>
                <tr>
                    <th>{% trans "Time of scan" %}</th>
                    <th>{% trans "Scan type" %}<br>{% trans "Check-in list" %}</th>
                    <th>{% trans "Result" %}</th>
                    <th>{% trans "Ticket" %}<br>{% trans "Product" %}</th>
                    <th>{% trans "Device" %}<br>{% trans "Gate" %}</th>
                </tr>
                </thead>
                <tbody>
                {% for c in checkins %}
                    <tr>
                        <td>
                            {{ c.datetime|date:"SHORT_DATETIME_FORMAT" }}
                            {% if c.type == "exit" %}
                                {% if c.auto_checked_in %}
                                    <span class="fa fa-fw fa-hourglass-end" data-toggle="tooltip"
                                          title="{% blocktrans trimmed with date=c.datetime|date:'SHORT_DATETIME_FORMAT' %}Automatically marked not present: {{ date }}{% endblocktrans %}"></span>
                                {% endif %}
                            {% elif c.forced and c.successful %}
                                <span class="fa fa-fw fa-warning" data-toggle="tooltip"
                                      title="{% blocktrans trimmed with date=c.datetime|date:'SHORT_DATETIME_FORMAT' %}Additional entry scan: {{ date }}{% endblocktrans %}"></span>
                            {% elif c.force_sent %}
                                <span class="fa fa-fw fa-cloud-upload" data-toggle="tooltip"
                                      title="{% blocktrans trimmed with date=c.created|date:'SHORT_DATETIME_FORMAT' %}Offline scan. Upload time: {{ date }}{% endblocktrans %}"></span>
                            {% elif c.auto_checked_in %}
                                <span class="fa fa-fw fa-magic" data-toggle="tooltip"
                                      title="{% blocktrans trimmed with date=c.datetime|date:'SHORT_DATETIME_FORMAT' %}Automatically checked in: {{ date }}{% endblocktrans %}"></span>
                            {% endif %}
                            {% if c.forced and not c.successful %}
                                <br>
                                <small class="text-muted">{% trans "Failed in offline mode" %}</small>
                            {% endif %}
                        </td>
                        <td>
                            {% if c.type == "exit" %}<span class="fa fa-fw fa-sign-out"></span>{% endif %}
                            {% if c.type == "entry" %}<span class="fa fa-fw fa-sign-in"></span>{% endif %}
                            {{ c.get_type_display }}
                            <br>
                            <small>
                                <a href="{% url "control:event.orders.checkinlists.show" organizer=request.event.organizer.slug event=request.event.slug list=c.list.id %}">{{ c.list }}</a>
                            </small>
                        </td>
                        <td>
                            {% if c.successful %}
                                <span class="label label-success">
                                    <span class="fa fa-fw fa-check"></span> {% trans "Successful" context "checkin_result" %}
                                </span>
                            {% else %}
                                <span class="label label-danger">
                                    <span class="fa fa-fw fa-exclamation-triangle"></span>
                                    {% trans "Denied" context "checkin_result" %}
                                </span>
                                <br>
                                <small>
                                    {{ c.get_error_reason_display }}
                                    {% if c.error_explanation %}
                                        <br>
                                        {{ c.error_explanation }}
                                    {% endif %}
                                </small>
                            {% endif %}
                        </td>
                        <td>
                            {% if c.position %}
                                <span class="fa fa-user fa-fw"></span>
                                <strong>
                                    <a href="{% url "control:event.order" event=request.event.slug organizer=request.event.organizer.slug code=c.position.order.code %}">{{ c.position.order.code }}</a>-{{ c.position.positionid }}
                                </strong>
                                {% if c.position.attendee_name %}
                                    <br>
                                    <small>
                                        {{ c.position.attendee_name }}
                                    </small>
                                {% endif %}
                                {% if c.position.item %}
                                    <br>
                                    <small>
                                        <a href="{% url "control:event.item" organizer=request.event.organizer.slug event=request.event.slug item=c.position.item_id %}">
                                            {{ c.position.item }}{% if c.position.variation %} –
                                                {{ c.position.variation }}{% endif %}
                                        </a>
                                    </small>
                                {% endif %}
                            {% else %}
                                <span class="fa fa-qrcode fa-fw"></span>
                                <span title="{{ c.raw_barcode }}">
                                    {{ c.raw_barcode|slice:":16" }}{% if c.raw_barcode|length > 16 %}…{% endif %}
                                    <button type="button" class="btn btn-xs btn-link btn-clipboard" data-clipboard-text="{{ c.raw_barcode }}">
                                        <i class="fa fa-clipboard" aria-hidden="true"></i>
                                        <span class="sr-only">{% trans "Copy to clipboard" %}</span>
                                    </button>
                                </span>
                                {% if c.raw_item %}
                                    <br>
                                    <small>
                                        <a href="{% url "control:event.item" organizer=request.event.organizer.slug event=request.event.slug item=c.raw_item.id %}">
                                            {{ c.raw_item }}{% if c.raw_variation %} – {{ c.raw_variation }}{% endif %}
                                        </a>
                                    </small>
                                {% endif %}
                                {% if c.raw_subevent %}
                                    <br>
                                    <small>
                                        {{ c.raw_subevent }}{% if c.raw_variation %} – {{ c.raw_variation }}{% endif %}
                                    </small>
                                {% endif %}
                            {% endif %}
                        </td>
                        <td>
                            {{ c.device|default:"" }}
                            {% if c.gate %}
                                <br><small>{{ c.gate }}</small>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    {% endif %}
    {% include "pretixcontrol/pagination.html" %}
{% endblock %}
