{{ define "title"}}{{ range .BreadCrumbs }}{{ pathUnescape (index . 0)}}/{{ end }} at {{ .Ref }} &middot; {{ .RepoInfo.FullName }} &middot; Tangled{{ end }}


{{ define "extrameta" }}

    {{ $path := "" }}
    {{ range .BreadCrumbs }}
    {{ $path = printf "%s/%s" $path (index . 0) }}
    {{ end }}

    {{ template "repo/fragments/meta" . }}
    {{ $title := printf "%s at %s &middot; %s" $path .Ref .RepoInfo.FullName }}
    {{ $url := printf "https://tangled.org/%s/tree/%s%s" .RepoInfo.FullName .Ref $path }}

    {{ template "repo/fragments/og" (dict "RepoInfo" .RepoInfo "Title" $title "Url" $url) }}
{{ end }}


{{define "repoContent"}}
<main>
  <div class="tree">
    {{ $linkstyle := "no-underline hover:underline" }}

    <div class="pb-2 mb-3 text-base border-b border-gray-200 dark:border-gray-700">
      <div class="flex flex-col md:flex-row md:justify-between gap-2">
        <div id="breadcrumbs" class="overflow-x-auto whitespace-nowrap text-gray-400 dark:text-gray-500">
          {{ range .BreadCrumbs }}
            <a href="{{ index . 1 }}" class="text-bold text-gray-500 dark:text-gray-400 {{ $linkstyle }}">{{ pathUnescape (index . 0) }}</a> /
          {{ end }}
        </div>
        <div id="dir-info" class="text-gray-500 dark:text-gray-400 text-xs md:text-sm flex flex-wrap items-center gap-1 md:gap-0">
          {{ $stats := .TreeStats }}

          <span>at <a href="/{{ $.RepoInfo.FullName }}/tree/{{ pathEscape $.Ref }}">{{ $.Ref }}</a></span>
          {{ if eq $stats.NumFolders 1 }}
            <span class="select-none px-1 md:px-2 [&:before]:content-['·']"></span>
            <span>{{ $stats.NumFolders }} folder</span>
          {{ else if gt $stats.NumFolders 1 }}
            <span class="select-none px-1 md:px-2 [&:before]:content-['·']"></span>
            <span>{{ $stats.NumFolders }} folders</span>
          {{ end }}

          {{ if eq $stats.NumFiles 1 }}
            <span class="select-none px-1 md:px-2 [&:before]:content-['·']"></span>
            <span>{{ $stats.NumFiles }} file</span>
          {{ else if gt $stats.NumFiles 1 }}
            <span class="select-none px-1 md:px-2 [&:before]:content-['·']"></span>
            <span>{{ $stats.NumFiles }} files</span>
          {{ end }}

        </div>
      </div>
    </div>

    {{ if .LastCommitInfo }}
      {{ template "repo/fragments/lastCommitPanel" $ }}
    {{ end }}

    {{ range .Files }}
      <div class="grid grid-cols-12 gap-4 items-center py-1">
        <div class="col-span-8 md:col-span-4">
          {{ $link := printf "/%s/%s/%s/%s/%s" $.RepoInfo.FullName "tree" (pathEscape $.Ref) $.Path .Name }}
          {{ $icon := "folder" }}
          {{ $iconStyle := "size-4 fill-current" }}

          {{ if .IsSubmodule }}
            {{ $link = printf "/%s/%s/%s/%s/%s" $.RepoInfo.FullName "blob" (urlquery $.Ref) $.Path .Name }}
            {{ $icon = "folder-input" }}
            {{ $iconStyle = "size-4" }}
          {{ end }}

          {{ if .IsFile }}
            {{ $link = printf "/%s/%s/%s/%s/%s" $.RepoInfo.FullName "blob" (urlquery $.Ref) $.Path .Name }}
            {{ $icon = "file" }}
            {{ $iconStyle = "size-4" }}
          {{ end }}

          <a href="{{ $link }}" class="{{ $linkstyle }}">
            <div class="flex items-center gap-2">
              {{ i $icon $iconStyle "flex-shrink-0" }}
              <span class="truncate">{{ .Name }}</span>
            </div>
          </a>
        </div>

        <div class="col-span-0 md:col-span-6 hidden md:block overflow-hidden">
          {{ with .LastCommit }}
            <a href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash }}" class="text-gray-500 dark:text-gray-400 block truncate">{{ .Message }}</a>
          {{ end }}
        </div>

        <div class="col-span-4 md:col-span-2 text-sm text-right">
          {{ with .LastCommit }}
            <a href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash }}" class="text-gray-500 dark:text-gray-400">{{ template "repo/fragments/time" .When }}</a>
          {{ end }}
        </div>
      </div>
    {{ end }}

  </div>
</main>
{{ template "repo/fragments/permalinkShortcut" . }}
{{end}}

{{ define "repoAfter" }}
    {{- if or .HTMLReadme .Readme -}}
       {{ template "repo/fragments/readme" . }}
    {{- end -}}
{{ end }}
