{% extends '_course_list.html' %}

{% block title %}Seznam offline kurzů Pythonu{% endblock title %}

{% block intro %}

    <p>Zde se nachází seznam kurzů s instruktorem. Kurzy pro samouky najdete <a href="{{ url_for('courses') }}">v seznamu materiálů</a>.</p>

{% endblock %}

{% macro show_run(run) %}
    <div>
        <h4>
            <a href="{{ run.get_url() }}">{{ run.title }}</a>
            {% if run.subtitle %}
                <small>– {{ run.subtitle }}</small>
            {% endif %}
        </h4>
        {% if run.start_date %}
            {{ (run.start_date, run.end_date) | format_date_range }}
        {% endif %}
        <p>{{ run.description }}</p>
    </div>
{% endmacro %}

{% macro pagination() %}
    <div>
        <ul class="paginate">
            <li class="paginate-prev">
                <a {% if year==None and all==None %}class="disabled"{% endif %}
                   href="{{ url_for('runs', **paginate_prev) }}">&lt;</a>
            </li>
            <li class="paginate-link {% if year==None and all==None %}current{% endif %}">
                 <a href="{{ url_for('runs', year=None) }}">Aktuální</a>
            </li>
            {% for page in all_years | reverse %}
                <li class="paginate-link {% if page==year %}current{% endif %}">
                     <a href="{{ url_for('runs', year=page) }}">{{ page }}</a>
                </li>
            {% endfor %}
            <li class="paginate-link {% if all!=None %}current{% endif %}">
                 <a href="{{ url_for('runs', year=None, all='all') }}">Vše</a>
            </li>
            <li class="paginate-next">
                <a {% if all!=None %}class="disabled"{% endif %}
                   href="{{ url_for('runs', **paginate_next) }}">&gt;</a>
            </li>
        </ul>
    </div>
{% endmacro %}

{% block list %}

    {% if all is none and year is none %}
        <h1>Aktuální kurzy</h1>
        {% if run_data["ongoing"] | length > 0 %}
            {% for run in run_data["ongoing"].values() | sort(attribute='start_date', reverse=True) %}
                {{ show_run(run) }}
            {% endfor %}
        {% else %}
            <div class="empty-run-list">
                Nemáme žádné aktuální kurzy.
            </div>
        {% endif %}

        {% if run_data["recent"] | length > 0 %}
            <h1>Proběhlé kurzy</h1>

            {{ pagination() }}
            {% for run in run_data["recent"].values() | sort(attribute='start_date', reverse=True) %}
                {{ show_run(run) }}
            {% endfor %}
        {% endif %}
    {% else %}
        {{ pagination() }}
        {% if year %}
            <h1>{{ year }}</h1>
        {% else %}
            <h1>Všechny kurzy</h1>
        {% endif %}
        {% for section, run_year in run_data.items() | sort(reverse=True) %}
            {% if (run_data | length) > 1 %}
                <h2>{{ section }}</h2>
            {% endif %}
            {% for run in run_year.values() | sort(attribute='start_date', reverse=True) %}
                {{ show_run(run) }}
            {% else %}
                <div class="empty-run-list">
                    V tomto roce neproběhly žádné kurzy.
                </div>
            {% endfor %}
        {% endfor %}
    {% endif %}

    {{ pagination() }}

{% endblock %}
