{% if event.type == 'conference' %}
    {% extends 'events/registration/display/_event_registration_base.html' %}
{% else %}
    {% extends 'events/registration/display/_meeting_registration_base.html' %}
{% endif %}

{% from 'message_box.html' import message_box %}

{% block subtitle %}
    {% trans %}Available forms{% endtrans %}
{% endblock %}

{% block description %}
    {% if description %}
        {{ description | markdown }}
    {% endif %}
{% endblock %}

{% block content %}
    {% set any_published_registrations = regforms|selectattr('publish_registration_count')|any %}
    {% if is_restricted_access %}
        {% call message_box('warning') %}
            {% trans -%}
                Access to the rest of this event is restricted to registered participants.
            {%- endtrans %}
        {% endcall %}
    {% endif %}
    <table id="regforms-list" class="i-table-widget">
        <thead>
            <tr>
                <th></th>
                <th>{% trans %}Opens{% endtrans %}</th>
                <th>{% trans %}Closes{% endtrans %}</th>
                {% if any_published_registrations %}
                    <th></th>
                {% endif %}
                <th></th>
            </tr>
        </thead>
        <tbody>
            {% for regform in regforms %}
                {% set button_text -%}
                    {% if regform.moderation_enabled %}
                        {# i18n: Apply for participation (analogous to 'Register' but 'Apply' is used when the registration form is moderated) #}
                        {%- trans 'Registration' %}Apply{% endtrans %}
                    {%- else %}
                        {%- trans %}Register{% endtrans %}
                    {%- endif %}
                {%- endset -%}
                <tr>
                    <td>
                        {% if event.can_manage(session.user, 'registration') %}
                            <a href="{{ url_for('.manage_regform', regform) }}">{{ regform.title }}</a>
                        {% else %}
                            {{ regform.title }}
                        {% endif %}
                    </td>
                    <td>{{ regform.start_dt | format_datetime(timezone=event.display_tzinfo) if regform.start_dt else _('Not started') }}</td>
                    <td>{{ regform.end_dt | format_datetime(timezone=event.display_tzinfo) if regform.end_dt else _('No deadline') }}</td>
                    {% if any_published_registrations %}
                        {% if regform.publish_registration_count %}
                            <td class="icon-user">
                                {{- regform.active_registration_count -}}
                                {%- if regform.registration_limit %}
                                    / {{ regform.registration_limit }}
                                {%- endif -%}
                            </td>
                        {% else %}
                            <td></td>
                        {% endif %}
                    {% endif %}
                    <td class="regform-actions">
                        {% if user_registrations[regform] %}
                            <a href="{{ url_for('.display_regform', regform) }}"
                               class="i-button highlight"
                               title="{% trans %}You have already registered{% endtrans %}">
                                {% trans %}Check details{% endtrans %}
                            </a>
                        {% elif regform.is_purged %}
                            <a class="i-button highlight disabled"
                               title="{% trans %}Registration is disabled due to an expired retention period{% endtrans %}">
                                {{ button_text }}
                            </a>
                        {% elif not regform.is_open %}
                            <a class="i-button highlight disabled"
                               title="{% trans %}Registration is closed{% endtrans %}">
                                {{ button_text }}
                            </a>
                        {% elif regform.limit_reached %}
                            <a class="i-button highlight disabled"
                               title="{% trans %}The maximum number of registrations has been reached{% endtrans %}">
                                {{ button_text }}
                            </a>
                        {% else %}
                            <a href="{{ url_for('.display_regform', regform) }}" class="i-button highlight">
                                {{ button_text }}
                            </a>
                        {% endif %}
                    </td>
                </tr>
            {% else %}
                <tr>
                    <td colspan="4">
                        {% trans %}No registration forms available for this event{% endtrans %}
                    </td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
    {% if event.type != 'conference' and event.can_access(session.user) %}
        <p>
            <a href="{{ event.url }}" class="i-button">
                {%- trans %}Back to the event{% endtrans -%}
            </a>
        </p>
    {% endif %}
{% endblock %}
