{% from 'events/management/_lists.html' import render_displayed_entries_fragment %}

{% macro render_user_papers_list(event, contributions, to_review=false, reviewed=false) %}
    <section>
        {% set id = none %}
        {% if to_review %}
            {% set id = 'to-review-list' %}
        {% elif reviewed %}
            {% set id = 'reviewed-list' %}
        {% endif %}
        <div {% if id %}id="{{ id }}"{% endif %} class="paper-contribution-list">
            <ul>
                {% for contribution in contributions|sort(attribute='friendly_id') %}
                    {% set latest_revision = contribution.paper.last_revision %}
                    <div class="contribution-row" data-friendly-id="{{ contribution.friendly_id }}">
                        <li>
                            <div class="row-title">
                                <a href="{{ url_for('.paper_timeline', contribution) }}"
                                   data-searchable="{{ contribution.title|lower }}">
                                    #{{ contribution.friendly_id }}: {{ contribution.title }}
                                </a>
                            </div>
                            <div class="row-content flexrow f-j-space-between">
                                <div>
                                    {% if reviewed or to_review %}
                                        <div class="submitter icon-user align-icon"
                                             data-searchable="{{ latest_revision.submitter.display_full_name|lower }}">
                                            {{- latest_revision.submitter.display_full_name -}}
                                        </div>
                                        {% set state_icon_map = {'submitted': 'icon-file-eye',
                                                                 'accepted': 'icon-checkmark',
                                                                 'rejected': 'icon-cross',
                                                                 'to_be_corrected': 'icon-tilde'} %}
                                        <div class="{{ state_icon_map[latest_revision.state.name] }} align-icon semantic-text {{ latest_revision.state.css_class }}">
                                            {%- if latest_revision.state.name == 'submitted' -%}
                                                {% trans %}Submitted for reviewing{% endtrans %}
                                            {%- else -%}
                                                {{ latest_revision.state.title }}
                                            {%- endif -%}
                                        </div>
                                        {% if session.user in contribution.paper_content_reviewers %}
                                            {% if latest_revision.has_user_reviewed(session.user, 'content') %}
                                                <div class="icon-checkmark align-icon semantic-text success">
                                                    {%- trans -%}You have submitted a content review{%- endtrans -%}
                                                </div>
                                            {% elif contribution.paper.cfp.is_content_reviewing_possible %}
                                                <div class="icon-hour-glass2 align-icon semantic-text warning">
                                                    <a href="{{ url_for('.paper_timeline', contribution) }}"
                                                       class="submission-link">
                                                        {%- trans -%}Your content review is pending{%- endtrans -%}
                                                    </a>
                                                </div>
                                            {% endif %}
                                        {% endif %}
                                        {% if session.user in contribution.paper_layout_reviewers %}
                                            {% if latest_revision.has_user_reviewed(session.user, 'layout') %}
                                                <div class="icon-checkmark align-icon semantic-text success">
                                                    {%- trans -%}You have submitted a layout review{%- endtrans -%}
                                                </div>
                                            {% elif contribution.paper.cfp.is_layout_reviewing_possible %}
                                                <div class="icon-hour-glass2 align-icon semantic-text warning">
                                                    <a href="{{ url_for('.paper_timeline', contribution) }}"
                                                       class="submission-link">
                                                        {%- trans -%}Your layout review is pending{%- endtrans -%}
                                                    </a>
                                                </div>
                                            {% endif %}
                                        {% endif %}
                                    {% endif %}
                                </div>
                                <ul>
                                    {% for file in latest_revision.files %}
                                        {% set icon = icon_from_mimetype(file.content_type, 'icon-file') %}
                                        <li class="flexrow f-j-end">
                                            <a href="{{ url_for('.download_file', file) }}">
                                                <span>{{ file.filename }}</span>
                                                <i class="attachment {{ icon }}"></i>
                                            </a>
                                        </li>
                                    {% endfor %}
                                </ul>
                            </div>
                        </li>
                    </div>
                {% endfor %}
            </ul>
        </div>
    </section>
{% endmacro %}
