{% extends "base.html" %}

{% block title %}{{ db_name }} - KenobiX Explorer{% endblock %}

{% block content %}
<hgroup>
  <h1>Database Overview</h1>
  <p>{{ db_path }}</p>
</hgroup>

<!-- Stats cards -->
<div class="stats-grid">
  <article>
    <header>Collections</header>
    <strong>{{ collections | length }}</strong>
  </article>
  <article>
    <header>Total Documents</header>
    <strong>{{ "{:,}".format(total_docs) }}</strong>
  </article>
  <article>
    <header>Database Size</header>
    <strong>{% if db_size < 1024 %}{{ db_size }} B{% elif db_size < 1048576 %}{{ "%.1f"|format(db_size / 1024) }} KB{% else %}{{ "%.2f"|format(db_size / 1048576) }} MB{% endif %}</strong>
  </article>
</div>

<h2>Collections</h2>

{% if collections %}
<figure>
  <table>
    <thead>
      <tr>
        <th scope="col">Name</th>
        <th scope="col">Documents</th>
        <th scope="col">Indexed Fields</th>
        <th scope="col"></th>
      </tr>
    </thead>
    <tbody>
      {% for coll in collections %}
      <tr>
        <td><a href="/collection/{{ coll.name }}"><strong>{{ coll.name }}</strong></a></td>
        <td>{{ "{:,}".format(coll.count) }}</td>
        <td>
          {% if coll.indexed %}
            {% for field in coll.indexed %}
            <span class="badge">{{ field }}</span>
            {% endfor %}
          {% else %}
            <small style="color: var(--pico-muted-color);">none</small>
          {% endif %}
        </td>
        <td><a href="/collection/{{ coll.name }}" role="button" class="outline secondary">Browse</a></td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
</figure>
{% else %}
<article>
  <p>No collections found in this database.</p>
</article>
{% endif %}
{% endblock %}
