{% extends "pretixcontrol/event/base.html" %}
{% load i18n %}
{% load eventurl %}
{% load urlreplace %}
{% load bootstrap3 %}
{% block title %}
    {% blocktrans with name=checkinlist.name %}Check-in list: {{ name }}{% endblocktrans %}
{% endblock %}
{% block content %}
    <h1>
        {% blocktrans with name=checkinlist.name %}Check-in list: {{ name }}{% endblocktrans %}
        {% if 'can_change_event_settings' in request.eventpermset %}
            <a href="{% url "control:event.orders.checkinlists.edit" event=request.event.slug organizer=request.event.organizer.slug list=checkinlist.pk %}"
                    class="btn btn-default">
                <span class="fa fa-edit"></span>
                {% trans "Edit list" %}
            </a>
        {% endif %}
        <a href="{% url "control:event.orders.export" event=request.event.slug organizer=request.event.organizer.slug %}?identifier=checkinlistpdf&checkinlistpdf-list={{ checkinlist.pk }}"
                class="btn btn-default" target="_blank">
            <span class="fa fa-download"></span>
            {% trans "PDF" %}
        </a>
        <a href="{% url "control:event.orders.export" event=request.event.slug organizer=request.event.organizer.slug %}?identifier=checkinlistcsv&checkinlistcsv-list={{ checkinlist.pk }}"
                class="btn btn-default" target="_blank">
            <span class="fa fa-download"></span>
            {% trans "CSV" %}
        </a>
    </h1>
    <form class="row filter-form" action="" method="get">
        <div class="col-md-4 col-sm-6 col-xs-12">
            {% bootstrap_field filter_form.user layout='inline' %}
        </div>
        <div class="col-md-3 col-sm-6 col-xs-12">
            {% bootstrap_field filter_form.status layout='inline' %}
        </div>
        <div class="col-md-3 col-sm-6 col-xs-12">
            {% bootstrap_field filter_form.item layout='inline' %}
        </div>
        <div class="col-md-2 col-sm-6 col-xs-12">
            <button class="btn btn-primary btn-block" type="submit">
                <span class="fa fa-filter"></span>
                <span class="hidden-md">
                    {% trans "Filter" %}
                </span>
            </button>
        </div>
    </form>
    {% if entries|length == 0 %}
        <div class="empty-collection">
            <p>
                {% blocktrans trimmed %}
                    No attendee record was found.
                {% endblocktrans %}
            </p>
        </div>
    {% else %}
        <form method="post" action="">
           {% csrf_token %}
            <div class="table-responsive">
                <table class="table table-condensed table-hover">
                    <thead>
                    <tr>
                        <th></th>
                        <th>{% trans "Order code" %} <a href="?{% url_replace request 'ordering' '-code'%}"><i class="fa fa-caret-down"></i></a>
                      <a href="?{% url_replace request 'ordering' 'code'%}"><i class="fa fa-caret-up"></i></a></th>
                        <th>{% trans "Item" %} <a href="?{% url_replace request 'ordering' '-item'%}"><i class="fa fa-caret-down"></i></a>
                      <a href="?{% url_replace request 'ordering' 'item'%}"><i class="fa fa-caret-up"></i></a></th>
                        <th>{% trans "Email" %} <a href="?{% url_replace request 'ordering' '-email'%}"><i class="fa fa-caret-down"></i></a>
                      <a href="?{% url_replace request 'ordering' 'email'%}"><i class="fa fa-caret-up"></i></a></th>
                        <th>{% trans "Name" %} <a href="?{% url_replace request 'ordering' '-name'%}"><i class="fa fa-caret-down"></i></a>
                      <a href="?{% url_replace request 'ordering' 'name'%}"><i class="fa fa-caret-up"></i></a></th>
                        <th>{% trans "Status" %} <a href="?{% url_replace request 'ordering' '-status'%}"><i class="fa fa-caret-down"></i></a>
                      <a href="?{% url_replace request 'ordering' 'status'%}"><i class="fa fa-caret-up"></i></a></th>
                        <th>{% trans "Timestamp" %} <a href="?{% url_replace request 'ordering' '-timestamp'%}"><i class="fa fa-caret-down"></i></a>
                      <a href="?{% url_replace request 'ordering' 'timestamp'%}"><i class="fa fa-caret-up"></i></a></th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for e in entries %}
                        <tr>
                            <td>
                                {% if "can_change_orders" in request.eventpermset %}
                                    <input type="checkbox" name="checkin" id="id_checkin" class="" value="{{ e.pk }}"/>
                                {% endif %}
                            </td>
                            <td>
                                <strong><a href="{% url "control:event.order" event=request.event.slug organizer=request.event.organizer.slug code=e.order.code %}">{{ e.order.code }}</a></strong>
                            </td>
                            <td>{{ e.item.name }}{% if e.variation %} – {{ e.variation }}{% endif %}</td>
                            <td>{{ e.order.email }}</td>
                            <td>
                                {% if e.addon_to %}
                                    {{ e.addon_to.attendee_name }}
                                {% elif e.attendee_name %}
                                    {{ e.attendee_name }}
                                {% endif %}
                            </td>
                            <td>
                                {% if not e.last_checked_in %}
                                    <span class="label label-danger">{% trans "Not checked in" %}</span>
                                {% else %}
                                    <span class="label label-success">{% trans "Checked in" %}</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if e.last_checked_in %}
                                    {{ e.last_checked_in_aware|date:"SHORT_DATETIME_FORMAT" }}
                                {% endif %}
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
            {% if "can_change_orders" in request.eventpermset %}
                <button type="submit" class="btn btn-primary btn-save">
                    {% trans "Check-In selected attendees" %}
                </button>
            {% endif %}
        </form>
        {% include "pretixcontrol/pagination.html" %}
    {% endif %}
{% endblock %}
