{% extends "base.html" %}

{% block title %}{{ repo }}/{{ path }}{% endblock %}
{% block og_title %}{{ repo }}/{{ path }}{% endblock %}
{% block og_description %}browsing {{ path }} in {{ repo }}{% endblock %}

{% block breadcrumbs %}
<ul>
  <li><a href="{{ crate::base_url() }}/">{{ crate::hostname() }}</a></li>
  <li><a href="{{ crate::base_url() }}/{{ repo }}">{{ repo }}</a></li>
  <li><a href="{{ crate::base_url() }}/{{ repo }}/commits/{{ sha }}">{{ sha[..8] }}</a></li>
  {% for crumb in breadcrumbs %}
  <li>{% if loop.last %}{{ crumb.label }}{% else %}<a href="{{ crumb.url }}">{{ crumb.label }}</a>{% endif %}</li>
  {% endfor %}
</ul>
{% endblock %}

{% block content %}
{% if is_file %}
<div class="file-view">
  <a href="{{ parent_url }}" class="tree-row">
    <span class="tree-icon"><svg class="summary-icon"><use href="#icon-up-dir"/></svg></span>
    <span class="tree-name">Parent</span>
    <span class="tree-size">[&gt;]</span>
  </a>
  <div class="repo-nav">
    <a href="{{ raw_url }}" class="repo-nav-item">
      <svg class="summary-icon"><use href="#icon-raw"/></svg>
      <span>Raw</span>
      <span class="repo-nav-item-arrow">[&gt;]</span>
    </a>
    <a href="{{ crate::base_url() }}/{{ repo }}/commits/{{ sha }}/blame/{{ path }}" class="repo-nav-item">
      <svg class="summary-icon"><use href="#icon-blame"/></svg>
      <span>Blame</span>
      <span class="repo-nav-item-arrow">[&gt;]</span>
    </a>
  </div>
  <div class="file-content">
    {{ content_html|safe }}
  </div>
</div>
{% else %}
<div class="tree-list">
  {% if path.is_empty() %}
  {% else %}
  <a href="{{ parent_url }}" class="tree-row">
    <span class="tree-icon"><svg class="summary-icon"><use href="#icon-up-dir"/></svg></span>
    <span class="tree-name">..</span>
    <span class="tree-size">-</span>
  </a>
  {% endif %}
  {% if entries.is_empty() %}
  <p>Empty directory.</p>
  {% else %}
  {% for entry in entries %}
  <a href="{{ entry.url }}" class="tree-row">
    <span class="tree-icon"><svg class="summary-icon"><use href="#icon-{% if entry.is_dir %}directory{% else %}file{% endif %}"/></svg></span>
    <span class="tree-name">{% if entry.is_dir %}{{ entry.name }}/{% else %}{{ entry.name }}{% endif %}</span>
    <span class="tree-size">{% if entry.is_dir %}-{% else %}{{ entry.size }}{% endif %}</span>
  </a>
  {% endfor %}
  {% endif %}
</div>
{% endif %}
{% endblock %}

{% block scripts %}
{% if is_file %}
<script>
  // Scroll to the top of the file content after navigation
  document.querySelector('.file-content')?.scrollIntoView(true);
</script>
{% endif %}
{% endblock %}
