{% extends 'skeleton.html' %}

{% block title %}Repository list{% endblock %}

{% block content %}

<h2>
  Repositories
</h2>

<form>
  <div>
    Order by:
    <input type="radio" id="order_by_last_updated" name="order_by" value="last_updated" onChange="this.form.submit()" {% if order_by == "last_updated" %} checked {% endif %}>
    <label for="order_by_last_updated">Last updated</label>
    <input type="radio" id="order_by_name" name="order_by" value="name" onChange="this.form.submit()" {% if order_by == "name" %} checked {% endif %}>
    <label for="order_by_name">Name</label>
  </div>
  <br>
  <label for="search_query">Search repos:</label>
  <input type="search" id="search_query" name="q" value="{{ search_query|default }}">
  <button type="submit">Search</button>
</form>

<ul class=repolist>
  {% for repo in repos %}
    {% set last_updated_at = repo.fast_get_last_updated_at() %}
    {% set description = repo.get_description() %}
    <li>
      <a
        {% if last_updated_at %}
          href="{{ url_for('index', namespace=repo.namespace, repo=repo.name) }}"
        {% endif %}
      >
        <div class=name>{{ repo.namespaced_name }}</div>
        {% if description %}
          <div class=description>{{ description }}</div>
        {% endif %}
        <div class=last-updated>
        {% if last_updated_at is not none %}
          last updated {{ last_updated_at|timesince }}
        {% else %}
          no commits yet
        {% endif %}
        </div>
      </a>
    </li>
  {% else %}
    <li><div class=name>No repositories to show!</div></li>
  {% endfor %}
</ul>

{% if invalid_repos %}
<ul class="repolist invalid">
  {% for repo in invalid_repos %}
    <li>
        <div class=name>{{ repo.namespaced_name }}</div>
        <div class=reason>
          Invalid git repository
        </div>
    </li>
  {% endfor %}
</ul>
{% endif%}

{% endblock %}
