{% extends "@FerienpassAdmin/layout/list.html.twig" %}

{% block list %}
{% component 'Admin:SearchableQueryableList' with {
        qb: qb,
        filterType: filterType,
        routeName: app.current_route,
        routeParameters: app.current_route_parameters|merge(app.request.query.all),
        searchable: searchable|default([]),
        headline: '',
        createUrl: createUrl|default(null),
        viewKey: 'admin_participants',
        viewPathPrefix: '/admin/teilnehmende',
        exports: exports|default([]),
        config: {
            showUrl: '{{ path("admin_participants_show", { uuid: item.uuid.toBase58 }) }}',
            squeezedColumns: [
                'dateOfBirth',
                'email',
                'mobile',
            ],
            selectedEditionAliases: selectedEditions|default([])|map(e => e.alias),
            title: '{{ item.name|default("") }}',
            info: [
                '{{ item.dateOfBirth ? item.dateOfBirth|date("d.m.Y") : "" }}',
                '{{ item.email ?: item.member.email|default("") }}',
            ],
            aside: '
{% set ed = selectedEditionAliases|default([]) %}
{% set confirmed = (ed ? item.attendancesConfirmed|filter(a => a.offer.edition.alias in ed) : item.attendancesConfirmed)|length %}
{% set confirmedNoCancel = (ed ? item.attendancesConfirmed(false)|filter(a => a.offer.edition.alias in ed) : item.attendancesConfirmed(false))|length %}
{% set notWithdrawn = (ed ? item.attendancesNotWithdrawn|filter(a => a.offer.edition.alias in ed) : item.attendancesNotWithdrawn)|length %}
{% set waitlisted = (ed ? item.attendancesWaitlisted(false)|filter(a => a.offer.edition.alias in ed) : item.attendancesWaitlisted(false))|length %}
{% set rejected = (ed ? item.attendancesRejected|filter(a => a.offer.edition.alias in ed) : item.attendancesRejected)|length %}
{% set unfulfilled = (ed ? item.attendancesUnfulfilled|filter(a => a.offer.edition.alias in ed) : item.attendancesUnfulfilled)|length %}
{% set waiting = (ed ? item.attendancesWaiting(false)|filter(a => a.offer.edition.alias in ed) : item.attendancesWaiting(false))|length %}
<div class="flex items-center space-x-2 shrink-0">
{% if confirmed %}
<span class="text-green-600 font-medium text-base">{{ confirmed }}</span>
{% else %}
<span class="text-gray-500 font-medium text-base">0</span>
{% endif %}
<div class="w-24 shrink-0 bg-gray-200 dark:bg-gray-200/50 rounded-full h-1.5 overflow-hidden flex">
{% if notWithdrawn %}
  <div class="bg-green-600 dark:bg-green-600/70 h-1.5" title="zugelassen: {{ confirmedNoCancel }}" style="width: {{ confirmedNoCancel/notWithdrawn*100 }}%"></div>
  <div class="bg-yellow-500 dark:bg-yellow-500/70 h-1.5" title="Warteliste: {{ waitlisted }}" style="width: {{ waitlisted/notWithdrawn*100 }}%"></div>
  <div class="bg-red-600 dark:bg-red-600/70 h-1.5" title="fehlerhaft: {{ rejected }}" style="width: {{ rejected/notWithdrawn*100 }}%"></div>
  <div class="bg-red-600 dark:bg-red-600/70 h-1.5" title="ohne Platz: {{ unfulfilled }}" style="width: {{ unfulfilled/notWithdrawn*100 }}%"></div>
  <div class="bg-gray-600 dark:bg-gray-100/70 h-1.5" title="wartend: {{ waiting }}" style="width: {{ waiting/notWithdrawn*100 }}%"></div>
{% endif %}
</div>
<span class="text-gray-500 font-medium text-base">{{ notWithdrawn }}</span>
</div>
',
            columns: {
                name: '<a href="{{ path("admin_participants_show", { uuid: item.uuid.toBase58 }) }}" class="hover:bg-gray-100 dark:hover:bg-gray-800 hover:text-gray-900 dark:hover:text-gray-100 rounded-md px-1.5 py-1 -mx-1.5 -my-1 font-medium text-gray-900 dark:text-gray-100 transition-colors" data-turbo-frame="slideover">{{ item.name|default("") }}</a>',
                dateOfBirth: '{{ item.dateOfBirth ? item.dateOfBirth|date("d.m.Y") : "" }}',
                email: '{{ item.email ?: item.member.email|default("-") }}',
                mobile: '{{ item.mobile ?: item.member.mobile|default("-") }}',
                attendances: '
{% set ed = selectedEditionAliases|default([]) %}
{% set confirmed = (ed ? item.attendancesConfirmed|filter(a => a.offer.edition.alias in ed) : item.attendancesConfirmed)|length %}
{% set confirmedNoCancel = (ed ? item.attendancesConfirmed(false)|filter(a => a.offer.edition.alias in ed) : item.attendancesConfirmed(false))|length %}
{% set notWithdrawn = (ed ? item.attendancesNotWithdrawn|filter(a => a.offer.edition.alias in ed) : item.attendancesNotWithdrawn)|length %}
{% set waitlisted = (ed ? item.attendancesWaitlisted(false)|filter(a => a.offer.edition.alias in ed) : item.attendancesWaitlisted(false))|length %}
{% set rejected = (ed ? item.attendancesRejected|filter(a => a.offer.edition.alias in ed) : item.attendancesRejected)|length %}
{% set unfulfilled = (ed ? item.attendancesUnfulfilled|filter(a => a.offer.edition.alias in ed) : item.attendancesUnfulfilled)|length %}
{% set waiting = (ed ? item.attendancesWaiting(false)|filter(a => a.offer.edition.alias in ed) : item.attendancesWaiting(false))|length %}
<div class="flex items-center space-x-2">
{% if confirmed %}
<span class="text-green-600 font-medium text-xs">{{ confirmed }}</span>
{% else %}
<span class="text-gray-500 font-medium text-xs">0</span>
{% endif %}
<div class="w-full bg-gray-200 dark:bg-gray-200/50 rounded-full h-1.5 overflow-hidden flex">
{% if notWithdrawn %}
  <div class="bg-green-600 dark:bg-green-600/70 h-1.5" title="zugelassen: {{ confirmedNoCancel }}" style="width: {{ confirmedNoCancel/notWithdrawn*100 }}%"></div>
  <div class="bg-yellow-500 dark:bg-yellow-500/70 h-1.5" title="Warteliste: {{ waitlisted }}" style="width: {{ waitlisted/notWithdrawn*100 }}%"></div>
  <div class="bg-red-600 dark:bg-red-600/70 h-1.5" title="fehlerhaft: {{ rejected }}" style="width: {{ rejected/notWithdrawn*100 }}%"></div>
  <div class="bg-red-600 dark:bg-red-600/70 h-1.5" title="ohne Platz: {{ unfulfilled }}" style="width: {{ unfulfilled/notWithdrawn*100 }}%"></div>
  <div class="bg-gray-600 dark:bg-gray-100/70 h-1.5" title="wartend: {{ waiting }}" style="width: {{ waiting/notWithdrawn*100 }}%"></div>
{% endif %}
</div>
<span class="text-gray-500 font-medium text-xs">{{ notWithdrawn }}</span>
</div>
',
                paid: '
{% set ed = selectedEditionAliases|default([]) %}
{% set paid = (ed ? item.attendancesPaid|filter(a => a.offer.edition.alias in ed) : item.attendancesPaid)|length %}
{% set confirmedNoCancel = (ed ? item.attendancesConfirmed(false)|filter(a => a.offer.edition.alias in ed) : item.attendancesConfirmed(false))|length %}
        <div class="flex items-center space-x-2">
{% if paid %}
<span class="text-green-600 font-medium text-xs">{{ paid }}</span>
{% else %}
<span class="text-gray-500 font-medium text-xs">0</span>
{% endif %}
<div class="w-full bg-gray-200 dark:bg-gray-200/50 rounded-full h-1.5 overflow-hidden flex">
{% if confirmedNoCancel %}
  <div class="bg-green-600 dark:bg-green-600/70 h-1.5" title="bezahlt: {{ paid }}" style="width: {{ (paid/confirmedNoCancel)*100 }}%"></div>
{% endif %}
</div>
<span class="{{ confirmedNoCancel > 0 and confirmedNoCancel == paid ? "text-green-600" : "text-gray-500" }} font-medium text-xs">{{ confirmedNoCancel }}</span>
</div>
'
            }
        }
    } %}
        {% block page_header %}
            <div class="flex items-center justify-between gap-4 flex-wrap py-5 border-b border-gray-200 dark:border-gray-800 mb-2">
                <twig:Admin:EditionSwitcher
                        :editions="editions|default([])"
                        :selected="selectedEditions|default([])"
                        baseLabel="Teilnehmende"
                        unscopedRoute="admin_participants_index"
                        scopedRoute="admin_participants_index" />

                {% if createUrl|default(null) %}
                    <twig:Admin:Button href="{{ createUrl }}" variant="primary">Neu erstellen</twig:Admin:Button>
                {% endif %}
            </div>
        {% endblock %}
    {% endcomponent %}

{% endblock %}
