<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Oxanus Dashboard</title>
    <script src="https://cdn.tailwindcss.com"></script>

</head>
<body class="bg-gray-950 text-gray-100 min-h-screen">
    <div class="max-w-[88rem] mx-auto px-4 sm:px-6 lg:px-8 py-8">
        <div class="mb-6">
            <h1 class="text-2xl font-bold tracking-tight">Oxanus Dashboard</h1>
        </div>

        {% include "_tabs.html" %}

        {% include "_stats_cards.html" %}

        <section class="mb-10">
            <h2 class="text-lg font-semibold mb-4">Active Processes ({{ stats.processes.len() }})</h2>
            {% if stats.processes.is_empty() %}
            <div class="bg-gray-900 border border-gray-800 rounded-lg p-6 text-center text-gray-500">
                No active processes
            </div>
            {% else %}
            <div class="overflow-x-auto">
                <table class="w-full text-sm">
                    <thead>
                        <tr class="border-b border-gray-800 text-left text-xs text-gray-400 uppercase tracking-wide">
                            <th class="pb-3 pr-4">Hostname</th>
                            <th class="pb-3 pr-4">PID</th>
                            <th class="pb-3 pr-4 text-right">Busy</th>
                            <th class="pb-3 pr-4">Started</th>
                            <th class="pb-3">Last Heartbeat</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for process in &stats.processes %}
                        <tr class="border-b border-gray-800/50 hover:bg-gray-900/50">
                            <td class="py-3 pr-4 font-mono text-sm">{{ process.hostname }}</td>
                            <td class="py-3 pr-4 font-mono">{{ process.pid }}</td>
                            <td class="py-3 pr-4 text-right text-purple-400">{{ self.busy_for_process(process) }}</td>
                            <td class="py-3 pr-4 text-gray-400">{{ process.started_at|relative_time }}</td>
                            <td class="py-3 text-gray-400">{{ process.heartbeat_at|relative_time }}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            {% endif %}
        </section>

        <section>
            <h2 class="text-lg font-semibold mb-4">Queues ({{ stats.queues.len() }})</h2>
            {% if stats.queues.is_empty() %}
            <div class="bg-gray-900 border border-gray-800 rounded-lg p-6 text-center text-gray-500">
                No queues
            </div>
            {% else %}
            <div class="overflow-x-auto">
                <table class="w-full text-sm">
                    <thead>
                        <tr class="border-b border-gray-800 text-left text-xs text-gray-400 uppercase tracking-wide">
                            <th class="pb-3 pr-4">Queue</th>
                            <th class="pb-3 pr-4 text-right">Concurrency</th>
                            <th class="pb-3 pr-4 text-right">Busy</th>
                            <th class="pb-3 pr-4 text-right">Enqueued</th>
                            <th class="pb-3 text-right">Latency</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for queue in &stats.queues %}
                        <tr class="border-b border-gray-800/50 hover:bg-gray-900/50">
                            <td class="py-3 pr-4 font-mono text-sm">{% if queue.queues.is_empty() %}<a href="{{ base_path }}/queues/{{ queue.key|urlencode }}" class="text-blue-400 hover:text-blue-300 hover:underline">{{ queue.key }}</a>{% else %}{{ queue.key }}{% endif %}</td>
                            <td class="py-3 pr-4 text-right text-gray-400">{{ self.concurrency_for(&queue.key) }}</td>
                            <td class="py-3 pr-4 text-right text-purple-400">{{ self.busy_for(&queue.key) }}</td>
                            <td class="py-3 pr-4 text-right text-blue-400">{{ queue.enqueued }}</td>
                            <td class="py-3 text-right text-purple-400">{{ queue.latency_s|format_latency }}</td>
                        </tr>
                        {% for dq in &queue.queues %}
                        {% if dq.enqueued > 0 %}
                        <tr class="border-b border-gray-800/50 hover:bg-gray-900/50 text-gray-500">
                            <td class="py-2 pr-4 pl-10 font-mono text-xs">&#8627; <a href="{{ base_path }}/queues/{{ queue.key }}%23{{ dq.suffix|urlencode }}" class="text-blue-400 hover:text-blue-300 hover:underline">{{ dq.suffix }}</a></td>
                            <td class="py-2 pr-4 text-right text-xs text-gray-500">{{ self.concurrency_for(&queue.key) }}</td>
                            <td class="py-2 pr-4 text-right text-xs text-purple-400"></td>
                            <td class="py-2 pr-4 text-right text-xs text-blue-400">{{ dq.enqueued }}</td>
                            <td class="py-2 text-right text-xs text-purple-400">{{ dq.latency_s|format_latency }}</td>
                        </tr>
                        {% endif %}
                        {% endfor %}
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            {% endif %}
        </section>
    </div>
</body>
</html>
