{% extends 'base.html' %}
{% block title %}Run #{{ run.display_id }} - TLS Analyzer{% endblock %}
{% block content %}
<div class="card">
    <h2>Run #{{ run.display_id }} — {{ run.created_at|date:"Y-m-d H:i" }}</h2>
    <p>Status: <span class="badge {% if run.status == 'completed' %}badge-success{% elif run.status == 'failed' %}badge-danger{% else %}badge-info{% endif %}">{{ run.get_status_display }}</span></p>
    <p>CSV: <code>{% if run.sqlite_table %}已存储至SQLite: {{ run.sqlite_table }}{% else %}{{ run.csv_glob }}{% endif %}</code></p>
</div>

<div class="grid-3">
    <div class="card" style="text-align:center;">
        <div class="stat">{{ run.total_flows|default:"0" }}</div>
        <div class="stat-label">Total Flows</div>
    </div>
    <div class="card" style="text-align:center;">
        <div class="stat">{{ run.entity_count|default:"0" }}</div>
        <div class="stat-label">Entities</div>
    </div>
    <div class="card" style="text-align:center;">
        <div class="stat">{{ run.cluster_count|default:"0" }}</div>
        <div class="stat-label">Clusters</div>
    </div>
</div>

<div class="card">
    <h2>Clusters</h2>
    <a href="{% url 'analysis:cluster_overview' run.display_id %}" class="btn btn-primary" style="margin-bottom:1rem;">View Cluster Overview</a>
    {% if clusters %}
    <table>
        <thead>
            <tr>
                <th>Cluster</th>
                <th>Size</th>
                <th>Proportion</th>
                <th>Silhouette</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            {% for c in clusters %}
            <tr>
                <td><span class="badge badge-info">#{{ c.cluster_label }}</span></td>
                <td>{{ c.size }}</td>
                <td>{{ c.proportion|floatformat:2 }}</td>
                <td>{{ c.silhouette_score|floatformat:4|default:"-" }}</td>
                <td><a href="{% url 'analysis:cluster_detail' run.display_id c.cluster_label %}" class="btn btn-primary">Detail</a></td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    {% else %}
    <div class="empty-state"><p>No clusters yet.</p></div>
    {% endif %}
</div>
{% endblock %}
