{% extends 'iconolab/user_base.html' %}

{% load staticfiles %}
{% load thumbnail %}
{% load iconolab_tags %}
{% load notifications_tags %}

{% block user_content %}

  {% notifications_unread as unread_count %}
  <h2>
    Mes notifications
    {% if unread_count %} <a class="btn btn-success pull-right" href="{% url 'user_notifications' %}?clear_notifications">
    <i class="fa fa-check"></i> Tout marquer comme lu</a>
    {% endif %}
  </h2>
  <hr>

  {% if notifications %}
    <ul class="list-group">
    {% for notification in notifications %}
      <a
        {% if notification.target and notification.action_object %}
          {% with notification.target as annotation %}
            class="list-group-item {% if notification.id in notifications_unread_ids %}list-group-item-info{% endif %}"
            {% if notification.action_object.get_comment_page %}
            href="{% url 'annotation_detail' annotation.image.item.collection.name annotation.image.image_guid annotation.annotation_guid %}?page={{notification.action_object.get_comment_page}}#c{{notification.action_object.id}}"
            {% else %}
            href="{% url 'revision_detail' annotation.image.item.collection.name annotation.image.image_guid annotation.annotation_guid notification.action_object.revision_guid %}"
            {% endif %}
          {% endwith %}
        {% else %}
          class="list-group-item disabled {% if forloop.counter > 5 %}hide-on-load{% endif %}"
        {% endif %}>
        <b>{{notification.actor.username}}</b> {{notification.verb}} <small> - {{notification.timesince}}</small>
      </a>
    {% endfor %}
    </ul>

    {% if notifications.has_previous or notifications.has_next %}
    <ul class="pagination pull-right">
      {% if notifications.has_previous %}
      <li>
        <a href="{% url 'user_notifications' %}?page={{notifications.previous_page_number}}" aria-label="Previous">
          <span aria-hidden="true">&laquo;</span>
        </a>
      </li>
      {% endif %}
      {% for page in notifications.paginator.page_range %}
        <li id="page-link-{{page}}" class="pagination-link {% if page == notifications.number %}active{% endif %}">
          <a {% if page != notifications.number %}href="{% url 'user_notifications' %}?page={{page}}"{% endif %}>{{page}}</a>
        </li>
      {% endfor %}
      {% if notifications.has_next %}
      <li>
        <a href="{% url 'user_notifications' %}?page={{notifications.next_page_number}}" aria-label="Next">
          <span aria-hidden="true">&raquo;</span>
        </a>
      </li>
      {% endif %}
    </ul>
    {% endif %}
  {% endif %}
{% endblock %}
