
<div {{ attributes.defaults({'data-controller': 'ferienpass--cms-anon-participants ferienpass--cms-application-form'})|raw }}>

    {% if showConsentGate %}

        {% include '@Contao/components/application_form/_gate.html.twig' %}

    {% else %}

        <div class="space-y-6 py-4 sm:py-6">

            {% set future_task = futureApplicationSystemTask %}

            {% if offer.dates|length and offer.isPast %}
                {% include '@Contao/components/application_form/_applications_past.html.twig' with { offer: offer } only %}
            {% elseif not offer.isOnlineApplication %}
                {% include '@Contao/components/application_form/_applications_open.html.twig' with { offer: offer } only %}
            {% elseif offer.applicationDeadline and offer.applicationDeadline < date() %}
                {% include '@Contao/components/application_form/_applications_closed.html.twig' with { offer: offer } only %}
            {% elseif applicationSystem is null and future_task %}
                {% include '@Contao/components/application_form/_applications_soon.html.twig' with { offer: offer, opens_at: future_task.periodBegin } only %}
            {% elseif applicationSystem is null %}
                {% include '@Contao/components/application_form/_applications_disabled.html.twig' with { offer: offer } only %}
            {% elseif not isRegistered and firstComeAvailability != 'open' %}
                {% include '@Contao/components/application_form/_applications_waitlist_full.html.twig' with {
                    offer: offer,
                    key: firstComeAvailability,
                } only %}
            {% elseif confirm is not null and confirm.message == 'applicationForm.confirm.applied' %}

                {# fresh application accepted — success screen instead of the form #}
                {% include '@Contao/components/application_form/_success.html.twig' %}

            {% else %}

                {# availability / chance banner #}
                {% include '@Contao/components/application_form/_spots_banner.html.twig' with {
                    offer: offer,
                    applicationSystem: applicationSystem,
                    vacant: vacant,
                    firstComeAvailability: firstComeAvailability,
                } only %}

                {# anonymous visitors: sign in or apply without an account #}
                {% if not app.user and participants is empty %}
                    {% include '@Contao/components/application_form/_anonymous.html.twig' %}
                {% endif %}

                {# a fee-based offer needs an account to apply #}
                {% if participants is not empty and not app.user and offer.fee > 0 and (applicationSystem.task and applicationSystem.task.allowAnonymous and not applicationSystem.task.allowAnonymousFee) %}
                    <twig:Cms:Alert type="warning"
                                    message="{{ 'applicationForm.feeRequiresAccount'|trans({}, 'cms') }}"/>

                    <twig:Cms:Button variant="primary"
                                     href="{{ path('cms', { to: 'offer_list', edition: offer.edition, auto_item: offer_auto_item(offer), login: '1' }) }}#registrieren"
                                     class="w-full">
                        {{ 'applicationForm.createAccountLater'|trans({}, 'cms') }}
                    </twig:Cms:Button>
                {% endif %}

                {# how the allocation works #}
                {% if app.user and participants is not empty %}
                    <div class="flex gap-2">
                        <twig:ux:icon name="lucide:chevron-right" class="block size-5 flex-none text-gray-400" />
                        <p class="flex-1 text-sm text-gray-500 dark:text-gray-300">{{ ('application.procedure.' ~ applicationSystem.type)|trans }}</p>
                    </div>
                {% endif %}

                {# postal address required before applying #}
                {% if app.user and mustAddPostalAddress %}
                    <p class="text-base font-bold text-orange-700 dark:text-orange-400">{{ 'applicationForm.mustAddAddress'|trans({}, 'cms') }}</p>

                    <twig:Cms:Button variant="primary"
                                     href="{{ path('cms', { to: 'user_account' }) }}"
                                     class="mt-5">
                        {{ 'applicationForm.enterBillingAddress'|trans({}, 'cms') }}
                    </twig:Cms:Button>
                {% endif %}

                {# no participants yet #}
                {% if app.user and not mustAddPostalAddress and participants is empty %}
                    <div class="text-center">
                        <twig:ux:icon name="lucide:user-plus" class="mx-auto block size-10 text-gray-400" />
                        <h3 class="mt-2 text-sm font-medium text-gray-900 dark:text-gray-100">{{ 'applicationForm.noParticipants.title'|trans({}, 'cms') }}</h3>
                        <p class="mt-1 text-sm text-gray-500 dark:text-gray-300">{{ 'applicationForm.noParticipants.text'|trans({}, 'cms') }}</p>
                        <div class="mt-6">
                            <twig:Cms:Button variant="primary"
                                             href="{{ path('cms', { to: 'user_account', alias: 'account' }) }}"
                                             class="gap-2">
                                <twig:ux:icon name="lucide:plus" class="-ml-1 size-5" />
                                {{ 'applicationForm.noParticipants.new'|trans({}, 'cms') }}
                            </twig:Cms:Button>
                        </div>
                    </div>
                {% endif %}

                {% if confirm is not null %}
                    <twig:Cms:Alert type="confirm" message="{{ confirm }}"/>
                {% endif %}

                {# participant picker + the application form unfolding below it #}
                {% if (not app.user or not mustAddPostalAddress) and participants is not empty and (app.user or (not applicationSystem.task or not offer.fee or applicationSystem.task.allowAnonymousFee)) %}
                    {% include '@Contao/components/application_form/_participants_picker.html.twig' %}
                {% endif %}

                {# logged-in members add a participant inline #}
                {% if hasNewParticipant and app.user %}
                    {% include '@Contao/components/application_form/_new_participant.html.twig' %}
                {% endif %}

            {% endif %}
        </div>

    {% endif %}

</div>
