{% load utils_extra %}
{% load cat_extra %}
{% load tag_extra %}
{% load event_extra %}
<article class="status_{{ event.status }}">
  <header>
    <h3>
      {{ event.category | small_cat_recurrent:event.has_recurrences }}
      {{ event|picto_status }} <a href="{{ event.get_absolute_url }}">
      {% if event.title_hl %}
        {{ event.title_hl | safe }}
      {% else %}
        {{ event.title }}
      {% endif %}
    </a>
    {{ event|picto_visibility:user.is_authenticated }}
  </h3>
  <p class="subentry-search">
    {% 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 %}
  </p>
  <p class="subentry-search">
    {% if not no_location %}
      {% if event.location or event.exact_location %}
        {% 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 'set_place_to_event' event.pk %}" class="missing-data">{{ event.location }}</a>
          {% else %}
            {{ event.location }}
          {% endif %}
        {% endif %}
      {% endif %}
    {% endif %}
  </p>
  {% if event.local_event %}
    <p class="subentry-search">
      <em>Événement de portée locale</em>
    </p>
  {% endif %}
  {% if event.has_recurrences %}
    <p class="subentry-search">
      {% picto_from_name "repeat" %}
      {% if event.recurrences.rrules %}
        {% 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 %}
      {% endif %}
      {% if event.recurrences.rdates %}
        les {{ event.recurrences.dtstart.date }}
        {% for d in event.recurrences.rdates %}
          {% if forloop.last %}
            et
          {% else %}
            ,
          {% endif %}
          {{ d.date }}
        {% endfor %}
      {% endif %}
    </p>
  {% endif %}
</header>
{% if event.tags %}
  <p class="subentry-search">
    {% 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 %}
<div class="description">
  {% if event.description_hl %}
    {{ event.description_hl | safe }} [...]
  {% else %}
    {% if event.description %}
      {{ event.description |truncatewords:60 }}
    {% else %}
      <em>pas de description</em>
    {% endif %}
  {% endif %}
</div>
{% if perms.agenda_culturel.change_event %}
  <footer>
    <div class="buttons">
      {% include "agenda_culturel/event-date-info-inc.html" %}
      {% include "agenda_culturel/edit-buttons-inc.html" with event=event details=0 %}
    </div>
  </footer>
{% endif %}
</article>
