{% load i18n passerelle tz gadjo %}

{% if logrecords %}
  <table class="main" id="table-logs" data-log-base-url="{% url 'view-logs-connector' connector=object.get_connector_slug slug=object.slug %}" >
    <thead>
      <th>{% trans 'Timestamp' %}</th>
      <th>{% trans 'Source IP' %}</th>
      <th>{% trans 'Message' %}</th>
    </thead>
    <tbody>
      {% for record in logrecords %}
        <tr class="level-{{record.level}}" data-pk="{{ record.pk }}">
          <td class="timestamp">
            {{ record.timestamp|localtime|date:'DATE_FORMAT' }}
            {{ record.timestamp|localtime|time:"H:i:s" }}
          </td>
          <td>{{ record.sourceip|default:"-" }}</td>
          <td class="message">{{ record.message|censor }}</td>
        </tr>
      {% endfor %}
    </tbody>
  </table>

  {% with page_obj=logrecords anchor="#table-logs" without_key="log_id" page_key=page_key|default:"page" %}
    {% if page_obj.has_next or page_obj.has_previous %}
      {% spaceless %}
        <p class="paginator">
          {% if page_obj.number > 1 %}
            {% if page_obj.previous_page_number != 1 %}
              <a href="{% querystring page_key=1 without without_key %}{{ anchor }}">1</a>
              …
            {% endif %}
          {% endif %}

          {% if page_obj.has_previous %}
            <a href="{% querystring page_key=page_obj.previous_page_number without without_key %}{{ anchor }}">{{ page_obj.previous_page_number }}</a>
          {% endif %}

          <span class="this-page">{{ page_obj.number }}</span>

          {% if page_obj.has_next %}
            <a href="{% querystring page_key=page_obj.next_page_number without without_key %}{{ anchor }}">{{ page_obj.next_page_number }}</a>
            …
          {% endif %}
        </p>
      {% endspaceless %}
    {% endif %}
  {% endwith %}

{% else %}
  <p>{% trans 'No records found' %}</p>
{% endif %}
