{% extends "agenda_culturel/page.html" %}


{% load cache %}
{% load cat_extra %}
{% load event_extra %}
{% load utils_extra %}
{% load static %}
{% load i18n %}

{% block entete_header %}
    {% css_categories %}
{% endblock %}

{% block navigation-menu %}
{% cache 90000 navigation_links_upcoming user.is_authenticated calendar.firstdate filter.get_url category calendar.nb_days %}
{% navigation_links filter category %}
{% endcache %}
{% endblock %}

{% block when_parameters %}{{ filter.get_url }}{% endblock %}

{% block body-class %}a-venir{% endblock %}

 {% block content %}


 <article id="filters">
    {% cache 60000 upcoming_title user.is_authenticated calendar.firstdate filter.get_url category calendar.nb_days %}
    <header><h1 id="index-avenir">{% block title %}{% block og_title %}
        {% if category %}{{ category.name }}{% else %}Événements{% endif %}
        {% if calendar.is_today %}
         à venir
        {% else %}
         du {{ calendar.firstdate | date:"l j F Y"  }}
        {% if calendar.nb_days > 1 %}
        et suivants
        {% endif %}
        {% endif %}{% if filter.has_location %} à {{ filter.get_position }}{% endif %}
    {% endblock %}{% endblock %}</h1></header>
    {% endcache %}
 
     {% with cache_timeout=user.is_authenticated|yesno:"30,6000" %}
     {% cache cache_timeout upcoming user.is_authenticated calendar.firstdate filter.get_url category calendar.nb_days %}
     {% include "agenda_culturel/filter-inc.html" with filter=filter noarticle=1 %}
    
    <footer>
    {% if category %}
    <a href="{% if calendar.nb_days == 1 %}{% url 'day_view_category' category.slug date_pred.year date_pred.month date_pred.day %}{% else %}{% url 'a_venir_jour_category' category.slug date_pred.year date_pred.month date_pred.day %}{% endif %}?{{ filter.get_url }}" aria-label="dates précédentes" role="button">
    {% else %}
    <a href="{% if calendar.nb_days == 1 %}{% url 'day_view' date_pred.year date_pred.month date_pred.day %}{% else %}{% url 'a_venir_jour' date_pred.year date_pred.month date_pred.day %}{% endif %}?{{ filter.get_url }}" aria-label="dates précédentes" role="button">
        {% endif %}
    {% picto_from_name "chevrons-left" %}
        {% if calendar.nb_days == 1 %}
            {{ date_pred }}
        {% endif %}
    </a>
    {% if calendar.nb_days > 1 %}
    {% for cd in calendar.calendar_days_list %}
        <a href="#{{ cd.id }}" role="button">
            {% if cd.is_today %}Aujourd'hui
            {% else %}
                {% if cd.is_tomorrow %}Demain
                {% else %}
                {{ cd.date| date:"l j b"|capfirst }}
                {% endif %}
            {% endif %}
        {% picto_from_name "chevrons-down" %}</a>
        {% endfor %}
    {% else %}
        {% if category %}
            <a role="button" href="{% url 'week_view_category' category.slug calendar.firstdate.year calendar.firstdate|week %}?{{ filter.get_url }}">toute la semaine  {% picto_from_name "chevrons-up" %</a>
        {% else %}
            <a role="button" href="{% url 'week_view' calendar.firstdate.year calendar.firstdate|week %}?{{ filter.get_url }}">toute la semaine  {% picto_from_name "chevrons-up" %}</a>
        {% endif %}
    {% endif %}
    {% if category %}
    <a href="{% if calendar.nb_days == 1 %}{% url 'day_view_category' category.slug date_next.year date_next.month date_next.day %}{% else %}{% url 'a_venir_jour_category' category.slug date_next.year date_next.month date_next.day %}{% endif %}?{{ filter.get_url }}" aria-label="dates suivantes" role="button">
    {% else %}
    <a href="{% if calendar.nb_days == 1 %}{% url 'day_view' date_next.year date_next.month date_next.day %}{% else %}{% url 'a_venir_jour' date_next.year date_next.month date_next.day %}{% endif %}?{{ filter.get_url }}" aria-label="dates suivantes" role="button">
        {% endif %}
        {% if calendar.nb_days == 1 %}
            {{ date_next }}
        {% endif %}
        {% picto_from_name "chevrons-right" %}
    </a>
</footer>
</article>

{% for cd in calendar.calendar_days_list %}
    <article class="day-interval" id="{{ cd.id }}">
        <header class="sticky">
            <a role="button" class="secondary slide-buttons" href="#index-avenir" data-placement="left" data-tooltip="Retour en haut">{% picto_from_name "chevrons-up" %}</a>
            {% if cd.is_today %}
            <hgroup>
                {% with cd.events|length as nb_events %}
                <h2>Aujourd'hui <a href="#{{ cd.id }}" role="button" class="badge">{{ nb_events }} événement{{ nb_events|pluralize }} {% picto_from_name "calendar" %}</a></h2>
                {% endwith %}
                <h3>{{ cd.date|date:"l j F Y"|frdate  }}</h3>
            </hgroup>
            {% else %}
                {% if cd.is_tomorrow %}
                <hgroup>
                    <h2>Demain <a href="#{{ cd.id }}" role="button" class="badge">{{ cd.events|length }} {% picto_from_name "calendar" %}</a></h2>
                    <h3>{{ cd.date|date:"l j F Y"|frdate  }}</h3>
                </hgroup>
                {% else %}
                <h2>{{ cd.date|date:"l j F Y"|frdate |capfirst }} <a href="#{{ cd.id }}" role="button" class="badge">{{ cd.events|length }} {% picto_from_name "calendar" %}</a></h2>
                {% endif %}
            {% endif %}
        </header>
        {% if cd.events|length > 0 %}
        <div class="resume">
            {% for ti in cd.get_time_intervals %}
            {% if ti.events|length > 0 %}
                <h3>{{ ti.short_name }} <a class="badge simple" href="#{{ ti.id }}" data-tooltip="Aller à {{ ti.name }}">{{ ti.events|length }} {% picto_from_name "chevrons-down" %}</a></h3>
                <ul>
                {% for event in ti.events %}
                    {% if event.is_first_after_now %} 
                    <li class="line-now"><div><div>{% now "H:i" %}</div><div class="line"></div></div></li>
                    {% endif %}
                    <li>{{ event.category | circle_cat:event.has_recurrences }}
                        {% if event.start_time %}
                        {{ event.start_time }}
                        {% endif %}
                        {{ event|picto_status }} <a href="#event-{{ event.id }}">{{ event.title|no_emoji }}</a> {{ event|tw_badge }} 
                    </li>
                {% endfor %}
                {% if forloop.last and cd.is_today_after_events %}
                <li class="line-now"><div><div>{% now "H:i" %}</div><div class="line"></div></div></li>
                {% endif %}
                </ul>
            {% endif %}
            {% endfor %}
        </div>
        {% else %}
        <em>Aucun événement</em>
        {% endif %}
    </article>
    {% for ti in cd.get_time_intervals %}
        {% if ti.events|length > 0 %}
        <article class="day-interval" id="{{ ti.id }}">
            <header class="sticky">
                <a role="button" class="secondary slide-buttons" href="#{{ cd.id }}" data-placement="left" data-tooltip="Retour au résumé de la journée">{% picto_from_name "chevron-up" %}</a>
                <hgroup>
                <h3>{{ ti.name|capfirst }}</h3>
                <h4>{{ ti.date| date:"l j F"|frdate  }}</h4>
                </hgroup>
            </header>
            {% with indexti=cd.id %}
                {% for event in ti.events %}
                {% include "agenda_culturel/single-event/event-elegant-inc.html" with event=event filter=filter day=day indexti=indexti %}
                {% endfor %}
            {% endwith %}
        </article>
        {% endif %}
        {% endfor %}
    
{% endfor %}
<article>
    <header><h2>Voir aussi</h2></header>
    {% if category %}
    <a href="{% if calendar.nb_days == 1 %}{% url 'day_view_category' category.slug date_pred.year date_pred.month date_pred.day %}{% else %}{% url 'a_venir_jour_category' category.slug date_pred.year date_pred.month date_pred.day %}{% endif %}?{{ filter.get_url }}" aria-label="dates précédentes" role="button">
    {% else %}
    <a href="{% if calendar.nb_days == 1 %}{% url 'day_view' date_pred.year date_pred.month date_pred.day %}{% else %}{% url 'a_venir_jour' date_pred.year date_pred.month date_pred.day %}{% endif %}?{{ filter.get_url }}" aria-label="dates précédentes" role="button">
        {% endif %}
        {% picto_from_name "chevrons-left" %}
        {% if calendar.nb_days == 1 %}
            {{ date_pred }}
        {% endif %}
    </a>
    {% if calendar.today_in_calendar %}
    {% if category %}
    <a role="button" href="{% url 'aujourdhui_category' category.slug %}?{{ filter.get_url }}">Aujourd'hui</a>
    {% else %}
    <a role="button" href="{% url 'aujourdhui' %}?{{ filter.get_url }}">Aujourd'hui</a>
    {% endif %}
    {% endif %}
    {% if calendar.nb_days == 1 %}
    {% if category %}
    <a role="button" href="{% url 'a_venir_jour_category' category.slug day.year day.month day.day %}?{{ filter.get_url }}">Autour du {{ day }}</a>
    {% else %}
    <a role="button" href="{% url 'a_venir_jour' day.year day.month day.day %}?{{ filter.get_url }}">Autour du {{ day }}</a>
    {% endif %}
    {% endif %}
    {% if category %}
        <a role="button" href="{% url 'week_view_category' category.slug calendar.firstdate.year calendar.firstdate|week %}?{{ filter.get_url }}">Semaine du {{ calendar.firstdate }}</a>
        <a role="button" href="{% url 'month_view_category' category.slug calendar.firstdate.year calendar.firstdate.month %}?{{ filter.get_url }}">{{ calendar.firstdate | date:"F o" }}</a>
    {% else %}
        <a role="button" href="{% url 'week_view' calendar.firstdate.year calendar.firstdate|week %}?{{ filter.get_url }}">Semaine du {{ calendar.firstdate }}</a>
        <a role="button" href="{% url 'month_view' calendar.firstdate.year calendar.firstdate.month %}?{{ filter.get_url }}">{{ calendar.firstdate | date:"F o" }}</a>
    {% endif %}
    {% if calendar.firstdate.month != calendar.lastdate.month %}
        {% if category %}
        <a role="button" href="{% url 'month_view_category' category.slug calendar.lastdate.year calendar.lastdate.month %}?{{ filter.get_url }}">{{ calendar.lastdate | date:"F o" }}</a>
        {% else %}
        <a role="button" href="{% url 'month_view' calendar.lastdate.year calendar.lastdate.month %}?{{ filter.get_url }}">{{ calendar.lastdate | date:"F o" }}</a>
        {% endif %}
    {% endif %}

    {% if category %}
        <a role="button" data-tooltip="Copiez ce lien et importez-le dans votre agenda" href="{% url 'export_ical_category' category.slug %}?{{ filter.get_url }}">Export ical {% picto_from_name "calendar" %}</a>
    {% else %}
        <a role="button" data-tooltip="Copiez ce lien et importez-le dans votre agenda" href="{% url 'export_ical' %}?{{ filter.get_url }}">Export ical {% picto_from_name "calendar" %}</a>
    {% endif %}

    {% if category %}
    <a href="{% if calendar.nb_days == 1 %}{% url 'day_view_category' category.slug date_next.year date_next.month date_next.day %}{% else %}{% url 'a_venir_jour_category' category.slug date_next.year date_next.month date_next.day %}{% endif %}?{{ filter.get_url }}" aria-label="dates suivantes" role="button">
    {% else %}
    <a href="{% if calendar.nb_days == 1 %}{% url 'day_view' date_next.year date_next.month date_next.day %}{% else %}{% url 'a_venir_jour' date_next.year date_next.month date_next.day %}{% endif %}?{{ filter.get_url }}" aria-label="dates suivantes" role="button">
    {% endif %}
        {% if calendar.nb_days == 1 %}
            {{ date_next }}
        {% endif %}
        {% picto_from_name "chevrons-right" %}
    </a>

</article>

{% endcache %}
{% endwith %}

{% endblock %}