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

<header>
    <div class="slide-buttons">
        <div class="buttons">
            <a href="{% url 'add_place_to_event' event.pk %}" role="button">Ajouter le lieu {% picto_from_name "map-pin" %}</a>
        </div>
    </div>


    <h3>{{ event.category | small_cat_recurrent:event.has_recurrences }} 
    {{ event|picto_status }}
     <a href="{{ event.get_absolute_url }}">
        {{ event.title }}</a>
        {{ event|picto_visibility:user.is_authenticated }}</h3>

        {% 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 %}

    <p>{% picto_from_name "calendar" %}
        {% if event.end_day and event.end_day != event.start_day %}du{% else %}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 %}
    {% if event.has_recurrences %}
        <p>
        {% 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 
        {% if event.recurrences.dtstart.date %}
        {{ event.recurrences.dtstart.date }}
        {% else %}
        {{ event.start_day }}
        {% endif %}
        </p>
    {% endif %}
    {% if event.tags and event.tags|length > 0 %} 
    <p>
        {% picto_from_name "tag" %}
        {% for tag in event.sorted_tags %}
        <a href="{% url 'view_tag' tag|prepare_tag %}">{{ tag|tw_highlight }}</a>
        {% if not forloop.last %}, {% endif %}
        {% endfor %}
    </p>
    {% endif %}
</header>
<div class="description">
        {% if event.description %}{{ event.description |truncatewords:60 }}{% else %}<em>pas de description</em>{% endif %}

    </div>
<footer>
    {% include "agenda_culturel/event-date-info-inc.html" %}
</footer>