{% extends "website/base.html" %}
{% block content %}
<section class="section">
  <div class="grid-2">
    <div class="card">
      <div class="card-title">
        <div class="icon">📊</div>
        <div>
          <h1 class="h1" style="margin:0">Support Analytics</h1>
          <div class="small">Live overview of tickets and SLA performance.</div>
        </div>
      </div>
      <div class="sep"></div>
      <div class="grid-3">
        <div class="card soft card-tight">
          <div class="small">Open</div>
          <div style="font-size:28px;font-weight:1000">{{ open_count }}</div>
        </div>
        <div class="card soft card-tight">
          <div class="small">Pending</div>
          <div style="font-size:28px;font-weight:1000">{{ pending_count }}</div>
        </div>
        <div class="card soft card-tight">
          <div class="small">Closed</div>
          <div style="font-size:28px;font-weight:1000">{{ closed_count }}</div>
        </div>
      </div>

      <div class="grid-2" style="margin-top:12px">
        <div class="card soft card-tight">
          <div class="small">Avg first response (mins)</div>
          <div style="font-size:24px;font-weight:1000">{{ avg_first_response|default:"—" }}</div>
        </div>
        <div class="card soft card-tight">
          <div class="small">SLA missed (awaiting first response)</div>
          <div style="font-size:24px;font-weight:1000">{{ sla_missed }}</div>
        </div>
      </div>

      <div style="display:flex;gap:10px;flex-wrap:wrap;margin-top:14px">
        <a class="btn btn-primary" href="{% url 'website:staff_support_dashboard' %}">Back to tickets</a>
      </div>
    </div>

    <div class="card">
      <div class="card-title">
        <div class="icon">🕒</div>
        <div>
          <h2 class="h2" style="margin:0">Recent tickets</h2>
          <div class="small">Quick glance at latest activity.</div>
        </div>
      </div>
      <div class="sep"></div>
      <div style="display:grid;gap:10px">
        {% for t in recent %}
          <a class="card soft card-tight" href="{% url 'website:staff_support_ticket' t.public_id %}" style="text-decoration:none;color:inherit">
            <div style="display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap">
              <strong>#{{ t.public_id }}</strong>
              <span class="small">{{ t.created_at|date:"M d, H:i" }}</span>
            </div>
            <div style="margin-top:4px">{{ t.subject }}</div>
            <div class="small" style="margin-top:4px">
              {{ t.full_name }} • Status: <strong>{{ t.get_status_display }}</strong>
              {% if t.assigned_to %} • Assigned: <strong>{{ t.assigned_to.username }}</strong>{% endif %}
            </div>
          </a>
        {% empty %}
          <div class="small">No tickets yet.</div>
        {% endfor %}
      </div>
    </div>
  </div>
</section>
{% endblock %}
