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

  {{ with $repo }}
    <div class="py-4 px-6 gap-1 flex flex-col drop-shadow-sm bg-white dark:bg-gray-800 min-h-32">
      <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 }}/{{ .Name }}" class="truncate min-w-0">{{ $repoOwner }}/{{ .Name }}</a>
          {{- else -}}
            <a href="/{{ $repoOwner }}/{{ .Name }}" class="truncate min-w-0">{{ .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>{{ . }}</span>
      </div>
    {{ end }}
    {{ with .IssueCount.Open }}
      <div class="flex gap-1 items-center text-sm">
        {{ i "circle-dot" "w-3 h-3" }}
        <span>{{ . }}</span>
      </div>
    {{ end }}
    {{ with .PullCount.Open }}
      <div class="flex gap-1 items-center text-sm">
        {{ i "git-pull-request" "w-3 h-3" }}
        <span>{{ . }}</span>
      </div>
    {{ end }}
  </div>
{{ end }}
