{% extends 'events/registration/management/_regform_base.html' %}

{% block content %}
    {% block regform_private %}
        {% if regform.private %}
            <div class="action-box highlight">
                <div class="section">
                    <div class="icon icon-lock-center"></div>
                    <div class="text">
                        <div class="label">
                            {%- trans %}This form is private{% endtrans -%}
                        </div>
                        {% trans -%}
                            Share the secret link or send invitations to anyone you want to register.
                        {%- endtrans %}
                    </div>
                    <div class="toolbar">
                        <a href="{{ url_for('.display_regform', regform, regform.locator.token, _external=true) }}"
                           class="js-copy-to-clipboard i-button highlight icon-copy"
                           title="{% trans %}Copy link to clipboard{% endtrans %}"
                           data-clipboard-text="{{ url_for('.display_regform', regform, regform.locator.token, _external=true) }}"
                           data-clipboard-action="copy">
                            {% trans %}Copy secret link{% endtrans %}
                        </a>
                    </div>
                </div>
            </div>
        {% endif %}
    {% endblock %}

    {% if regform.is_purged %}
        {%- call message_box('error', fixed_width=true) -%}
            {% trans %}Registrations have been deleted due to an expired retention period.{% endtrans %}
        {%- endcall %}
    {% elif regform.retention_period %}
        {%- call message_box('warning', fixed_width=true) -%}
            {% trans count=(regform.retention_period.days // 7), date=(event.end_dt + regform.retention_period)|format_date %}
                Registrations will be permanently deleted {{ count }} week after the event ended (on {{ date }}).
            {% pluralize %}
                Registrations will be permanently deleted {{ count }} weeks after the event ended (on {{ date }}).
            {% endtrans %}
        {%- endcall %}
    {% endif %}

    {% block regform_state %}
        {% if not regform.has_started %}
            {% include 'events/registration/management/regform_actions/not_started.html' %}
        {% elif regform.is_open %}
            {% include 'events/registration/management/regform_actions/open.html' %}
        {% elif regform.has_ended %}
            {% include 'events/registration/management/regform_actions/ended.html' %}
        {% endif %}
    {% endblock %}

    {% block regform_setup_box %}
        <div class="action-box">
            <div class="section">
                <div class="icon icon-settings"></div>
                <div class="text">
                    <div class="label">
                        {% trans %}General Settings{% endtrans %}
                    </div>
                    {% trans %}Edit settings for this form.{% endtrans %}
                </div>
                <div class="toolbar">
                    <a href="{{ url_for('.edit_regform', regform) }}" class="i-button icon-edit">
                        {% trans %}Edit{% endtrans %}
                    </a>
                </div>
            </div>

            <div class="section">
                <div class="icon icon-clipboard"></div>
                <div class="text">
                    <div class="label">
                        {% trans %}Registration Form{% endtrans %}
                    </div>
                    {% trans %}Add, remove or modify information registrants may fill out.{% endtrans %}
                </div>
                <div class="toolbar">
                    <a href="{{ url_for('.modify_regform', regform) }}" class="i-button icon-settings">
                        {% trans %}Configure{% endtrans %}
                    </a>
                </div>
            </div>

            <div class="section">
                <div class="sui-icon-wrapper">
                    <i class="icon balance scale"></i>
                </div>
                <div class="text">
                    <div class="label">
                        {% trans %}Privacy settings{% endtrans %}
                    </div>
                    {% trans %}Choose who can see the participants of this event.{% endtrans %}
                </div>
                <div class="toolbar">
                    <a href="{{ url_for('.manage_registration_privacy_settings', regform) }}" class="i-button icon-settings">
                        {% trans %}Configure{% endtrans %}
                    </a>
                </div>
            </div>
        </div>
    {% endblock %}

    <div class="action-box">
        <div class="section">
            <div class="icon icon-users"></div>
            <div class="text">
                <div class="label">
                    {% trans %}List of registrations{% endtrans %}
                </div>
                {% trans %}Add, remove or modify registrations.{% endtrans %}
            </div>
            <div class="toolbar">
                <div class="group">
                    {% block registrations_count_label %}
                        <span class="i-button label icon-user" title="{% trans %}Total registrations{% endtrans %}">
                            {{ regform.active_registration_count }}
                            {%- if regform.registration_limit %}
                                / {{ regform.registration_limit }}
                            {%- endif -%}
                        </span>
                    {% endblock %}
                </div>
                <div class="group">
                    {% set purged_title %}
                        {% trans %}Registration is disabled due to an expired retention period{% endtrans %}
                    {% endset %}
                    <a href="{{ url_for('.manage_reglist', regform) }}"
                       class="i-button icon-settings {% if regform.is_purged %}disabled{% endif %}"
                       {% if regform.is_purged %}title="{{ purged_title }}"{% endif %}>
                        {% trans %}Manage{% endtrans %}
                    </a>
                </div>
            </div>
        </div>

        {% block invitations_section %}
            <div class="section">
                <div class="icon icon-mail"></div>
                <div class="text">
                    <div class="label">
                        {% trans %}Invitations{% endtrans %}
                    </div>
                    {% trans %}Manage invitations to register for your event.{% endtrans %}
                </div>
                <div class="toolbar">
                    <a href="{{ url_for('.invitations', regform) }}" class="i-button icon-settings">
                        {% trans %}Manage{% endtrans %}
                    </a>
                </div>
            </div>
        {% endblock %}

        {% block ticket_config_section %}
            <div class="section">
                <div class="icon icon-ticket"></div>
                <div class="text">
                    <div class="label">
                        {% trans %}Tickets{% endtrans %}
                    </div>
                    {% trans %}Configure ticketing system{% endtrans %}
                </div>

                <div class="toolbar">
                    <div class="group">
                        <a id="checkin-app-link" class="icon-link"
                           style="margin-right:1em;{{ 'display: none;' if not regform.tickets_enabled }}"
                           href="{{ indico_config.CHECKIN_APP_URL }}"
                           target="_blank"
                           rel="noopener noreferrer"
                           title="{% trans %}Use the app to manage the check-in status of the participants{% endtrans %}">
                            {% trans %}Open the Check-in App{% endtrans %}
                        </a>
                        <button id="qr-code" class="i-button icon-qrcode"
                           style="{{ 'display: none;' if not regform.tickets_enabled }}"
                           data-href="{{ url_for('.tickets_qrcode', regform) }}"
                           title="{% trans %}In order to configure your mobile app to use this event,
                                  you will have to scan the QR code{% endtrans %}">
                            {% trans %}QR Code{% endtrans %}
                        </button>
                        <button id="qr-code-config" class="i-button icon-settings"
                           data-href="{{ url_for('.tickets', regform) }}"
                           data-title="{%- trans %}Configure tickets{% endtrans -%}"
                           data-ajax-dialog>
                            {% trans %}Configure{% endtrans %}
                        </button>
                    </div>
                </div>
            </div>
        {% endblock %}
    </div>
    {{ template_hook('extra-regform-settings', regform=regform) }}
    <div class="toolbar right">
        {% block regform_stats_button %}
            <a class="i-button icon-chart" href="{{ url_for('.regform_stats', regform) }}">
                {% trans %}Stats{% endtrans %}
            </a>
        {% endblock %}
    </div>
    <script>
        (function() {
            'use strict';
            const qrCodeButton = $('#qr-code');
            const checkinAppLink = $('#checkin-app-link');
            qrCodeButton.qbubble({
                content: {
                    text: function() {
                        return $.ajax({
                            url: qrCodeButton.data('href'),
                            cache: false
                        });
                    }
                },
                style: {
                    classes: 'no-max-width'
                }
            });
            $('#qr-code-config').on('ajaxDialog:closed', function(evt, data) {
                if (data) {
                    qrCodeButton.toggle(data.tickets_enabled);
                    checkinAppLink.toggle(data.tickets_enabled);
                }
            });
        })();
    </script>
{% endblock %}
