{% extends "base.html" %}
{% block title %}Channel {{ channel.name }} - 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="/">Home</a>
        <span class="sep">/</span>
        <a href="/channels">Channels</a>
        <span class="sep">/</span>
        <span class="current">{{ channel.name }}</span>
    </nav>
{% endblock %}
{% block content %}
    <h1>Channel: {{ channel.name }}</h1>

    <dl class="detail-grid">
        <dt>Current Evaluation</dt>
        <dd>
            {% match channel.current_evaluation_id %}
                {% when Some with (eval_id) %}
                    <a href="/evaluation/{{ eval_id }}">{{ eval_id }}</a>
                {% when None %}
                    <em>None</em>
            {% endmatch %}
        </dd>
        <dt>Updated</dt>
        <dd>
            {{ channel.updated_at.format("%Y-%m-%d %H:%M UTC") }}
        </dd>
        <dt>Nix Channel</dt>
        <dd>
            <code>nix-channel --add http://&lt;server&gt;/api/v1/channels/{{ channel.id }}/nixexprs.tar.xz {{ channel.name }}</code>
        </dd>
    </dl>

    {% if builds.is_empty() %}
        <div class="empty">
            {% match channel.current_evaluation_id %}
                {% when None %}
                    <div class="empty-title">No evaluation promoted to this channel yet</div>
                    <div class="empty-hint">Use the API or admin panel to promote a completed evaluation.</div>
                {% when Some with (_) %}
                    <div class="empty-title">No succeeded builds in current evaluation</div>
            {% endmatch %}
        </div>
    {% else %}
        <section class="panel">
            <div class="panel-header">
                <h2>Contents ({{ builds.len() }} jobs)</h2>
                <span class="panel-actions">
                    {% if succeeded_count > 0 %}
                        <span class="badge badge-succeeded">{{ succeeded_count }} succeeded</span>
                    {% endif %}
                    {% if failed_count > 0 %}
                        <span class="badge badge-failed">{{ failed_count }} failed</span>
                    {% endif %}
                    {% if pending_count > 0 %}
                        <span class="badge badge-pending">{{ pending_count }} pending</span>
                    {% endif %}
                </span>
            </div>
            <div class="table-wrap compact-table-wrap">
                <table>
                    <thead>
                        <tr>
                            <th>Job</th>
                            <th>System</th>
                            <th>Status</th>
                            <th>Output</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for b in builds %}
                            <tr>
                                <td>
                                    <a href="/build/{{ b.id }}">{{ b.job_name }}</a>
                                </td>
                                <td>{{ b.system }}</td>
                                <td>
                                    <span class="badge badge-{{ b.status_class }}">{{ b.status_text }}</span>
                                </td>
                                <td>
                                    {% if !b.output_path.is_empty() %}
                                        <code class="path-short">{{ b.output_path }}</code>
                                    {% else %}
                                        -
                                    {% endif %}
                                </td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </section>
    {% endif %}
{% endblock %}
