{% extends "base.html" %}
{% block title %}Evaluation {{ eval.commit_short }} - circus{% endblock %}
{% block auth %}
    {% if !auth_name.is_empty() %}
        <span class="auth-user">{{ auth_name }}</span>
        <form method="POST" action="/logout">
            <button class="btn-ghost" type="submit">Logout</button>
        </form>
    {% else %}
        <a class="btn btn-secondary" href="/login">Login</a>
    {% endif %}
{% endblock %}
{% block breadcrumbs %}
    <nav class="breadcrumbs">
        <a href="/projects">Projects</a>
        <span class="sep">/</span>
        <a href="/project/{{ project_id }}">{{ project_name }}</a>
        <span class="sep">/</span>
        <a href="/project/{{ project_id }}#jobsets">Jobsets</a>
        <span class="sep">/</span>
        <a href="/jobset/{{ jobset_id }}">{{ jobset_name }}</a>
        <span class="sep">/</span>
        <span class="current">{{ eval.commit_short }}</span>
    </nav>
{% endblock %}
{% block content %}
    <h1>Evaluation {{ eval.commit_short }}</h1>
    {% if is_admin %}
        <div class="page-actions">
            <form class="inline" method="POST" action="/evaluation/{{ eval.id }}/visibility">
                <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
                <input type="hidden" name="return_to" value="/evaluation/{{ eval.id }}">
                {% if eval.hidden %}
                    <input type="hidden" name="hidden" value="false">
                    <button class="btn btn-small btn-secondary" type="submit">Unhide Evaluation</button>
                {% else %}
                    <input type="hidden" name="hidden" value="true">
                    <button class="btn btn-small btn-secondary" type="submit">Hide Evaluation</button>
                {% endif %}
            </form>
        </div>
    {% endif %}
    <p>
        <strong>Status:</strong>
        <span class="badge badge-{{ eval.status_class }}">{{ eval.status_text }}</span>
        {% if eval.hidden %}<span class="badge badge-skipped">Hidden</span>{% endif %}
    </p>
    <p>
        <strong>Commit:</strong> <code>{{ eval.commit_hash }}</code>
    </p>
    <p>
        <strong>Time:</strong> {{ eval.time }}
    </p>
    {% match eval.error_message %}
        {% when Some with (err) %}
            <div class="flash-message flash-error">
                <strong>Evaluation error</strong>
                <pre class="error-detail">
{{ err }}</pre>
            </div>
        {% when None %}
    {% endmatch %}

    <div class="stats-grid">
        <div class="stat-card">
            <div class="stat-value">{{ succeeded_count }}</div>
            <div class="stat-label">Succeeded</div>
        </div>
        <div class="stat-card">
            <div class="stat-value">{{ failed_count }}</div>
            <div class="stat-label">Failed</div>
        </div>
        <div class="stat-card">
            <div class="stat-value">{{ running_count }}</div>
            <div class="stat-label">Running</div>
        </div>
        <div class="stat-card">
            <div class="stat-value">{{ pending_count }}</div>
            <div class="stat-label">Pending</div>
        </div>
    </div>

    <h2>Builds</h2>
    {% if builds.is_empty() %}
        <div class="empty">No builds for this evaluation.</div>
    {% else %}
        <div class="table-wrap">
            <table>
                <thead>
                    <tr>
                        <th>Job</th>
                        <th>Status</th>
                        <th>System</th>
                        <th>Created</th>
                    </tr>
                </thead>
                <tbody>
                    {% for b in builds %}
                        <tr>
                            <td>
                                <a href="/build/{{ b.id }}">{{ b.job_name }}</a>
                            </td>
                            <td>
                                <span class="badge badge-{{ b.status_class }}">{{ b.status_text }}</span>
                            </td>
                            <td>{{ b.system }}</td>
                            <td>{{ b.created_at }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    {% endif %}
{% endblock %}
