{% extends "base.html" %}
{% block content %}
<ul class="breadcrumb">
    <li><a href="/">Dashboard</a></li>
    <li>{{ repo_name }}</li>
</ul>

{% if repo %}
<hgroup>
    <h2>{{ repo.name }}</h2>
    <p>
        <code>{{ repo.branch or "detached" }}</code>
        {% if repo.ahead %}<span class="pull-clean">&uarr;{{ repo.ahead }}</span>{% endif %}
        {% if repo.behind %}<span>&darr;{{ repo.behind }}</span>{% endif %}
        {% if repo.pull_status == "conflict" %}<span class="pull-conflict">&#x26A0; conflict</span>{% endif %}
        {% if repo.remote_url %}&mdash; <a href="{{ repo.remote_url | replace('.git', '') }}" target="_blank">GitLab &#x2197;</a>{% endif %}
    </p>
</hgroup>

<div role="group">
    <button class="outline" hx-post="/action/fetch/{{ repo.name }}" hx-swap="none"
            hx-on::after-request="this.textContent='Fetched'; setTimeout(() => this.textContent='Fetch', 3000)">
        Fetch
    </button>
    <button class="outline" hx-post="/action/pull/{{ repo.name }}" hx-target="#pull-result" hx-swap="innerHTML">
        Pull
    </button>
    <button class="outline secondary" hx-post="/action/exclude/{{ repo.name }}" hx-swap="none"
            hx-confirm="Exclude {{ repo.name }} from dashboard?"
            hx-on::after-request="window.location='/'">
        Exclude
    </button>
</div>
<div id="pull-result"></div>

{% if repo.has_forge %}
<section>
    <h3>Merge Requests</h3>
    <div hx-get="/fragment/repo/{{ repo.name }}/mrs"
         hx-trigger="load, every 5s[document.visibilityState === 'visible']"
         hx-swap="innerHTML">
    </div>
</section>

<section>
    <h3>Pipelines</h3>
    <div hx-get="/fragment/repo/{{ repo.name }}/pipelines"
         hx-trigger="load, every 5s[document.visibilityState === 'visible']"
         hx-swap="innerHTML">
    </div>
</section>

<section>
    <h3>Vulnerabilities</h3>
    <div hx-get="/fragment/repo/{{ repo.name }}/vulns"
         hx-trigger="load, every 5s[document.visibilityState === 'visible']"
         hx-swap="innerHTML">
    </div>
</section>
{% endif %}

{% else %}
<p>Repo <strong>{{ repo_name }}</strong> not found.</p>
{% endif %}
{% endblock %}
