{% extends 'events/display/conference/base.html' %}

{% from 'events/contributions/display/_contribution_list.html' import render_contribution_list %}
{% from 'events/display/common/_conferences.html' import render_attachments %}
{% from 'events/display/indico/_common.html' import render_location, render_users %}
{% from 'events/_affiliation.html' import render_affiliation %}
{% from 'message_box.html' import message_box %}

{% block page_class %}conference-page item-summary{% endblock %}

{% block title %}
    {%- trans %}Session{% endtrans -%}
{% endblock %}

{% block subtitle %}
    {{- sess.title -}}
{% endblock %}

{% block info %}
    {% if sess.code %}
        <div class="generic-data">
            <i class="icon-tag header-data"></i>
            {{ sess.code }}
        </div>
    {% endif %}
    <div class="generic-data">
        <i class="icon-time header-data"></i>
        <span class="time-info">
            {% if sess.start_dt -%}
                {{ sess.start_dt|format_datetime(timezone=event.display_tzinfo) }}
            {%- else -%}
                {% trans %}Not scheduled{% endtrans %}
            {%- endif %}
        </span>
    </div>
    {% if sess.has_location_info %}
        <div class="generic-data">
            {{ render_location(sess, class='session-location') }}
        </div>
    {% endif %}
{% endblock %}

{% block page_actions -%}
    <div class="toolbar">
        <div class="group">
            {% if sess.can_manage(session.user) -%}
                <button class="i-button icon-edit"
                        title="{% trans %}Edit session{% endtrans %}"
                        data-title="{% trans %}Edit session{% endtrans %}"
                        data-href="{{ url_for('.modify_session', sess) }}"
                        data-ajax-dialog
                        data-reload-after></button>
                <button class="i-button icon-shield"
                        title="{% trans %}Manage protection{% endtrans %}"
                        data-title="{% trans title=sess.title %}Manage protection{% endtrans %}"
                        data-href="{{ url_for('.session_protection', sess) }}"
                        data-ajax-dialog
                        data-reload-after></button>
            {%- endif %}
            {% if sess.can_manage(session.user, 'coordinate') -%}
                <a href="{{ url_for('timetable.manage_session', sess) }}"
                   class="i-button icon-time"
                   title="{% trans %}Manage timetable{% endtrans %}"></a>
            {%- endif %}
        </div>
        <div class="group">
            <a href="{{ url_for('sessions.export_session_timetable', sess) }}" class="i-button icon-file-pdf" title="{% trans %}Export to PDF{% endtrans %}"></a>
            {% if sess.start_dt -%}
                {% if g.static_site %}
                    <a href="{{ url_for('sessions.export_ics', sess) }}" class="i-button icon-calendar" title="{% trans %}Export{% endtrans %}"></a>
                {% else %}
                    <div id="session-calendar-link" data-session-id="{{ sess.id }}" data-event-id="{{ sess.event_id }}"
                         data-session-contrib-count="{{ sess.contributions|length }}"></div>
                {% endif %}
            {%- endif %}
        </div>
    </div>
{%- endblock %}

{% block content -%}
    {% if sess.blocks and sess.conveners -%}
        <section>
            <div class="flexrow">
                <div class="session-conveners">
                    <div class="header">
                        <div class="header-row">
                            <h3>{% trans %}Conveners{% endtrans %}</h3>
                        </div>
                    </div>
                    {% for block in sess.blocks -%}
                        <div class="header-row">
                            <h4>{{ block.full_title }}</h4>
                        </div>
                        <ul>
                            {% for convener in block.person_links -%}
                                <li class="icon-user">
                                    {% if sess.can_manage(session.user) %}
                                        <a href="mailto:{{ convener.email }}">
                                            {{ convener.full_name }}
                                        </a>
                                    {% else %}
                                        {{ convener.full_name }}
                                    {% endif %}
                                    {% if convener.affiliation %}
                                        <span class="affiliation">
                                            <span class="text">({{ render_affiliation(convener) }})</span>
                                        </span>
                                    {% endif %}
                                </li>
                            {%- else -%}
                                <li>{% trans %}There are no conveners in this block{% endtrans %}</li>
                            {%- endfor %}
                        </ul>
                    {%- endfor %}
                </div>
            </div>
        </section>
    {%- endif %}

    {% if sess.description %}
        <section>
            <div class="header">
                <div class="header-row">
                    <h3>{% trans %}Description{% endtrans %}</h3>
                </div>
                <div class="description">
                    {{ sess.description }}
                </div>
            </div>
        </section>
    {% endif %}

    {{ render_attachments(sess) }}

    <section>
        <div class="item-subitems toolbar">
            {% if sess.contributions %}
                <button class="i-button icon-list js-switch-view"
                        data-show="session-contrib-list">
                    {%- trans %}Contribution list{% endtrans -%}
                </button>
            {% endif %}
            {% if not sess.is_poster %}
                <button class="i-button icon-time highlight js-switch-view"
                        data-show="session-timetable">
                    {%- trans %}Timetable{% endtrans -%}
                </button>
            {% endif %}
        </div>
    </section>

    <div class="js-container">
        {% if sess.contributions %}
            <div id="session-contrib-list" class="contribution-list js-view">
                {{ render_contribution_list(event, event.display_tzinfo, sess.contributions, with_session_info=false) }}
            </div>
        {% endif %}

        {% if not sess.is_poster -%}
            <div id="session-timetable" class="js-view">
                {% set timetable_html = template_hook('session-timetable', session=sess, timetable_layout=none) %}
                {% if timetable_html %}
                    {{ timetable_html }}
                {% else %}
                    {% call message_box('info') -%}
                        {% trans %}No scheduled contributions{% endtrans %}
                    {%- endcall %}
                {% endif %}
            </div>
        {%- endif %}
    </div>

    <script>
        setupAttachmentTreeView();
        $('.js-switch-view').on('click', function(evt) {
            evt.preventDefault();

            $('.js-switch-view').removeClass('highlight');
            $('.js-container .js-view').hide();
            $(this).addClass('highlight');
            $('#' + $(this).data('show')).show();
        }).trigger('click');

        setupSessionsList({
            createSessionTypeURL: {{ url_for('sessions.create_type', event) | tojson }}
        });
    </script>
{%- endblock %}
