{% from 'events/notes/_note.html' import render_note %}
{% from 'attachments/_display.html' import render_attachments_folders %}
{% from 'events/display/indico/_common.html' import render_users %}

{% macro render_description(item, class='') %}
    <div itemprop="description" class="item-description {{ class }}">
        {{ item.description }}
    </div>
{% endmacro %}

{% macro render_references(item, class='reference-list-meeting') -%}
    <ul class="reference-list {{ class }}">
        {%- for reference in item.references -%}
            <li title="{% trans title=reference.reference_type.name %}External reference ({{ title }}){% endtrans %}"
                class="icon-link">
            {% if reference.url -%}
                <a href="{{ reference.url }}" class="title" target="_blank" rel="noopener noreferrer">
                    {{ reference.urn or reference.value }}
                </a>
            {%- else -%}
                <span class="title">{{ reference.urn or reference.value }}</span>
            {%- endif %}
            </li>
        {%- endfor -%}
    </ul>
{%- endmacro %}

{% macro render_time(item, timezone=none, hide_end_time=false) -%}
    <span class="start-time">
        {{ item.timetable_entry.start_dt | format_time(timezone=timezone) }}
    </span>
    {% if not hide_end_time %}
        &rarr;
        <span class="end-time">
            {{ item.timetable_entry.end_dt | format_time(timezone=timezone) }}
        </span>
    {% endif %}
{%- endmacro %}

{% macro render_speakers(speakers) -%}
    <div class="speaker-list">
        <span class="label">{{ ngettext("Speaker", "Speakers", speakers | length) }}</span>:
        {{ render_users(speakers | sort(attribute="display_order_key"), title=speakers[0].object.event.show_titles) }}
    </div>
{%- endmacro %}

{% macro render_attachments(item) -%}
    <div class="js-attachment-container">
        {% if item.attached_items %}
            <div class="material-list">
                {{ render_attachments_folders(item=item) }}
            </div>
        {% endif %}
    </div>
{%- endmacro %}

{% macro render_notes(item, for_event=none, anchor=none, hidden=true) -%}
    {% if item.has_note %}
        {% set req = request.args.get('note') %}
        {% set note_id = item.note.id|string %}
        {{ render_note(item.note, hidden=(hidden and req != note_id), can_edit=item.can_edit_note(session.user),
                       for_event=for_event, anchor=anchor) }}
    {% endif %}
{%- endmacro %}
