{% extends "base.html" %}
{% set active_nav = "workers" %}
{% block title %}Eval Run {{ run.id[:8] }} — Loom Workshop{% endblock %}
{% block content %}
<hgroup>
    <h1>Eval Run <code>{{ run.id[:8] }}</code></h1>
    <p>Worker: <a href="/workers/{{ name }}">{{ name }}</a> &middot;
       Tier: <kbd>{{ run.tier }}</kbd> &middot;
       Status: {{ run.status }} &middot;
       {{ run.passed_cases }}/{{ run.total_cases }} passed</p>
</hgroup>

<progress value="{{ run.passed_cases }}" max="{{ run.total_cases }}"
          aria-label="{{ run.passed_cases }} of {{ run.total_cases }} cases passed"></progress>

<div class="table-wrap">
<table>
    <thead>
        <tr>
            <th scope="col">Case</th>
            <th scope="col">Result</th>
            <th scope="col">Score</th>
            <th scope="col">Latency</th>
            <th scope="col">Tokens</th>
            <th scope="col">Error</th>
        </tr>
    </thead>
    <tbody>
        {% for r in results %}
        <tr>
            <td>{{ r.case_name }}</td>
            <td>
                {% if r.passed %}
                <mark data-status="pass">PASS</mark>
                {% else %}
                <mark data-status="fail">FAIL</mark>
                {% endif %}
            </td>
            <td>{{ '%.2f' | format(r.score or 0) }}</td>
            <td>{{ r.latency_ms or '—' }}ms</td>
            <td>{{ r.prompt_tokens or 0 }}+{{ r.completion_tokens or 0 }}</td>
            <td>{{ r.error or '—' }}</td>
        </tr>
        {% endfor %}
    </tbody>
</table>
</div>

{% for r in results %}
<details>
    <summary>{{ r.case_name }} — details</summary>
    <div class="grid">
        <div>
            <h4>Input</h4>
            <pre><code>{{ r.input_payload if r.input_payload is string else (r.input_payload | tojson(indent=2)) }}</code></pre>
        </div>
        <div>
            <h4>Expected</h4>
            <pre><code>{{ r.expected_output if r.expected_output is string else (r.expected_output | tojson(indent=2) if r.expected_output else '—') }}</code></pre>
        </div>
        <div>
            <h4>Actual</h4>
            <pre><code>{{ r.actual_output if r.actual_output is string else (r.actual_output | tojson(indent=2) if r.actual_output else '—') }}</code></pre>
        </div>
    </div>
</details>
{% endfor %}

<p><a href="/workers/{{ name }}/eval">&larr; Back to eval dashboard</a></p>
{% endblock %}
