{% extends "orga/cfp/base.html" %}
{% load bootstrap4 %}
{% load compress %}
{% load i18n %}
{% load rules %}
{% load static %}
{% load url_replace %}

{% block stylesheets %}
{% if timeline_data %}
    <link rel="alternate" hreflang="en" type="application/rss+xml" title="{% trans "Submission feed" %}" href="{{ request.event.orga_urls.submission_feed }}">
{% endif %}
{% endblock %}

{% block content %}
{% has_perm 'orga.create_submission' request.user request.event as can_create_submission %}
{% has_perm 'orga.view_speakers' request.user request.event as can_view_speakers %}
    <a href="{{ request.event.orga_urls.submission_feed }}" title="{% trans "Submission feed" %}">
        <i class="fa fa-feed float-right"></i>
    </a>
    <h2>
        <span>
            {{ page_obj.paginator.count }}
            {% blocktrans trimmed count count=page_obj.paginator.count %}
            submission
            {% plural %}
            submissions
            {% endblocktrans %}
        </span>
    </h2>

    <div class="submit-group">
        <form class="search-form">
            {% bootstrap_form search_form %}
            {% bootstrap_field filter_form.submission_type %}
            {% bootstrap_field filter_form.state layout='inline' %}
            {% if request.event.settings.use_tracks %}
                {% bootstrap_field filter_form.track %}
            {% endif %}
            <button class="btn btn-success" type="submit">{% trans "Search" %}</button>
        </form>
        {% if can_create_submission %}
        <p class="ml-auto">
            <a href="{{ request.event.orga_urls.new_submission }}" class="btn btn-success mt-2">
                <i class="fa fa-plus"></i> {% trans "Add new submission" %}
            </a>
        </p>
        {% endif %}
    </div>

    <table class="table table-sm table-hover table-responsive-md">
        <thead>
            <tr>
                {% if request.event.settings.use_tracks %}
                <th></th>
                {% endif %}
                <th>
                    {% trans "Title" %}
                    <a href="?{% url_replace request 'sort' 'title' %}"><i class="fa fa-caret-down" title="{% trans "Sort by title (a-z)" %}"></i></a>
                    <a href="?{% url_replace request 'sort' '-title' %}"><i class="fa fa-caret-up" title="{% trans "Sort by title (z-a)" %}"></i></a>
                </th>
                {% if can_view_speakers %}<th>{% trans "Speakers" %}</th>{% endif %}
                <th>
                    {% trans "Type" %}
                </th>
                <th>
                    {% trans "State" %}
                    <a href="?{% url_replace request 'sort' 'state' %}"><i class="fa fa-caret-down" title="{% trans "Sort by state (a-z)" %}"></i></a>
                    <a href="?{% url_replace request 'sort' '-state' %}"><i class="fa fa-caret-up" title="{% trans "Sort by state (z-a)" %}"></i></a>
                </th>
                <th>
                    {% trans "Sneak peek" %} <i class="fa fa-question-circle" data-toggle="tooltip" title="{% trans "Show this submission on the public preview page, if it was accepted" %}"></i>
                    <a href="?{% url_replace request 'sort' '-is_featured' %}"><i class="fa fa-caret-down" title="{% trans "Sort by sneak peek first" %}"></i></a>
                    <a href="?{% url_replace request 'sort' 'is_featured' %}"><i class="fa fa-caret-up" title="{% trans "Sort sneak peek last" %}"></i></a>
                </th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            {% for submission in submissions %}
                <tr>
                    {% if request.event.settings.use_tracks %}
                    <td>
                        {% if submission.track %}
                        <div class="color-square" style="background-color: {{ submission.track.color }}" title="{{ submission.track.name }}">
                        </div>
                        {% endif %}
                    </td>
                    {% endif %}
                    <td>
                        <a href="{{ submission.orga_urls.base }}">
                            {{ submission.title }}
                        </a>
                    </td>
                    {% if can_view_speakers %}
                    <td>
                        {% for speaker in submission.speakers.all %}
                            <a href="{% url "orga:speakers.view" event=request.event.slug pk=speaker.id %}">
                                {{ speaker.get_display_name }}
                            </a><br>
                        {% endfor %}
                    </td>
                    {% endif %}
                    <td>
                        {{ submission.submission_type.name }}
                    </td>
                    <td>
                        {% include "orga/submission/state_dropdown.html" with submission=submission %}
                    </td>
                    <td class="submission_featured">
                        <div class="checkbox mt-1" title="{% trans 'Show this submission in the public sneak peek.' %}">
                            <input
                                type="checkbox"
                                id="featured_{{ submission.code }}"
                                data-id="{{ submission.code }}"
                                class="submission_featured"
                                {% if submission.is_featured %}checked{% endif %}
                            >
                            <label for="featured_{{ submission.code }}"></label>
                        </div>
                        <i class="working fa fa-spinner fa-spin d-none"></i>
                        <i class="done fa fa-check d-none"></i>
                        <i class="fail fa fa-times d-none"></i>
                    </td>
                    <td class="action-column">
                        <a href="{{ submission.orga_urls.edit }}"
                            title="{% trans "edit" %}"
                            class="btn btn-sm btn-info">
                            <i class="fa fa-edit"></i>
                        </a>
                        <a href="{{ submission.orga_urls.delete }}?from=list"
                            title="{% trans "delete" %}"
                            class="btn btn-sm btn-danger">
                            <i class="fa fa-trash"></i>
                        </a>
                    </td>
                </tr>
            {% endfor %}
        </tbody>
    </table>

    {% include "orga/pagination.html" %}


{% endblock %}
