{# Consent management — review & withdraw, grouped by edition.

   Every consent the user ever decided on is listed with its current state.
   Expanding a row reveals the consent text, a history line and the
   consequence of a withdrawal BEFORE the user acts; the withdrawal itself
   happens inline behind a confirm sub-step (no modal).

   Required context: consentGroups (see {@see \Ferienpass\CmsBundle\Components\Consents}) #}

<div {{ attributes.defaults({'data-controller': 'ferienpass--cms-consents'})|raw }}>

    {% if consentGroups is empty %}

        <div class="rounded-lg border border-dashed border-gray-300 px-6 py-10 text-center dark:border-gray-700">
            <twig:ux:icon name="lucide:clipboard-check" class="mx-auto size-9 text-gray-400" />
            <p class="mt-3 text-sm text-gray-500 dark:text-gray-400">{{ 'userAccount.consents.empty'|trans({}, 'cms') }}</p>
        </div>

    {% else %}

        {% for group in consentGroups %}
            <section class="mb-8 last:mb-0">

                {# ── edition heading ── #}
                <div class="mb-1.5 flex items-center gap-2.5">
                    <span class="grid size-8 flex-none place-items-center rounded-lg bg-[#e5efe9] text-[#2f6f57] dark:bg-[#2f6f57]/20 dark:text-[#9cc4ae]">
                        <twig:ux:icon name="lucide:calendar" class="size-4" />
                    </span>
                    <h3 class="text-xs font-bold uppercase tracking-widest text-gray-900 dark:text-gray-100">
                        {{ group.edition ? group.edition.name|machine_translate : 'userAccount.consents.otherGroup'|trans({}, 'cms') }}
                    </h3>
                    {% set holiday = group.edition ? group.edition.holiday : null %}
                    {% if holiday and holiday.periodBegin %}
                        <span class="ml-auto whitespace-nowrap text-[11px] font-semibold text-gray-400 dark:text-gray-500">
                            {{ holiday.periodBegin|date('d.m.Y') }}{% if holiday.periodEnd %} – {{ holiday.periodEnd|date('d.m.Y') }}{% endif %}
                        </span>
                    {% endif %}
                </div>
                <p class="mb-3.5 text-[13px] text-gray-500 dark:text-gray-400 sm:ml-[42px]">
                    {{ 'userAccount.consents.editionCaption'|trans({}, 'cms') }}
                </p>

                {% for state in group.states %}
                    {% include '@Contao/components/consents/_row.html.twig' with { state: state } only %}
                {% endfor %}

            </section>
        {% endfor %}

    {% endif %}

</div>
