{% extends 'layout/dialog_base.html' %}
{% from 'forms/_form.html' import form_header, form_rows, form_footer %}
{% from 'message_box.html' import message_box %}

{% block content %}
    <form method="POST">
        <div class="js-assign-dialog">
            <div id="assign-role-table">
                {% if users %}
                    <table class="i-table-widget tablesorter">
                        <thead>
                            <tr class="i-table">
                                <th class="i-table thin-column" data-sorter="false"></th>
                                {# i18n: Full name of the person #}
                                <th class="i-table name-column">{{ pgettext('Person', 'Name') }}</th>
                                <th class="i-table competencies-column">{% trans %}Competences{% endtrans %}</th>
                            </tr>
                        </thead>
                        <tbody class="scroll">
                            {% for user in users|sort(attribute='full_name') -%}
                                <tr class="i-table">
                                    <td class="i-table thin-column id-column">
                                        <input type="checkbox" class="select-row" id="assign-user-{{ user.id }}"
                                               name='user_id' value="{{ user.id }}">
                                    </td>
                                    <td class="i-table name-column">
                                        <label for="assign-user-{{ user.id }}">
                                            {{ user.full_name }}
                                            {% if user.affiliation %}
                                                <br>
                                                <span class="affiliation">
                                                    {{ user.affiliation }}
                                                    {% set user_conflicts = conflicts.get(user) %}
                                                    {% if user_conflicts %}
                                                        <span class="js-count-label"
                                                              data-title="{% trans %}Overlapping affiliation{% endtrans %}"
                                                              data-items="{{ user_conflicts | tojson | forceescape }}">
                                                            <i class="icon-warning warning-text"></i>
                                                        </span>
                                                    {% endif %}
                                                </span>
                                            {% endif %}
                                        </label>
                                    </td>
                                    <td>
                                        {% for competence in competences.get('competences_{}'.format(user.id), []) %}
                                            <div class="label i-tag">{{ competence }}</div>
                                        {% endfor %}
                                    </td>
                                </tr>
                            {%- endfor %}
                        </tbody>
                    </table>
                {% else %}
                    {%- call message_box('info') -%}
                        {% if action == 'assign' %}
                            {% if role == 'judge' %}
                                {%- trans %}There are no judges yet.{% endtrans %}
                            {% elif role == 'content_reviewer' %}
                                {%- trans %}There are no content reviewers yet.{% endtrans %}
                            {% elif role == 'layout_reviewer' %}
                                {%- trans %}There are no layout reviewers yet.{% endtrans %}
                            {% endif %}
                        {% else %}
                            {% if role == 'judge' %}
                                {%- trans %}There are no judges assigned to the selected contributions.{% endtrans %}
                            {% elif role == 'content_reviewer' %}
                                {%- trans %}There are no content reviewers assigned to the selected contributions.{% endtrans %}
                            {% elif role == 'layout_reviewer' %}
                                {%- trans %}There are no layout reviewers assigned to the selected contributions.{% endtrans %}
                            {% endif %}
                        {% endif %}
                    {%- endcall %}
                {% endif %}
            </div>
            {% for contrib in contribs %}
                <input type="hidden" name="contribution_id" value="{{ contrib.id }}">
            {% endfor %}
            <button type="button" class="i-button big right" data-button-back>{% trans %}Cancel{% endtrans %}</button>
            <input class="i-button big highlight disabled js-requires-selected-row right" type="submit"
                   value="{{ _('Assign') if action == 'assign' else _('Unassign') }}">
        </div>
    </form>
    <script>
        enableIfChecked('.js-assign-dialog', '.select-row:visible', '.js-assign-dialog .js-requires-selected-row');
        setupConflictsList();
    </script>
{% endblock %}
