{% extends "base.html" %}
{% import "macros/ui.html" as m %}
{% block title %}Dashboard{% endblock %}
{% block nav_dashboard %}btn-active{% endblock %}

{% block content %}
<h1 class="text-2xl font-bold font-mono mb-6">Dashboard</h1>

<div class="stats stats-horizontal shadow bg-base-200 w-full mb-6">
  {{ m::stat(title="Tools", value=tool_count, desc="registered in Registry") }}
  {{ m::stat(title="Invocations", value=total_invocations, desc="since startup", accent="primary") }}
  {{ m::stat(title="Sessions", value=active_sessions, desc="active") }}
  {% if secs_since_reload %}
  {{ m::stat(title="Config reload", value=secs_since_reload ~ "s", desc="seconds ago") }}
  {% else %}
  {{ m::stat(title="Config reload", value="—", desc="not reloaded") }}
  {% endif %}
</div>

<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">

  <div class="card bg-base-200 shadow">
    <div class="card-body">
      <h2 class="card-title text-sm font-mono">Recent Invocations</h2>
      {% if recent %}
      <div class="overflow-x-auto">
        <table class="table table-xs">
          <thead>
            <tr><th>Tool</th><th>Status</th><th>Duration</th><th>When</th></tr>
          </thead>
          <tbody>
            {% for r in recent %}
            <tr>
              <td><a href="/ui/tools/{{ r.tool }}" class="link link-hover font-mono text-xs">{{ r.tool }}</a></td>
              <td>{{ m::outcome_badge(record=r) }}</td>
              <td>{{ m::duration(ms=r.duration_ms) }}</td>
              <td class="text-base-content/50 text-xs">{{ r.invoked_at }}</td>
            </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>
      {% else %}
      <p class="text-base-content/40 text-sm">No invocations yet.</p>
      {% endif %}
    </div>
  </div>

  <div class="card bg-base-200 shadow">
    <div class="card-body">
      <h2 class="card-title text-sm font-mono">Quick Links</h2>
      <div class="flex flex-col gap-2 mt-2">
        <a href="/ui/tools" class="btn btn-sm btn-outline">Browse {{ tool_count }} tools</a>
        <a href="/ui/workspaces" class="btn btn-sm btn-outline">Workspaces</a>
        <a href="/ui/jobs" class="btn btn-sm btn-outline">Orchestrator jobs</a>
        <a href="/ui/extensions" class="btn btn-sm btn-outline">Extensions</a>
        <a href="/ui/modes" class="btn btn-sm btn-outline">Reflection modes</a>
        <a href="/ui/ontology" class="btn btn-sm btn-outline">Domain ontology graph</a>
      </div>
    </div>
  </div>

</div>
{% endblock %}
