{% extends 'layout.twig' %}

{% block title %}Blog Visits - Admin{% endblock %}

{% block content %}
  <h1>Blog Visits</h1>

  <h2>Top visitors (by hits)</h2>
  <table class="table">
    <thead>
      <tr><th>IP</th><th>User-Agent</th><th>Count</th><th>First seen</th><th>Last seen</th></tr>
    </thead>
    <tbody>
    {% for v in visitors %}
      <tr>
        <td>{{ v.ip }}</td>
        <td style="max-width:40ch; overflow:hidden; text-overflow:ellipsis; white-space:nowrap">{{ v.useragent }}</td>
        <td>{{ v.cnt }}</td>
        <td>{{ v.first_seen }}</td>
        <td>{{ v.last_seen }}</td>
      </tr>
    {% else %}
      <tr><td colspan="5">No visitors yet</td></tr>
    {% endfor %}
    </tbody>
  </table>

  <h2>Recent detail log</h2>
  <table class="table">
    <thead><tr><th>Timestamp</th><th>IP</th><th>URL</th></tr></thead>
    <tbody>
    {% for d in details %}
      <tr>
        <td>{{ d.timestamp }}</td>
        <td>{{ d.ip }}</td>
        <td style="max-width:60ch; overflow:hidden; text-overflow:ellipsis; white-space:nowrap">{{ d.url }}</td>
      </tr>
    {% else %}
      <tr><td colspan="3">No details</td></tr>
    {% endfor %}
    </tbody>
  </table>

{% endblock %}
