{% extends "Global/layout.html.twig" %}

{% set pagetitle = 'Attendees Check In'|trans %}

{% block title %}{{pagetitle}}{% endblock %}

{% block content %}

    {% set navigation = [{ "dashboard_index": ('Event list' | trans),"current":(pagetitle) }] %}
    {% include "Global/navigation.html.twig" with navigation %}

    <section class="section-content padding-y bg-white">
        <div class="{{ services.getSetting("app_layout") }}">
            <div class="row">
                <aside class="col-lg-3 pt-3 pt-lg-0">
                    {% include "Dashboard/sidebar.html.twig" %}
                </aside>
                <div class="col-lg-9 mt-4 mt-lg-0">

                    <div class="row mb-4">
                        <div class="col-12 col-lg-8">
                            <div class="box bg-gray h-100">
                                {% include "Global/event-preview-horizontal.html.twig" with { eventdate: eventDate, hideorganizer: true } %}
                            </div>
                        </div>
                        <div class="col-12 col-lg-4 p-1">
                            <p class="text-center mt-2"><small class="text-muted">{{ "Total attendees check-in"|trans }}</small></p>
                            <div class="mx-auto chart-circle chart-circle" data-value="{{ eventDate.getScannedTicketsCount / eventDate.getOrderElementsQuantitySum }}">
                                <div class="chart-circle-value">{{ eventDate.getTotalCheckInPercentage }}%</div>
                            </div>
                            <p class="text-center"><small class="text-muted font-weight-bold">{{ eventDate.getScannedTicketsCount }} / {{ eventDate.getOrderElementsQuantitySum }}</small></p>
                        </div>
                    </div>

                    <div class="box shadow-none bg-gray mb-4">
                        <div class="row">
                            <div class="col-sm-12 col-lg-6 text-center text-lg-left mb-3 mb-lg-0">
                                <span class="center-lg-y text-muted">{{ "%resultsCount% attendee(s) found"|trans({'%resultsCount%': tickets.getTotalItemCount}) }}</span>
                            </div>
                            <div class="col-sm-12 col-lg-6 text-center text-lg-right">
                                <label for="sortable-select" class="display-inline">{{ "Sort by"|trans }}
                                    <select id="sortable-select" class="form-control display-inline-block bg-white select2 ml-3" data-placeholder="{{ "Select an option"|trans }}" style="width: 50%;">
                                        {{ knp_pagination_sortable(tickets, "Order date"|trans ~ ' (' ~ "desc"|trans ~ ')', "t.createdAt", {"direction": "desc", "criteria": "t.createdAt"}) }}
                                        {{ knp_pagination_sortable(tickets, "Order date"|trans ~ ' (' ~ "asc"|trans ~ ')', "t.createdAt", {"direction": "asc", "criteria": "t.createdAt"}) }}
                                    </select>
                                </label>
                            </div>
                        </div>
                        <form class="mt-3">
                            <div class="row">
                                <div class="col-sm-12 col-lg-6 mb-3">
                                    <label for="keyword">{{ "Attendee name or email, ticket reference, order reference"|trans }}</label>
                                    <input id="keyword" name="keyword" type="text" class="form-control bg-white" value="{{ app.request.get('keyword') }}">
                                </div>
                                <div class="col-sm-12 col-lg-3 mb-3">
                                    <div class="custom-control custom-checkbox">
                                        <input id="checkedin-all" type="radio" name="checkedin" value="all" class="custom-control-input">
                                        <label for="checkedin-all" class="custom-control-label">{{ "All"|trans }}</label>
                                    </div>
                                    <div class="custom-control custom-checkbox">
                                        <input id="checkedin-yes" type="radio" name="checkedin" value="1" class="custom-control-input">
                                        <label for="checkedin-yes" class="custom-control-label">{{ "Checked In Only"|trans }}</label>
                                    </div>
                                    <div class="custom-control custom-checkbox">
                                        <input id="checkedin-no" type="radio" name="checkedin" value="0" class="custom-control-input">
                                        <label for="checkedin-no" class="custom-control-label">{{ "Not Checked In Only"|trans }}</label>
                                    </div>
                                </div>
                                <div class="col-sm-12 col-lg-3 mb-3">
                                    <button type="submit" class="btn btn-primary" data-toggle="tooltip" title="{{ "Search"|trans }}"><i class="fas fa-search"></i></button>
                                    <button type="reset" class="btn btn-primary" data-toggle="tooltip" title="{{ "Reset"|trans }}"><i class="fas fa-search-minus"></i></button>
                                </div>
                            </div>
                        </form>
                    </div>

                    {% if tickets.getTotalItemCount > 0 %}

                        <div class="row">

                            <div class="col-12">
                                <div class="card">
                                    <div class="table-responsive">
                                        <table class="table table-hover table-vcenter text-nowrap">
                                            <thead>
                                                <tr>
                                                    <th class="text-center">#</th>
                                                    <th>{{'Attendee Name / Email'|trans}}</th>
                                                    <th>{{'Ticket type'|trans}}</th>
                                                    <th>{{'Status' | trans}}</th>
                                                </tr>
                                            </thead>
                                            <tbody>

                                                {% for ticket in tickets %}

                                                    <tr>
                                                        <td class="text-center">
                                                            {{ ticket.reference }}
                                                            <br>
                                                            <span class="text-sm text-muted">
                                                                {{ "Order"|trans }}# {{ ticket.orderelement.order.reference }}
                                                            </span>
                                                        </td>
                                                        <td>
                                                            {{ ticket.orderelement.order.payment.firstname ~ " " ~ ticket.orderelement.order.payment.lastname }}
                                                            <br>
                                                            <span class="text-sm text-muted">
                                                                {{ ticket.orderelement.order.payment.clientEmail }}
                                                            </span>
                                                        </td>
                                                        <td>
                                                            {{ ticket.orderelement.eventticket.name }}
                                                            <br>
                                                            <span class="text-sm text-muted">
                                                                {{ "Bought on"|trans }} {{ ticket.createdAt|localizeddate('none', 'none', app.request.locale, date_timezone, date_format) }}
                                                            </span>
                                                        </td>
                                                        <td>
                                                            {% if ticket.scanned %}
                                                                <span class="badge badge-success" data-toggle="tooltip" title="{{ "Checked In At"|trans ~ " " ~ ticket.updatedAt|localizeddate('none', 'none', app.request.locale, date_timezone, date_format) }}"><i class="fas fa-check"></i> {{ "checked In"|trans }}</span>
                                                            {% else %}
                                                                <a href="{{ path('dashboard_scanner_ticket_check_in', {eventDateReference: eventDate.reference, ticketReference: ticket.reference}) }}" class="">{{ "Check In"|trans }}</a>
                                                            {% endif %}
                                                        </td>
                                                    </tr>

                                                {% endfor %}
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                {{ knp_pagination_render(tickets, null, {}, {'align': 'center'}) }}
                            </div>

                        </div>

                    {% else %}

                        {% include "Global/message.html.twig" with { type: "info", message: ('No attendees found'|trans), icon: "fas fa-exclamation-circle" } %}

                    {% endif %}
                </div>
            </div>

        </div>
    </section>

{% endblock %}

{% block javascripts %}

    <script>

        $(document).ready(function () {

            if (getURLParameter('checkedin') != "null") {
                $('input[type="radio"][name="checkedin"][value="' + getURLParameter('checkedin') + '"]').attr("checked", "checked");
            }

        });

    </script>

{% endblock %}