{% extends "base.html" %}
{% block title %}{{ name }} NARs - 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="/caches">Caches</a>
        <span class="sep">/</span>
        <a href="{{ detail_href }}">{{ name }}</a>
        <span class="sep">/</span>
        <span class="current">NARs</span>
    </nav>
{% endblock %}

{% block content %}
    <div class="cache-header">
        <div class="cache-header-title">
            <h1>{{ name }} &middot; NARs</h1>
            <span class="badge badge-neutral">{{ scope_label }}</span>
        </div>
    </div>

    <div class="stat-strip">
        <div class="stat-card">
            <div class="stat-label">Total NARs</div>
            <div class="stat-value">{{ total_nars }}</div>
        </div>
        <div class="stat-card">
            <div class="stat-label">NAR size</div>
            <div class="stat-value">{{ nar_size }}</div>
        </div>
        <div class="stat-card">
            <div class="stat-label">File size</div>
            <div class="stat-value">{{ file_size }}</div>
        </div>
        <div class="stat-card">
            <div class="stat-label">Last uploaded</div>
            <div class="stat-value">{{ last_uploaded }}</div>
        </div>
        <div class="stat-card">
            <div class="stat-label">Oldest fetched</div>
            <div class="stat-value">{{ oldest_fetched }}</div>
        </div>
    </div>

    <form method="get" action="{{ detail_href }}/nars" class="filter-form">
        <label>
            Hash: <input type="text" name="hash" value="{{ filter_hash }}" placeholder="store hash prefix">
        </label>
        <label>
            Package: <input type="text" name="package" value="{{ filter_package }}" placeholder="package name">
        </label>
        <button type="submit" class="btn btn-secondary">Filter</button>
    </form>

    {% if nars.is_empty() %}
        <div class="empty">
            <div class="empty-title">No NARs match filters</div>
            <div class="empty-hint">Adjust the filters above, or wait for builds to upload paths.</div>
        </div>
    {% else %}
        <div class="table-wrap">
            <table>
                <colgroup>
                    <col style="width:18%">
                    <col style="width:30%">
                    <col style="width:12%">
                    <col style="width:12%">
                    <col style="width:14%">
                    <col style="width:14%">
                </colgroup>
                <thead>
                    <tr>
                        <th>Hash</th>
                        <th>Package</th>
                        <th>NAR size</th>
                        <th>Compressed</th>
                        <th>Created</th>
                        <th>Last fetched</th>
                    </tr>
                </thead>
                <tbody>
                    {% for n in nars %}
                        <tr>
                            <td>
                                <code class="mono-trunc">{{ n.hash }}</code>
                            </td>
                            <td>
                                <details class="nar-detail">
                                    <summary>{{ n.package }}</summary>
                                    <code class="nar-store-path">{{ n.store_path }}</code>
                                </details>
                            </td>
                            <td>{{ n.nar_size }}</td>
                            <td>{{ n.compressed }}</td>
                            <td>{{ n.created_at }}</td>
                            <td>{{ n.last_fetched }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        {% if total_pages > 1 %}
            <nav class="pagination">
                {% if has_prev %}
                    <a href="{{ detail_href }}/nars?offset={{ prev_offset }}&limit={{ limit }}&hash={{ filter_hash }}&package={{ filter_package }}"
                       class="btn btn-small btn-secondary">
                        &laquo; Previous
                    </a>
                {% endif %}
                <span class="text-muted">Page {{ page }} of {{ total_pages }}</span>
                {% if has_next %}
                    <a href="{{ detail_href }}/nars?offset={{ next_offset }}&limit={{ limit }}&hash={{ filter_hash }}&package={{ filter_package }}"
                       class="btn btn-small btn-secondary">
                        Next &raquo;
                    </a>
                {% endif %}
            </nav>
        {% endif %}
    {% endif %}
{% endblock %}
