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

{% block list %}

    {# Status as a calm icon + label (not a badge): a green check when signed, a
       muted grey ✗ for an active "no" decision, a red ✗ when a previously given
       consent was revoked. Reused for the table's status column and the card
       view's aside. #}
    {% set status_badge = '
{% if item.revoked %}
    <span class="inline-flex items-center gap-x-1.5 align-middle">{{ ux_icon("ph:x", { class: "size-4 flex-none text-red-600" }) }}<span class="font-medium text-gray-700 dark:text-gray-200">{{ "consents.status.revoked"|trans({}, "admin") }}</span></span>
{% elseif item.decision != 1 %}
    <span class="inline-flex items-center gap-x-1.5 align-middle">{{ ux_icon("ph:x", { class: "size-4 flex-none text-gray-400" }) }}<span class="font-medium text-gray-700 dark:text-gray-200">{{ "consents.status.disagreed"|trans({}, "admin") }}</span></span>
{% else %}
    <span class="inline-flex items-center gap-x-1.5 align-middle">{{ ux_icon("ph:check", { class: "size-4 flex-none text-green-600" }) }}<span class="font-medium text-gray-700 dark:text-gray-200">{{ "consents.status.agreed"|trans({}, "admin") }}</span></span>
{% endif %}
' %}

    {# The consent form title, falling back to the generic type label
       ("Einwilligung" / "Einverständniserklärung") for form-less records. #}
    {% set consent_title = '{{ item.consentForm.title|default(("consent." ~ item.type)|trans({}, "admin")) }}' %}

    {% set compulsory_column = '{% if item.consentForm|default and item.consentForm.compulsory %}<span class="text-gray-700 dark:text-gray-300">{{ ("consentForm.compulsory." ~ item.consentForm.compulsory)|trans({}, "admin") }}</span>{% endif %}' %}

    {# "Aktualisiert": the most recent meaningful timestamp — revocation wins,
       else the signature, else the record's creation. #}
    {% set updated_column = '{% set d = item.revokedAt ?? item.signedAt ?? item.createdAt %}{% if d %}<span class="text-gray-700 dark:text-gray-300" title="{{ d|date("d.m.Y H:i") }}">{{ d|date("d.m.Y") }}</span>{% endif %}' %}

    {% set columns = {
        subject: '{% include "@FerienpassAdmin/page/consents/_subject.html.twig" %}',
        consent: consent_title,
        scope: '{% include "@FerienpassAdmin/page/consents/_scope.html.twig" %}',
        compulsory: compulsory_column,
        status: status_badge,
        date: updated_column,
    } %}

    {% 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: (headline == "#{translationPrefix}.#{action}.title") ? "#{translationPrefix}.title"|trans : headline,
        createUrl: createUrl|default(null),
        viewKey: 'admin_consents',
        viewPathPrefix: '/admin/einwilligungen',
        exports: exports|default([]),
        config: {
            squeezedColumns: ['scope', 'compulsory', 'date'],
            title: '{{ item.participant.name|default(item.user.name|default(item.signedBy|default("Unbekannt"))) }}',
            info: [
                consent_title,
                '{% set cf = item.consentForm|default(null) %}{{ cf and cf.offer ? cf.offer.name : (cf and cf.edition ? cf.edition.name : "consents.scope.general"|trans({}, "admin")) }}',
                compulsory_column,
                updated_column,
            ],
            aside: status_badge,
            columns: columns,
        }
    } %}{% endcomponent %}
{% endblock %}
