{% from 'events/display/common/_manage_button.html' import render_manage_button %}
{% from 'events/timetable/display/indico/_common.html' import render_speakers, render_references, render_attachments,
                                                              render_notes, render_description, render_time %}


{% macro render_subcontribution(subcontrib, event, theme_settings, theme_context, show_notes=true) %}
    <li class="timetable-subcontrib timetable-item" id="{{ subcontrib.slug }}">
        <div class="timetable-item-body flexcol">
            <div class="timetable-item-header flexrow">
                <span class="timetable-title" data-anchor="{{ subcontrib.slug }}" data-anchor-strip-arg="note">
                    {% if theme_settings.number_contributions %}
                        {%- set n_scontrib = theme_context.num_subcontribution -%}
                        {{- 'abcdefghijklmnopqrstuvwxyz'[(n_scontrib - 1) % 26] * ((n_scontrib - 1) // 26 + 1) }})
                    {% endif %}
                    {{- subcontrib.title -}}
                </span>
                {% if subcontrib.duration and not theme_settings.hide_duration %}
                    <span class="icon-time timetable-duration">
                        {{- subcontrib.duration | format_human_timedelta(narrow=true) -}}
                    </span>
                {% endif %}
                <div class="timetable-item-actions">
                    {{ render_manage_button(subcontrib, 'SUBCONTRIBUTION', show_notes=show_notes) }}
                </div>
            </div>

            {% if subcontrib.description %}
                {{ render_description(subcontrib, class='subcontrib-description') }}
            {% endif %}

            {% set speakers = subcontrib.person_links|selectattr("is_speaker")|list %}
            {% if speakers %}
                {{ render_speakers(speakers) }}
            {% endif %}

            <table class="timetable-subcontrib-details">
                <tbody>
                    {% if subcontrib.references -%}
                        {{ render_references(subcontrib) }}
                    {% endif %}
                    {{ render_attachments(subcontrib) }}
                </tbody>
            </table>

            {{ render_notes(subcontrib, anchor=subcontrib.slug) }}
        </div>
    </li>
{% endmacro %}
