{% extends 'events/management/full_width_base.html' %}
{% from 'events/registration/management/_reglist.html' import render_registration_list %}
{% from 'message_box.html' import message_box %}

{% block back_button_url -%}
    {{ url_for('.manage_regform', regform) }}
{%- endblock %}

{% block title %}
    {%- trans %}Registration{% endtrans -%}
{% endblock %}

{% block subtitle %}
    {% trans title=regform.title %}List of registrations for "{{ title }}"{% endtrans %}
{% endblock %}

{% block content %}
    {% if regform.is_purged %}
        {% call message_box('error', fixed_width=true, large_icon=true) %}
            <div class="label">
                {% trans %}Registration is disabled due to an expired retention period{% endtrans %}
            </div>
        {% endcall %}
    {% else %}
        {{ render_registrations() }}
    {% endif %}
{% endblock %}

{% macro render_registrations() -%}
    <div class="list registrations">
        <div class="toolbars space-after">
            <div class="toolbar">
                <div class="group">
                    <button class="icon-checkbox-checked i-button arrow left icon-only"
                            aria-hidden="true" data-toggle="dropdown"></button>
                    <ul class="i-dropdown">
                        <li><a href="#" id="select-all">{% trans 'Selection' %}All{% endtrans %}</a></li>
                        <li><a href="#" id="select-none">{% trans 'Selection' %}None{% endtrans %}</a></li>
                    </ul>
                </div>
                <div class="group">
                    <button class="i-button icon-settings js-dialog-action js-customize-list {% if filtering_enabled %} highlight{% endif %}"
                            data-href="{{ url_for('.customize_reglist', regform) }}"
                            data-title="{% trans %}Registration list configuration{% endtrans %}"
                            data-dialog-classes="list-filter-dialog"
                            data-update='#registration-list'
                            data-ajax-dialog>
                        {% trans %}Customize list{% endtrans %}
                    </button>
                </div>
                <div class="group hide-if-locked">
                    <button class="i-button arrow icon-plus" data-toggle="dropdown">
                        {% trans %}Register{% endtrans %}
                    </button>
                    <ul class="i-dropdown">
                        <li>
                            <a href="{{ url_for('.create_registration', regform) }}"
                               data-title="{% trans %}Register a user that doesn't exist in Indico{% endtrans %}">
                                {% trans %}New user{% endtrans %}
                            </a>
                        </li>
                        <li>
                            <a href="#" class="js-add-user"
                               data-href="{{ url_for('.create_registration', regform) }}"
                               data-title="{% trans %}Register a Indico user{% endtrans %}"
                               data-search-token="{{ make_user_search_token() }}">
                                {% trans %}Indico user{% endtrans %}
                            </a>
                        </li>
                        <li>
                            <a href="#" class="js-add-multiple-users"
                               data-href="{{ url_for('.create_multiple_registrations', regform) }}"
                               data-title="{% trans %}Register multiple Indico users{% endtrans %}">
                                {% trans %}Multiple Indico users{% endtrans %}
                            </a>
                        </li>
                    </ul>
                    <button class="i-button icon-remove js-requires-selected-row disabled js-delete-registrations"
                       data-href="{{ url_for('.delete_registrations', regform) }}"
                       data-method="POST">
                        {%- trans %}Remove{% endtrans -%}
                    </button>
                </div>
                <div class="group">
                    <button class="i-button arrow button js-requires-selected-row disabled" data-toggle="dropdown">
                        {%- trans %}Export{% endtrans -%}
                    </button>
                    <ul class="i-dropdown">
                        <li>
                            <a href="#" class="icon-file-pdf js-requires-selected-row disabled js-submit-list-form"
                               data-href="{{ url_for('.registrations_pdf_export_table', regform) }}">
                                {%- trans %}PDF (table style){% endtrans -%}
                            </a>
                        </li>
                        <li>
                            <a href="#" class="icon-file-pdf js-requires-selected-row disabled js-submit-list-form"
                               data-href="{{ url_for('.registrations_pdf_export_book', regform) }}">
                                {%- trans %}PDF (book style){% endtrans -%}
                            </a>
                        </li>
                        <li>
                            <a href="#" class="icon-file-spreadsheet js-requires-selected-row disabled js-submit-list-form"
                               data-href="{{ url_for('.registrations_csv_export', regform) }}">CSV</a>
                        </li>
                        <li>
                            <a href="#" class="icon-file-excel js-requires-selected-row disabled js-submit-list-form"
                               data-href="{{ url_for('.registrations_excel_export', regform) }}">XLSX (Excel)</a>
                        </li>
                    </ul>
                    <button class="i-button"
                            data-href="{{ url_for('.registrations_import', regform) }}"
                            data-title="{% trans %}Import registrants from CSV File{% endtrans %}"
                            data-ajax-dialog>
                        {%- trans %}Import{% endtrans -%}
                    </button>
                    <button class="i-button arrow button js-requires-selected-row disabled"
                            data-toggle="dropdown">
                        {%- trans %}Actions{% endtrans -%}
                    </button>
                    <ul class="i-dropdown">
                        {% for item in action_menu_items %}
                            <li {% if item.hide_if_locked %}class="hide-if-locked"{% endif %}>
                                <a href="#"
                                   class="icon-{{ item.icon_name }}
                                          disabled
                                          {{ 'js-requires-selected-row' if item.requires_selected }}
                                          {{ item.extra_classes }}"
                                   data-weight="{{ item.weight }}"
                                   data-params="{{ item.params | tojson | forceescape }}"
                                   {% if item.type == "callback" %}
                                       data-params-selector="#registration-list tr input[type=checkbox]:checked"
                                       data-callback="{{ item.callback }}"
                                   {% elif item.type == "href-custom" %}
                                       data-href="{{ item.url }}"
                                   {% elif item.type == "ajax-dialog" %}
                                       data-href="{{ item.url }}"
                                       data-title="{{ item.dialog_title or item.text }}"
                                       data-params-selector="#registration-list tr input[type=checkbox]:checked"
                                       data-method="POST"
                                       data-ajax-dialog
                                       {{ 'data-reload-after' if item.reload_page }}
                                   {% endif %}
                                >
                                    {{ item.text }}
                                </a>
                            </li>
                        {% endfor %}
                    </ul>
                    {% set pending_registrations = registrations | selectattr('state.name', 'equalto', 'pending') | list %}
                    {% if (regform.moderation_enabled or pending_registrations) and not event.is_locked %}
                        <button class="i-button arrow button js-requires-selected-row disabled"
                                data-toggle="dropdown">
                            {%- trans %}Moderation{% endtrans -%}
                        </button>
                        <ul class="i-dropdown">
                            <li>
                                <a href="#" class="icon-checkmark js-requires-selected-row disabled js-modify-status"
                                   data-href="{{ url_for('.registrations_approve', regform) }}"
                                   data-method="POST"
                                   data-confirm="{% trans %}Do you really want to approve the selected registrations? This will trigger a notification email for each registrant.{% endtrans %}">
                                    {%- trans %}Approve registrations{% endtrans -%}
                                </a>
                            </li>
                            <li>
                                <a href="#" class="icon-close js-requires-selected-row disabled"
                                   data-href="{{ url_for('.registrations_reject', regform) }}"
                                   data-params-selector="#registration-list tr input[type=checkbox]:checked"
                                   data-method="POST"
                                   data-title="{% trans %}Reject registrations{% endtrans %}"
                                   data-update="#registration-list"
                                   data-ajax-dialog>
                                    {%- trans %}Reject registrations{% endtrans -%}
                                </a>
                            </li>
                            <li>
                                <a href="#" class="icon-loop js-requires-selected-row disabled js-modify-status"
                                   data-href="{{ url_for('.registrations_reset', regform) }}"
                                   data-method="POST"
                                   data-confirm="{% trans %}Do you really want to reset the selected registrations?{% endtrans %}">
                                    {%- trans %}Reset registrations{% endtrans -%}
                                </a>
                            </li>
                        </ul>
                    {% endif %}
                    {% if not event.is_locked %}
                        <button class="i-button arrow button js-requires-selected-row disabled" data-toggle="dropdown">
                            {%- trans %}Check-in control{% endtrans -%}
                        </button>
                        <ul class="i-dropdown">
                            <li>
                                <a href="#" class="icon-location js-requires-selected-row disabled js-modify-status"
                                   data-method="POST"
                                   data-flag="1"
                                   data-href="{{ url_for('.registrations_check_in', regform) }}">
                                    {%- trans %}Check-in{% endtrans -%}
                                </a>
                            </li>
                            <li>
                                <a href="#" class="icon-close js-requires-selected-row disabled js-modify-status"
                                   data-href="{{ url_for('.registrations_check_in', regform) }}"
                                   data-method="POST"
                                   data-flag="0"
                                   data-confirm="{% trans %}Are you sure you want to reset the check-in info? The original check-in time will be lost.{% endtrans %}"
                                   data-title="{% trans %}Reset check-in{% endtrans %}">
                                    {%- trans %}Reset check-in{% endtrans -%}
                                </a>
                            </li>
                        </ul>
                    {% endif %}
                    {{ template_hook('registration-status-action-button', regform=regform) }}
                </div>
                <div class="group">
                    <button class="i-button button change-columns-width" title="{% trans %}Adapt columns width{% endtrans %}"></button>
                </div>
            </div>
            <div class="toolbar">
                <div class="group">
                    <button class="i-button icon-link js-static-url"
                       data-href="{{ url_for('.generate_static_url', regform) }}"
                       title="{% trans %}Generate a URL for the selected filters and columns.{% endtrans %}"></button>
                </div>
                <div class="group">
                    <span class="i-button label icon-user" title="{% trans %}Total active registrations{% endtrans %}">
                        {{ regform.active_registration_count }}
                        {%- if regform.registration_limit %}
                            / {{ regform.registration_limit }}
                        {%- endif -%}
                    </span>
                    {% if regform.existing_registrations_count > regform.active_registration_count -%}
                        <span class="i-button label icon-user-block" title="{% trans %}Inactive registrations{% endtrans %}">
                            {{ regform.existing_registrations_count - regform.active_registration_count }}
                        </span>
                    {%- endif %}
                </div>
            </div>
        </div>
        <div class="list-content" id="registration-list">
            {{ render_registration_list(regform, registrations, dynamic_columns, static_columns, extra_columns, total_registrations) }}
        </div>
    </div>

    <script>
        setupRegistrationList();
    </script>
{%- endmacro %}
