{% extends 'forms/base_widget.html' %}

{% macro render_section(id, title=none, placeholder=none) %}
    {% if title is not none %}
        <div id="{{ id }}-list-title-{{ field.id }}" class="titled-rule">
            {{ title }}
        </div>
    {% endif %}
    {% if placeholder is not none %}
        <div id="no-{{ id }}-placeholder-{{ field.id }}" class="nobody-placeholder">
            {{ placeholder }}
        </div>
    {% endif %}
    <div id="{{ id }}-list-{{ field.id }}" class="person-list"></div>
{% endmacro %}

{% block html %}
    <div id="person-link-field-{{ field.id }}"></div>
    <input type="hidden" id="{{ field.id }}" name="{{ field.name }}" value="{{ field._value()|tojson|forceescape }}">
{% endblock %}

{% block javascript %}
    <script>
        setupPersonLinkWidget({
            fieldId: {{ field.id | tojson }},
            eventId: {{ (field.event.id if field.event else none) | tojson }},
            roles: {{ field.roles | default([]) | tojson }},
            sortByLastName: {{ field.sort_by_last_name | default(false) | tojson }},
            emptyMessage: {{ field.empty_message | default(none) | tojson }},
            hasPredefinedAffiliations: {{ field.has_predefined_affiliations | tojson }},
            allowCustomAffiliations: {{ field.allow_custom_affiliations | tojson }},
            customPersonsMode: {{ field.custom_persons_mode.name | tojson }},
            requiredPersonFields: {{ field.required_person_fields | list | tojson }},
            defaultSearchExternal: {{ field.default_search_external | tojson }},
            nameFormat: {{ field.name_format.name | tojson }},
            sessionUser: Indico.User,
            validateEmailUrl: {{ field.validate_email_url | tojson }},
            extraParams: {{ field.extra_params | tojson }},
            searchToken: {{ (field.search_token if not field.search_token_source|default(none) else none) | tojson }},
            searchTokenSource: {{ field.search_token_source|default(none) | tojson }},
        });
    </script>
{% endblock %}
