<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Job: {{ job_id }} - Oxana</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="flex items-center justify-between mb-6">
            <h1 class="text-2xl font-bold tracking-tight">Oxana Dashboard</h1>
        </div>

        {% include "_tabs.html" %}

        {% match job %}
        {% when Some with (job) %}
        <div class="flex items-center justify-between mb-4">
            <div>
                <h2 class="text-lg font-semibold">
                    <a href="{{ base_path }}/metrics/job?worker={{ job.job.name|urlencode }}" class="text-blue-400 hover:text-blue-300 hover:underline">{{ job.job.name }}</a>
                </h2>
                <div class="mt-1 text-xs text-gray-500 font-mono break-all">{{ job.id }}</div>
            </div>
            {% if is_dead %}
            <span class="px-2 py-1 rounded bg-red-900/50 border border-red-800 text-red-300 text-xs">Dead</span>
            {% endif %}
        </div>

        <div class="bg-gray-900 border border-gray-800 rounded-lg p-4">
            <div class="grid grid-cols-1 sm:grid-cols-4 gap-2 text-xs text-gray-400">
                <div>
                    <span class="text-gray-500">Queue:</span>
                    <a href="{{ base_path }}/queues/{{ job.queue|urlencode }}" class="ml-1 text-blue-400 hover:text-blue-300 hover:underline">{{ job.queue }}</a>
                </div>
                <div>
                    <span class="text-gray-500">Retries:</span>
                    <span class="ml-1 text-gray-300">{{ job.meta.retries }}</span>
                </div>
                <div>
                    <span class="text-gray-500">Created:</span>
                    <span class="ml-1 text-gray-300">{{ job.meta.created_at|relative_time_micros }}</span>
                </div>
                <div>
                    <span class="text-gray-500">Scheduled:</span>
                    <span class="ml-1 text-gray-300">{{ job.meta.scheduled_at|relative_time_micros }}</span>
                </div>
                <div>
                    <span class="text-gray-500">Started:</span>
                    <span class="ml-1 text-gray-300">{{ job.meta.started_at|relative_time_micros_opt }}</span>
                </div>
                <div>
                    <span class="text-gray-500">Unique:</span>
                    <span class="ml-1 text-gray-300">{{ job.meta.unique }}</span>
                </div>
                <div>
                    <span class="text-gray-500">Resurrect:</span>
                    <span class="ml-1 text-gray-300">{{ job.meta.resurrect }}</span>
                </div>
                <div>
                    <span class="text-gray-500">Throttle cost:</span>
                    <span class="ml-1 text-gray-300">
                        {% match job.meta.throttle_cost %}
                        {% when Some with (cost) %}{{ cost }}
                        {% when None %}&mdash;
                        {% endmatch %}
                    </span>
                </div>
            </div>

            {% let arg_pills = job.job.args|simple_args %}
            {% include "_arg_pills.html" %}
            {% if job.job.args|show_args_json %}
            <details class="mt-3" open>
                <summary class="text-xs text-gray-500 cursor-pointer hover:text-gray-300">Arguments</summary>
                <pre class="mt-2 text-xs bg-gray-950 rounded p-3 overflow-x-auto text-gray-300 border border-gray-800">{{ job.job.args|pretty_json }}</pre>
            </details>
            {% endif %}

            {% match job.meta.state %}
            {% when Some with (state) %}
            {% if state|show_job_progress %}
            {% let progress_started_at = job.meta.started_at %}
            {% include "_job_progress.html" %}
            {% else %}
            <details class="mt-3" open>
                <summary class="text-xs text-gray-500 cursor-pointer hover:text-gray-300">State</summary>
                <pre class="mt-2 text-xs bg-gray-950 rounded p-3 overflow-x-auto text-gray-300 border border-gray-800">{{ state|pretty_json }}</pre>
            </details>
            {% endif %}
            {% when None %}
            {% endmatch %}

            {% match job.meta.error %}
            {% when Some with (error) %}
            <details class="mt-3" open>
                <summary class="text-xs text-red-400 cursor-pointer hover:text-red-300">Error</summary>
                <pre class="mt-2 text-xs bg-gray-950 rounded p-3 overflow-x-auto text-red-300 border border-red-900/50">{{ error }}</pre>
            </details>
            {% when None %}
            {% endmatch %}
        </div>
        {% when None %}
        <div class="bg-gray-900 border border-gray-800 rounded-lg p-6 text-center text-gray-500">
            No job found for <span class="font-mono">{{ job_id }}</span>
        </div>
        {% endmatch %}
    </div>
</body>
</html>
