{% extends "base.html" %}
{% block title %}Partitions — Drakkar Debug{% endblock %}

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

<table class="w-full text-sm">
    <thead>
        <tr class="text-left text-gray-400 border-b border-cream-200">
            <th class="py-2 px-3">Partition</th>
            <th class="py-2 px-3">Status</th>
            <th class="py-2 px-3">Last Consumed</th>
            <th class="py-2 px-3">Last Committed</th>
            <th class="py-2 px-3">Committed</th>
            <th class="py-2 px-3">High WM</th>
            <th class="py-2 px-3">Lag</th>
            <th class="py-2 px-3">Queue</th>
            <th class="py-2 px-3">Pending</th>
            <th class="py-2 px-3">Consumed</th>
            <th class="py-2 px-3">Completed</th>
            <th class="py-2 px-3">Failed</th>
        </tr>
    </thead>
    <tbody>
        {% for s in summary %}
        <tr class="border-b border-cream-100 hover:bg-cream-100">
            <td class="py-2 px-3">
                <a href="/partitions/{{ s.partition }}" class="text-teal-600 hover:underline font-mono">{{ s.partition }}</a>
            </td>
            <td class="py-2 px-3">
                {% if s.is_live %}
                <span class="inline-block w-2 h-2 bg-emerald-400 rounded-full"></span> live
                {% else %}
                <span class="inline-block w-2 h-2 bg-gray-300 rounded-full"></span> history
                {% endif %}
            </td>
            <td class="py-2 px-3 text-gray-400" title="{{ format_ts_ms(s.last_consumed) }}">{{ format_ts(s.last_consumed) }}</td>
            <td class="py-2 px-3 text-gray-400" title="{{ format_ts_ms(s.last_committed) }}">{{ format_ts(s.last_committed) }}</td>
            <td class="py-2 px-3 font-mono">{{ s.committed_offset or '-' }}</td>
            <td class="py-2 px-3 font-mono">{{ s.high_watermark or '-' }}</td>
            <td class="py-2 px-3 font-mono {% if s.lag > 20 %}text-red-600{% elif s.lag > 5 %}text-amber-600{% else %}text-emerald-600{% endif %}">{{ s.lag }}</td>
            <td class="py-2 px-3 font-mono">{{ s.queue_size }}</td>
            <td class="py-2 px-3 font-mono">{{ s.pending_offsets }}</td>
            <td class="py-2 px-3 font-mono">{{ s.consumed_count }}</td>
            <td class="py-2 px-3 font-mono text-emerald-600">{{ s.completed_count }}</td>
            <td class="py-2 px-3 font-mono {% if s.failed_count > 0 %}text-red-600{% endif %}">{{ s.failed_count }}</td>
        </tr>
        {% endfor %}
        {% if not summary %}
        <tr><td colspan="12" class="py-4 text-center text-gray-400">No partition data recorded yet</td></tr>
        {% endif %}
    </tbody>
</table>
{% endblock %}
