{% from 'events/display/indico/_common.html' import render_location, render_users %}
{% from 'message_box.html' import message_box %}

{% macro render_contribution_list(event, timezone, contributions, total_entries=none, with_session_info=true) %}
    {% if contributions %}
        {% for contrib in contributions | selectattr('start_dt_display') | sort(attribute='title') | sort(attribute='start_dt_display') %}
            {{- _render_contribution_row(timezone, contrib, with_session_info) -}}
        {% endfor %}
        {% for contrib in contributions | rejectattr('start_dt_display') | sort(attribute='title') %}
            {{- _render_contribution_row(timezone, contrib, with_session_info) -}}
        {% endfor %}
    {%- else %}
        {% if total_entries is none %}{% set total_entries = contributions|length %}{% endif %}
        {%- call message_box('info') %}
            {%- if total_entries %}
                {%- trans -%}
                    The filtering criteria do not match with any of the existing contributions. Try to clear the filters.
                {%- endtrans %}
            {%- else %}
                {%- trans %}There are no contributions yet.{% endtrans %}
            {%- endif %}
        {%- endcall %}
    {%- endif %}
{% endmacro %}

{% macro _render_contribution_row(timezone, contrib, with_session_info=true) %}
    <div class="contribution-row" data-friendly-id="{{ contrib.friendly_id }}">
        <div class="contrib-title info" data-searchable="{{ contrib.title|lower }}">
            <span class="value">
                <a class="js-mathjax" href="{{ url_for('contributions.display_contribution', contrib) }}">
                    <span class="contrib-id">{{ contrib.friendly_id }}.</span>
                    {{ contrib.title }}
                    {% if contrib.code -%}
                        <span class="contrib-code" data-searchable="{{ contrib.code|lower }}">
                            ({{ contrib.code }})
                        </span>
                    {%- endif %}
                </a>
            </span>
        </div>
        {% if contrib.speakers -%}
            <div class="speaker-list icon-user" data-searchable="{{ contrib.speakers|lower }}">
                {{ render_users(contrib.speakers|sort(attribute='display_order_key'),
                                span_class='speaker-item-inline', title=contrib.event.show_titles) }}
            </div>
        {%- endif %}
        {% if contrib.start_dt_display -%}
            <div class="contrib-time icon-time">
                {{ contrib.start_dt_display|format_datetime(format='short', timezone=timezone) }}
            </div>
        {%- endif %}
        <div>
            {% if contrib.track -%}
                <div class="contrib-track small"
                     data-searchable="{{ contrib.track.title|lower }}"
                     title="{{ contrib.track.title_with_group if contrib.track.track_group }}">
                    {{ contrib.track.title }}
                </div>
            {%- endif %}
            {% if contrib.type -%}
                <div class="contrib-type small" data-searchable="{{ contrib.type.name|lower }}">
                    {{ contrib.type.name }}
                </div>
            {%- endif %}
            {% if contrib.session and with_session_info -%}
                <div class="contrib-session small" data-searchable="{{ contrib.session.title|lower }}"
                     style="{{ contrib.session.colors.css }}">
                    <a href="{{ url_for('sessions.display_session', contrib.session) }}"
                       style="color: #{{ contrib.session.colors.text }}">{{ contrib.session.title }}</a>
                    <span class="session-bg-color" style="background: #{{ contrib.session.colors.background }};"></span>
                </div>
            {%- endif %}
        </div>
        {% if contrib.description -%}
            <a href="{{ url_for('contributions.display_contribution', contrib) }}">
                <div class="description js-mathjax">
                    {{ contrib.description|truncate(400) }}
                </div>
            </a>
        {%- endif %}
    </div>
{% endmacro %}
