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

{% block list %}
    {{ component('Admin:SearchableQueryableList', {
        qb: qb,
        searchable: searchable|default([]),
        paginate: false,
        routeName: app.current_route,
        routeParameters: app.current_route_parameters|merge(app.request.query.all),
        headline: (headline == "#{translationPrefix}.#{action}.title") ? "#{translationPrefix}.title"|trans : headline,
        createUrl: createUrl|default(null),
        exports: exports|default([]),
        config: {
            groupBy: '{% set status = item.statusGroup|default(null) %}{% if status == "unconfirmed" %}Unbestätigt{% else %}Geduldet{% endif %}',
            title: '
                {% set p1 = item.participant1 %}{% set p2 = item.participant2 %}
                {% set dobColor = item.hasDobMatch ? "text-teal-600 dark:text-teal-400" : "text-yellow-600 dark:text-yellow-400" %}
                {% set userColor = item.hasUserMatch ? "text-teal-600 dark:text-teal-400" : "text-yellow-600 dark:text-yellow-400" %}
                <span>{{ p1.name }} (<span class="{{ dobColor }}">{{ p1.dateOfBirth ? p1.dateOfBirth|date("d.m.Y") : "-" }}</span>, <span class="{{ userColor }}">{{ p1.userName ?: "kein User" }}</span></span>
                <br>
                <span>{{ p2.name }} (<span class="{{ dobColor }}">{{ p2.dateOfBirth ? p2.dateOfBirth|date("d.m.Y") : "-" }}</span>, <span class="{{ userColor }}">{{ p2.userName ?: "kein User" }}</span></span>',
            info: [
                '{{ item.participant1.email }} / {{ item.participant2.email }}',
            ],
            aside: null,
            columns: {
                participant1: '
<div class="flex flex-col">
    <a href="{{ path("admin_participants_show", { uuid: item.participant1.uuid.toBase58 }) }}" data-turbo-frame="slideover" class="font-medium 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 transition-colors text-gray-900 dark:text-gray-100">{{ item.participant1.name }}</a>
    <span class="text-xs text-gray-500">{{ item.participant1.email }}</span>
    <span class="text-xs {{ item.hasDobMatch ? "text-teal-600 dark:text-teal-400" : "text-yellow-600 dark:text-yellow-400" }}">{{ item.participant1.dateOfBirth ? item.participant1.dateOfBirth|date("d.m.Y") : "-" }}</span>
    <span class="text-xs {{ item.hasUserMatch ? "text-teal-600 dark:text-teal-400" : "text-yellow-600 dark:text-yellow-400" }}">{{ item.participant1.userName ?: "kein User" }}</span>
    <span class="text-xs text-gray-400">{{ item.participant1.attendanceCount }} Anm.</span>
</div>',
                participant2: '
<div class="flex flex-col">
    <a href="{{ path("admin_participants_show", { uuid: item.participant2.uuid.toBase58 }) }}" data-turbo-frame="slideover" class="font-medium 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 transition-colors text-gray-900 dark:text-gray-100">{{ item.participant2.name }}</a>
    <span class="text-xs text-gray-500">{{ item.participant2.email }}</span>
    <span class="text-xs {{ item.hasDobMatch ? "text-teal-600 dark:text-teal-400" : "text-yellow-600 dark:text-yellow-400" }}">{{ item.participant2.dateOfBirth ? item.participant2.dateOfBirth|date("d.m.Y") : "-" }}</span>
    <span class="text-xs {{ item.hasUserMatch ? "text-teal-600 dark:text-teal-400" : "text-yellow-600 dark:text-yellow-400" }}">{{ item.participant2.userName ?: "kein User" }}</span>
    <span class="text-xs text-gray-400">{{ item.participant2.attendanceCount }} Anm.</span>
</div>'
            }
        }
    }) }}
{% endblock %}

{% block ignore_success_stream %}
    <twig:Turbo:Stream:Update target="#modal"/>
    <twig:Turbo:Stream:Remove target="#tr-{{ p1_id }}-{{ p2_id }}"/>
    <twig:Turbo:Stream:Prepend target="#notifications">
        <twig:Admin:Notification type="success" title="Duplikat wurde ignoriert" message="Die beiden Datensätze existieren weiter unabhängig voneinander."/>
    </twig:Turbo:Stream:Prepend>
{% endblock %}

{% block tolerate_success_stream %}
    <twig:Turbo:Stream:Update target="#modal"/>
    <twig:Turbo:Stream:Remove target="#tr-{{ p1_id }}-{{ p2_id }}"/>
    <twig:Turbo:Stream:Prepend target="#notifications">
        <twig:Admin:Notification type="success" title="Duplikat wird geduldet" message="Die beiden Datensätze existieren weiter, Anmeldungen werden im Admin-Panel jedoch zusammengeführt. Für die Eltern ändert sich nichts."/>
    </twig:Turbo:Stream:Prepend>
{% endblock %}

{% block merge_success_stream %}
    <twig:Turbo:Stream:Update target="#modal"/>
    <twig:Turbo:Stream:Remove target="#tr-{{ p1_id }}-{{ p2_id }}"/>
    <twig:Turbo:Stream:Prepend target="#notifications">
        <twig:Admin:Notification type="success" title="Duplikate zusammengeführt" message="Die Duplikate wurden zusammengeführt, in dem ein Datensatz gelöscht wurde."/>
    </twig:Turbo:Stream:Prepend>
{% endblock %}
