{% extends "base.html" %}
{% set active_nav = "workers" %}
{% block title %}{{ name }} — Loom Workshop{% endblock %}
{% block content %}
<hgroup>
    <h1>{{ name }}</h1>
    <p>{{ config.description or 'No description' }} &middot; <kbd>{{ config.get('worker_kind', 'llm') }}</kbd> &middot; tier: <kbd>{{ config.get('default_model_tier', '—') }}</kbd></p>
</hgroup>

<div class="grid">
    <div>
        <a href="/workers/{{ name }}/test" role="button" class="outline">Test Bench</a>
    </div>
    <div>
        <a href="/workers/{{ name }}/eval" role="button" class="outline">Eval Dashboard</a>
    </div>
    <div>
        <form method="post" action="/workers/{{ name }}/clone" style="display:inline">
            <fieldset role="group">
                <input type="text" name="new_name" placeholder="clone_name" required aria-label="Clone name">
                <button type="submit" class="outline">Clone</button>
            </fieldset>
        </form>
    </div>
</div>

<h2>Pipeline Impact</h2>
<div id="impact-panel"
     hx-get="/workers/{{ name }}/impact-panel"
     hx-trigger="load"
     hx-swap="innerHTML">
    <small class="htmx-indicator" aria-busy="true">Analyzing impact&hellip;</small>
</div>

<h2>Config (YAML)</h2>
<form method="post" action="/workers/{{ name }}" id="worker-form">
    <label for="yaml_content">Worker configuration</label>
    <textarea name="yaml_content" id="yaml_content" rows="25"
              hx-post="/workers/{{ name }}/validate"
              hx-target="#validation-feedback"
              hx-trigger="input changed delay:500ms"
              hx-swap="innerHTML"
              hx-include="[name='yaml_content']">{{ yaml_content }}</textarea>
    <div id="validation-feedback" aria-live="polite"></div>
    <label for="description">Version note</label>
    <input type="text" name="description" id="description" placeholder="Optional version note">
    <button type="submit">Save</button>
</form>

{% if versions %}
<h2>Version History</h2>
<div class="table-wrap">
<table>
    <thead>
        <tr><th scope="col">Hash</th><th scope="col">Date</th><th scope="col">Note</th></tr>
    </thead>
    <tbody>
        {% for v in versions %}
        <tr>
            <td><code>{{ v.config_hash[:8] }}</code></td>
            <td>{{ v.created_at }}</td>
            <td>{{ v.description or '—' }}</td>
        </tr>
        {% endfor %}
    </tbody>
</table>
</div>
{% endif %}
{% endblock %}
