{% extends 'base/layout.html' %}

{% block title %}UniFi Sync Runs{% endblock %}

{% block content %}
<div class="card mb-3">
  <div class="card-header"><strong>Filters</strong></div>
  <div class="card-body">
    <form method="get" class="row g-3">
      <div class="col-md-3">{{ form.status.label_tag }} {{ form.status }}</div>
      <div class="col-md-5">{{ form.q.label_tag }} {{ form.q }}</div>
      <div class="col-md-2">{{ form.limit.label_tag }} {{ form.limit }}</div>
      <div class="col-md-2 d-flex align-items-end"><button class="btn btn-primary w-100" type="submit">Apply</button></div>
    </form>
  </div>
</div>

<div class="card">
  <div class="card-header d-flex justify-content-between align-items-center">
    <strong>Run History</strong>
    <span class="text-muted">Total: {{ total }}</span>
  </div>
  <div class="table-responsive">
    <table class="table table-hover mb-0">
      <thead>
        <tr><th>ID</th><th>Created</th><th>Status</th><th>Mode</th><th>Duration</th><th>Controllers</th><th>Sites</th><th>Devices</th><th>Summary</th></tr>
      </thead>
      <tbody>
      {% for run in runs %}
        <tr>
          <td><a href="{% url 'plugins:netbox_unifi_sync:run_detail' run.pk %}">#{{ run.pk }}</a></td>
          <td>{{ run.created }}</td>
          <td>{{ run.get_status_display }}</td>
          <td>{% if run.dry_run %}Dry run{% else %}Sync{% endif %}{% if run.cleanup_requested %} + cleanup{% endif %}</td>
          <td>{{ run.duration_ms }} ms</td>
          <td>{{ run.controllers_total }}</td>
          <td>{{ run.sites_total }}</td>
          <td>{{ run.devices_total }}</td>
          <td>{{ run.summary|default:'-' }}</td>
        </tr>
      {% empty %}
        <tr><td colspan="9" class="text-muted">No runs found.</td></tr>
      {% endfor %}
      </tbody>
    </table>
  </div>
</div>
{% endblock %}
