{{ define "user/fragments/repoCard" }}
  {{/* root, repo, fullName [,starButton [,starData{IsStarred,SubjectAt,StarCount,RepoName} [,compact]]] */}}
  {{ $root := index . 0 }}
  {{ $repo := index . 1 }}
  {{ $fullName := index . 2 }}
  {{ $starButton := false }}
  {{ $starData := dict }}
  {{ $compact := false }}
  {{ if gt (len .) 3 }}
    {{ $starButton = index . 3 }}
    {{ if gt (len .) 4 }}
      {{ $starData = index . 4 }}
      {{ if gt (len .) 5 }}
        {{ $compact = index . 5 }}
      {{ end }}
    {{ end }}
  {{ end }}

  {{ with $repo }}
    <div class="{{ if not $compact }} min-h-32 {{ end }} {{ if $compact }} focus-within:bg-gray-100 dark:focus-within:bg-gray-800/80 {{ end }} py-4 px-6 gap-1 flex flex-col drop-shadow-sm bg-white dark:bg-gray-800">
      <div class="font-medium dark:text-white flex items-center justify-between">
        <div class="flex items-center min-w-0 flex-1 mr-2">
          {{ if .Source }}
            {{ i "git-fork" "w-4 h-4 mr-1.5 shrink-0" }}
          {{ else }}
            {{ i "book-marked" "w-4 h-4 mr-1.5 shrink-0" }}
          {{ end }}
          {{ $repoOwner := resolve .Did }}
          {{- if $fullName -}}
            <a href="/{{ $repoOwner }}/{{ .Slug }}" data-nav-result class="truncate min-w-0 {{ if $compact }} focus:outline-none {{ end }}">{{ $repoOwner }}/{{ .Name }}</a>
          {{- else -}}
            <a href="/{{ $repoOwner }}/{{ .Slug }}" data-nav-result class="truncate min-w-0 {{ if $compact }} focus:outline-none {{ end }}">{{ .Name }}</a>
          {{- end -}}
        </div>
        {{ if and $starButton $root.LoggedInUser }}
        <div class="shrink-0">
          {{ template "fragments/starBtn" $starData }}
        </div>
        {{ end }}
      </div>
      {{ with .Description }}
        <div class="text-gray-600 dark:text-gray-300 text-sm line-clamp-2">
          {{ . | description }}
        </div>
      {{ end }}

      {{ if .RepoStats }}
        {{ block "repoStats" .RepoStats }}{{ end }}
      {{ end }}
    </div>
  {{ end }}
{{ end }}

{{ define "repoStats" }}
  <div class="text-gray-400 text-sm font-mono inline-flex gap-4 mt-auto">
    {{ with .Language }}
      <div class="flex gap-2 items-center text-sm">
        {{ template "repo/fragments/colorBall" (dict "color" (langColor .)) }}
        <span>{{ . }}</span>
      </div>
    {{ end }}
    {{ with .StarCount }}
      <div class="flex gap-1 items-center text-sm">
        {{ i "star" "w-3 h-3 fill-current" }}
        <span>{{ scaleFmt . }}</span>
      </div>
    {{ end }}
    {{ with .ForkCount }}
      <div class="flex gap-1 items-center text-sm">
        {{ i "git-fork" "w-3 h-3" }}
        <span>{{ scaleFmt . }}</span>
      </div>
    {{ end }}
    {{ with .IssueCount.Open }}
      <div class="flex gap-1 items-center text-sm">
        {{ i "circle-dot" "w-3 h-3" }}
        <span>{{ scaleFmt . }}</span>
      </div>
    {{ end }}
    {{ with .PullCount.Open }}
      <div class="flex gap-1 items-center text-sm">
        {{ i "git-pull-request" "w-3 h-3" }}
        <span>{{ scaleFmt . }}</span>
      </div>
    {{ end }}
  </div>
{{ end }}
