{% load static %}
{% load cat_extra %}
{% load utils_extra %}
{% load event_extra %}
{% load tag_extra %}

<article id="event-{{ event.pk}}" class="single-event {% if not event.image and not event.local_image %}no-image{% endif %}  status_{{ event.status }}">
    <header class="head">
        {% if day == 0 %}
        <div class="small-ephemeride">
            {% include "agenda_culturel/ephemeris-inc.html" with event=event filter=filter %}
        </div>
        {% else %}
            {% if event|can_show_start_time:day %}
                {% if event.start_time %}
                <article class='ephemeris-hour'>
                        <span class="large">{{ event.start_time }}</span>
                </article>
                {% endif %}
            {% endif %}
            {% if event|can_show_end_time:day %}
                {% if event.end_time %}
                <article class='ephemeris-hour'>
                        jusqu'à <span class="large">{{ event.end_time }}</span>
                </article>
                {% endif %}
            {% endif %}
        {% endif %}
    <div class="header-complement">
    {{ event.category | small_cat_recurrent:event.has_recurrences }}
    
        {% if event.location or event.exact_location %}<hgroup>{% endif %}
                <h4>
                {{ event|picto_status }}    
                <a href="{{ event.get_absolute_url }}">{{ event.title }}</a>
                {{ event|picto_visibility:user.is_authenticated }}
            </h4>
        {% if event.location or event.exact_location %}
        {% if not no_location %}
        <h5>
            {% picto_from_name "map-pin" %}

            {% if event.exact_location %}
                <a href="{{ event.exact_location.get_absolute_url }}">{{ event.exact_location.name }}, {{ event.exact_location.city }}</a>
            {% else %}
                {% if perms.agenda_culturel.change_event and perms.agenda_culturel.change_place %}
                <a href="{% url 'add_place_to_event' event.pk %}" class="missing-data">{{ event.location }}</a>
                {% else %}
                {{ event.location }}
                {% endif %}
            {% endif %}
            </h5>
            {% endif %}
        </hgroup>
    {% endif %}



    {% if event|need_complete_display:True %}<p>
            {% picto_from_name "calendar" %}
    
            <em>{% if event.end_day and event.end_day != event.start_day %}Cet événement dure du {% else %}Cet événement a lieu le{% endif %}
                {{ event.start_day|date|frdate }} 
                {% if event.start_time %} {% if not event.end_day or event.end_day == event.start_day %}{% if event.end_time %}de{% else %}à{% endif %}{% endif %}
                    {{ event.start_time }}
                {% endif %}
                {% if event.end_day and event.end_day != event.start_day %}
                    au {% if event.end_day and event.end_day != event.start_day %}{{ event.end_day|date|frdate }}{% endif %}
                {% endif %}
                {% if event.end_time %} {% if not event.end_day|date|frdate or event.end_day == event.start_day %}jusqu'à{% endif %} {{ event.end_time }}{% endif %}
            </em></p>
        {% endif %}
        <div class="infos">
            <p>
                {% for tag in event.sorted_tags %}
                <a href="{% url 'view_tag' tag|prepare_tag %}" role="button" class="small-cat">{{ tag|tw_highlight }}</a>
                {% endfor %}
            </p>

            {% if event.has_recurrences %}
            <p class="footer">
            {% picto_from_name "repeat" %}
            <!-- TODO: see https://forge.chapril.org/jmtrivial/agenda_culturel/issues/65 -->
            {% for r in event.recurrences.rrules %}
            {{ r.to_text }}{% if not forloop.first %}, {% endif %}{% endfor %}, depuis le {{ event.recurrences.dtstart.date }}
            </p>
            {% endif %}
        </div>
    </div>

        <div class="buttons" style="clear: both">
            {% if perms.agenda_culturel.change_event %}
            {% include "agenda_culturel/edit-buttons-inc.html" with event=event details=0 %}
            {% endif %}
        </div>
    </header>

    <div class="description">
        <div class="texte">
            {{ event.description |linebreaks2 | truncatewords:60 }}
        </div>
        <div class="right bottom">
            <a role="button" href="{{ event.get_absolute_url }}">Voir l'événement {% picto_from_name "chevron-right" %}
            </svg></a>
        </div>
    </div>

    {% if event.image or event.local_image %}
    <div>
        <article class='illustration'>
            <img src="{% if event.local_image %}{{ event.local_image.url }}{% else %}{{ event.image }}{% endif %}" alt="{{ event.image_alt }}" />
        </article>
    </div>
    <div style="clear: both"></div>
    {% endif %}

</article>

