{{ define "repo/pulls/fragments/pullStack" }}
  <details class="bg-white dark:bg-gray-800 group" open>
    <summary class="p-2 text-sm font-bold list-none cursor-pointer hover:text-gray-500 hover:dark:text-gray-400">
      <span class="flex items-center gap-2">
        <span class="group-open:hidden">
          {{ i "chevrons-up-down" "w-4 h-4" }}
        </span>
        <span class="hidden group-open:flex">
          {{ i "chevrons-down-up" "w-4 h-4" }}
        </span>
        STACK
        <span class="bg-gray-200 dark:bg-gray-700 font-normal rounded py-1/2 px-1 text-sm">{{ len .Stack }}</span>
      </span>
    </summary>
    {{ block "pullList" (list .Stack $) }} {{ end }}
  </details>

  {{ if gt (len .AbandonedPulls) 0 }}
    <details class="mt-4 bg-white dark:bg-gray-800 group" open>
      <summary class="p-2 text-sm font-bold list-none cursor-pointer hover:text-gray-500 hover:dark:text-gray-400">
        <span class="flex items-center gap-2">
          <span class="group-open:hidden">
            {{ i "chevrons-up-down" "w-4 h-4" }}
          </span>
          <span class="hidden group-open:flex">
            {{ i "chevrons-down-up" "w-4 h-4" }}
          </span>
          ABANDONED PULLS
          <span class="bg-gray-200 dark:bg-gray-700 rounded py-1/2 px-1 text-sm ml-1">{{ len .AbandonedPulls }}</span>
        </span>
      </summary>
      {{ block "pullList" (list .AbandonedPulls $) }} {{ end }}
    </details>
  {{ end }}
{{ end }}

{{ define "pullList" }}
  {{ $list := index . 0 }}
  {{ $root := index . 1 }}
  <div class="grid grid-cols-1 rounded border border-gray-200 dark:border-gray-700 divide-y divide-gray-200 dark:divide-gray-700">
    {{ range $pull := $list }}
      {{ $isCurrent := false }}
      {{ $pipeline := index $root.Pipelines $pull.LatestSha }}
      {{ with $root.Pull }}
        {{ $isCurrent = eq $pull.PullId $root.Pull.PullId }}
      {{ end }}
      <a href="/{{ $root.RepoInfo.FullName }}/pulls/{{ $pull.PullId }}" class="no-underline hover:no-underline hover:bg-gray-100/25 hover:dark:bg-gray-700/25">
        <div class="flex gap-2 items-center px-2 {{ if $isCurrent }}bg-gray-100/50 dark:bg-gray-700/50{{ end }}">
          {{ if $isCurrent }}
            <div class="flex-shrink-0">
              {{ i "arrow-right" "w-4 h-4" }}
            </div>
          {{ end }}
          <div class="{{ if not $isCurrent }} pl-6 {{ end }} flex-grow min-w-0 w-full py-2">
            {{ template "repo/pulls/fragments/summarizedPullHeader" (list $pull $pipeline) }}
          </div>
        </div>
      </a>
    {{ end }}
  </div>
{{ end }}
