{{ define "title" }}
    {{ .Pull.Title }} &middot; Pull #{{ .Pull.PullId }} &middot; {{ .RepoInfo.FullName }} &middot; Tangled
{{ end }}

{{ define "extrameta" }}
  {{ template "repo/pulls/fragments/og" (dict "RepoInfo" .RepoInfo "Pull" .Pull) }}
{{ end }}

{{ define "mainLayout" }}
  <div class="px-1 flex-grow flex flex-col gap-4">
    <div class="max-w-full md:max-w-screen-lg mx-auto">
      {{ block "contentLayout" . }}
        {{ block "content" . }}{{ end }}
      {{ end }}
    </div>
    {{ block "contentAfterLayout" . }}
      <main>
        {{ block "contentAfter" . }}{{ end }}
      </main>
    {{ end }}
  </div>
  <script>
    (function() {
      const details = document.getElementById('bottomSheet');
      const backdrop = document.getElementById('bottomSheetBackdrop');
      const isDesktop = () => window.matchMedia('(min-width: 768px)').matches;

      // function to update backdrop
      const updateBackdrop = () => {
        if (backdrop) {
          if (details.open && !isDesktop()) {
            backdrop.classList.remove('opacity-0', 'pointer-events-none');
            backdrop.classList.add('opacity-100', 'pointer-events-auto');
            document.body.style.overflow = 'hidden';
          } else {
            backdrop.classList.remove('opacity-100', 'pointer-events-auto');
            backdrop.classList.add('opacity-0', 'pointer-events-none');
            document.body.style.overflow = '';
          }
        }
      };

      // close on mobile initially
      if (!isDesktop()) {
        details.open = false;
      }
      updateBackdrop(); // initialize backdrop

      // prevent closing on desktop
      details.addEventListener('toggle', function(e) {
        if (isDesktop() && !this.open) {
          this.open = true;
        }
        updateBackdrop();
      });

      const mediaQuery = window.matchMedia('(min-width: 768px)');
      mediaQuery.addEventListener('change', function(e) {
        if (e.matches) {
          // switched to desktop - keep open
          details.open = true;
        } else {
          // switched to mobile - close
          details.open = false;
        }
        updateBackdrop();
      });

      // close when clicking backdrop
      if (backdrop) {
        backdrop.addEventListener('click', () => {
          if (!isDesktop()) {
            details.open = false;
          }
        });
      }
    })();
  </script>
  <script>
    (function() {
      const isPermalink = (id) => id.startsWith('comment-') || id.startsWith('round-');

      const reveal = () => {
        const raw = window.location.hash.slice(1);
        if (!raw) return;
        let id;
        try { id = decodeURIComponent(raw); } catch (e) { return; }
        if (!isPermalink(id)) return;
        const target = document.getElementById(id);
        if (!target) return;

        for (let el = target.parentElement; el; el = el.parentElement) {
          if (el.tagName === 'DETAILS') el.open = true;
        }

        requestAnimationFrame(() => requestAnimationFrame(() => {
          target.scrollIntoView({ block: 'center' });
          const card = target.closest('.group\\/comment') || target;
          card.classList.add('comment-hl');
        }));
      };

      if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', reveal);
      } else {
        reveal();
      }
      window.addEventListener('hashchange', reveal);
    })();
  </script>
{{ end }}

{{ define "repoContentLayout" }}
  <div class="grid grid-cols-1 md:grid-cols-10 gap-4 w-full">
    <div class="col-span-1 md:col-span-8 flex flex-col gap-4">
      <section class="bg-white dark:bg-gray-800 p-6 rounded relative w-full mx-auto dark:text-white h-full flex-shrink">
        {{ block "repoContent" . }}{{ end }}
      </section>
      {{ template "repo/pulls/fragments/pullVouchNudge" . }}
    </div>
    <div class="flex flex-col gap-6 col-span-1 md:col-span-2">
      {{ template "repo/fragments/labelPanel"
        (dict "RepoInfo" $.RepoInfo
              "Defs" $.LabelDefs
              "Subject" $.Pull.AtUri
              "State" $.Pull.Labels) }}
      {{ template "repo/fragments/participants" $.Pull.Participants }}
      {{ template "repo/fragments/backlinks"
        (dict "RepoInfo" $.RepoInfo
              "Backlinks" $.Backlinks) }}
      {{ template "repo/fragments/externalLinkPanel" $.Pull.AtUri }}
    </div>
  </div>
{{ end }}

{{ define "contentAfter" }}
  <input type="hidden" id="round-link-base" value="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/round/{{ .ActiveRound }}" />
  {{ if .IsInterdiff }}
    <input type="hidden" id="is-interdiff" value="1" />
  {{ end }}
  {{ template "repo/fragments/diff" (list .Diff .DiffOpts $) }}
{{ end }}

{{ define "repoContent" }}
  {{ template "repo/pulls/fragments/pullHeader" . }}
  {{ if (gt (len .Stack) 1) }}
    <div class="mt-8">
      {{ template "repo/pulls/fragments/pullStack" . }}
    </div>
  {{ end }}
{{ end }}

{{ define "resize-grip" }}
  {{ $id := index . 0 }}
  {{ $target := index . 1 }}
  {{ $direction := index . 2 }}
  <div id="{{ $id }}"
    data-resizer="vertical"
    data-target="{{ $target }}"
    data-direction="{{ $direction }}"
    class="resizer-vertical hidden md:flex w-4 sticky top-12 max-h-screen flex-col items-center justify-center group">
    <div class="w-1 h-16 group-hover:h-24 group-[.resizing]:h-24 transition-all rounded-full bg-gray-400 dark:bg-gray-500 group-hover:bg-gray-500 group-hover:dark:bg-gray-400"></div>
  </div>
{{ end }}

{{ define "diffLayout" }}
  {{ $diff := index . 0 }}
  {{ $opts := index . 1 }}
  {{ $root := index . 2 }}

  <div class="flex col-span-full">
    <!-- left panel -->
    <div id="files" class="w-0 hidden md:block overflow-hidden sticky top-12 max-h-screen overflow-y-auto pb-12">
      <section class="overflow-x-auto text-sm px-6 py-2 border-b border-x border-gray-200 dark:border-gray-700 w-full mx-auto min-h-full rounded-b rounded-t-none bg-white dark:bg-gray-800 shadow-sm">
        {{ template "repo/fragments/fileTree" $diff.FileTree }}
      </section>
    </div>

    {{ template "resize-grip" (list "resize-files" "files" "before") }}

    <!-- main content -->
    <div id="diff-files" class="flex-1 min-w-0 sticky top-12 pb-12">
      {{ template "diffFiles" (list $diff $opts) }}
    </div>

    {{ template "resize-grip" (list "resize-subs" "subs" "after") }}

    <!-- right panel -->
    {{ template "subsPanel" $ }}
  </div>
{{ end }}

{{ define "subsPanel" }}
  {{ $root := index . 2 }}
  {{ $pull := $root.Pull }}
  {{ $bgColor := "bg-gray-600 dark:bg-gray-700" }}

  {{ if $pull.State.IsOpen }}
    {{ $bgColor = "bg-green-600 dark:bg-green-700" }}
  {{ else if $pull.State.IsMerged }}
    {{ $bgColor = "bg-purple-600 dark:bg-purple-700" }}
  {{ else if $pull.State.IsAbandoned }}
    {{ $bgColor = "bg-red-600 dark:bg-red-700" }}
  {{ end }}

  <!-- backdrop overlay - only visible on mobile when open -->
  <div id="bottomSheetBackdrop" class="fixed inset-0 bg-black/50 md:hidden opacity-0 pointer-events-none transition-opacity duration-300 z-20"></div>
  <!-- right panel - bottom sheet on mobile, side panel on desktop -->
  <div id="subs" class="fixed bottom-0 left-0 right-0 z-30 w-full md:static md:z-auto md:max-h-screen md:sticky md:top-12 overflow-hidden">
    <details open id="bottomSheet" class="rounded-t-2xl md:rounded-t shadow-lg md:shadow-none group/panel">
      <summary class="
        flex gap-4 items-center justify-between
        rounded-t-2xl md:rounded-t cursor-pointer list-none p-4 md:h-12
        text-white md:text-black md:dark:text-white
        {{ $bgColor }}
        md:bg-white md:dark:bg-gray-800
        shadow-sm border-t md:border-x border-gray-200 dark:border-gray-700
        md:pointer-events-none
        ">
        <h2 class="">History</h2>
        <span class="pointer-events-auto cursor-text">
          {{ template "subsPanelSummary" $ }}
        </span>
      </summary>
      <div class="max-h-[85vh] md:max-h-[calc(100vh-3rem-3rem)] w-full flex flex-col-reverse gap-4 overflow-y-auto bg-slate-100 dark:bg-gray-900 md:bg-transparent">
        {{ template "submissions" $root }}
      </div>
    </details>
  </div>
{{ end }}

{{ define "subsPanelSummary" }}
  {{ $root := index . 2 }}
  {{ $pull := $root.Pull }}
  {{ $rounds := len $pull.Submissions }}
  {{ $comments := $pull.TotalComments }}
  <div class="flex items-center gap-2 text-sm">
    <span>
      {{ $rounds }} round{{ if ne $rounds 1 }}s{{ end }}
    </span>
    <span class="select-none before:content-['\00B7']"></span>
    <span>
      {{ $comments }} comment{{ if ne $comments 1 }}s{{ end }}
    </span>

    <span class="md:hidden inline">
      <span class="inline group-open:hidden">{{ i "chevron-up" "size-4" }}</span>
      <span class="hidden group-open:inline">{{ i "chevron-down" "size-4" }}</span>
    </span>
  </div>
{{ end }}

{{ define "subsCheckbox" }}
  <input type="checkbox" id="subsToggle" class="peer/subs hidden" checked/>
{{ end }}

{{ define "subsToggle" }}
  <style>
    #subsToggle:checked ~ div div#subs {
      width: 100%;
      margin-left: 0;
    }
    #subsToggle:checked ~ div label[for="subsToggle"] .show-toggle { display: none; }
    #subsToggle:checked ~ div label[for="subsToggle"] .hide-toggle { display: flex; }
    #subsToggle:not(:checked) ~ div label[for="subsToggle"] .hide-toggle { display: none; }

    @media (min-width: 768px) {
      #subsToggle:checked ~ div div#subs {
        width: 25vw;
        max-width: 50vw;
      }
      #subsToggle:not(:checked) ~ div div#subs {
        width: 0;
        display: none;
        margin-left: 0;
      }
      #subsToggle:not(:checked) ~ div div#resize-subs {
        display: none;
      }
    }
  </style>
    <label title="Toggle review panel" for="subsToggle" class="hidden md:flex items-center justify-end pointer-events-none">
      <span class="show-toggle hit-area hit-area-4 hit-area-x-2 pointer-events-auto cursor-pointer">{{ i "message-square-more" "size-4" }}</span>
      <span class="hide-toggle w-[25vw] justify-end"><span class="hit-area hit-area-4 hit-area-x-2 pointer-events-auto cursor-pointer">{{ i "message-square" "size-4" }}</span></span>
    </label>
{{ end }}


{{ define "submissions" }}
  {{ $lastIdx := sub (len .Pull.Submissions) 1 }}
  {{ if not .LoggedInUser }}
    {{ template "loginPrompt" $ }}
  {{ end }}
  {{ range $ridx, $item := reverse .Pull.Submissions }}
    {{ $idx := sub $lastIdx $ridx }}
    {{ template "submission" (list $item $idx $lastIdx $) }}
  {{ end }}
{{ end }}

{{ define "submission" }}
  {{ $item := index . 0 }}
  {{ $idx := index . 1 }}
  {{ $lastIdx := index . 2 }}
  {{ $root := index . 3 }}
  {{ $round := $item.RoundNumber }}
  <div id="round-{{ $round }}" class="
    w-full shadow-sm  border overflow-clip

    {{ if eq $round 0 }}rounded-b{{ else }}rounded{{ end }}
    {{ if eq $round $root.ActiveRound }}
       bg-blue-50/25 dark:bg-blue-900/10 border-blue-200 dark:border-blue-900
    {{ else }}
       bg-gray-50 dark:bg-gray-900 border-gray-200 dark:border-gray-700
    {{ end }}
    ">
    {{ template "submissionHeader" $ }}
    {{ template "submissionComments" $ }}
  </div>
{{ end }}

{{ define "submissionHeader" }}
  {{ $item := index . 0 }}
  {{ $lastIdx := index . 2 }}
  {{ $root := index . 3 }}
  {{ $round := $item.RoundNumber }}
  <div class="
    {{ if ne $round 0 }}rounded-t{{ end }}
    px-6 py-4 pr-2 pt-2
    {{ if eq $round $root.ActiveRound }}
      bg-blue-50 dark:bg-blue-950
    {{ else }}
      bg-white dark:bg-gray-800
    {{ end }}

    flex gap-2 sticky top-0 z-20">
    <!-- left column: just profile picture -->
    <div class="flex-shrink-0 pt-2">
      {{ template "user/fragments/picLink" (list $root.Pull.OwnerDid "size-8" (index $root.VouchRelationships (did $root.Pull.OwnerDid))) }}
    </div>
    <!-- right column -->
    <div class="flex-1 min-w-0 flex flex-col gap-1">
      {{ template "submissionInfo" $ }}
      {{ template "submissionCommits" $ }}
      {{ template "submissionPipeline" $ }}
      {{ if eq $lastIdx $round }}
        <div id="mergecheck-banner">
          {{ if $root.Pull.State.IsOpen }}
            <div class="flex items-center gap-2 text-gray-500 dark:text-gray-400">
              {{ i "loader-circle" "w-4 h-4 animate-spin" }}
              <span>Checking mergeability…</span>
            </div>
          {{ end }}
        </div>
      {{ end }}
    </div>
  </div>
{{ end }}

{{ define "submissionInfo" }}
  {{ $item := index . 0 }}
  {{ $idx := index . 1 }}
  {{ $root := index . 3 }}
  {{ $round := $item.RoundNumber }}
  <div class="flex gap-2 items-center justify-between mb-1">
<span class="inline-flex items-center gap-2 text-sm
      {{ if eq $round $root.ActiveRound }}
      text-gray-600 dark:text-gray-300
      {{ else }}
      text-gray-500 dark:text-gray-400
      {{ end }}
      pt-2">
      {{ $handle := resolve $root.Pull.OwnerDid }}
      <a class="
        {{ if eq $round $root.ActiveRound }}
          text-gray-800 dark:text-gray-300 hover:text-gray-800 dark:hover:text-gray-200
        {{ else }}
          text-gray-500 dark:text-gray-400 hover:text-gray-500 dark:hover:text-gray-300
        {{ end }}
        " href="/{{ $handle }}">{{ $handle }}</a>
      submitted
      <span class="px-2 py-0.5 rounded font-mono text-xs border
        {{ if eq $round $root.ActiveRound }}
          text-blue-800 dark:text-white bg-blue-100 dark:bg-blue-600 border-blue-200 dark:border-blue-500
        {{ else }}
          text-black dark:text-white bg-gray-100 dark:bg-gray-700 border-gray-300 dark:border-gray-600
        {{ end }}
        ">
        #{{ $round }}
      </span>
      <span class="select-none before:content-['\00B7']"></span>
      <a class="
        {{ if eq $round $root.ActiveRound }}
        text-gray-600 dark:text-gray-300 hover:text-gray-600 dark:hover:text-gray-200
        {{ else }}
        text-gray-500 dark:text-gray-400 hover:text-gray-500 dark:hover:text-gray-300
        {{ end }}
        " href="#round-{{ $round }}">
        {{ template "repo/fragments/shortTime" $item.Created }}
      </a>
    </span>
    <div class="flex gap-2 items-center">
      {{ if or $root.IsInterdiff (ne $root.ActiveRound $round) }}
      <a class="btn-flat flex items-center gap-2 no-underline hover:no-underline text-sm"
        href="/{{ $root.RepoInfo.FullName }}/pulls/{{ $root.Pull.PullId }}/round/{{ $round }}?{{ safeUrl $root.DiffOpts.Encode }}#round-{{ $round }}">
        {{ i "diff" "w-4 h-4" }}
        Diff
      </a>
      {{ end }}
      {{ if and (ne $idx 0) (or (not $root.IsInterdiff) (ne $root.ActiveRound $round)) }}
        <a class="btn-flat flex items-center gap-2 no-underline hover:no-underline text-sm"
           href="/{{ $root.RepoInfo.FullName }}/pulls/{{ $root.Pull.PullId }}/round/{{ $round }}/interdiff?{{ safeUrl $root.DiffOpts.Encode }}">
          {{ i "chevrons-left-right-ellipsis" "w-4 h-4 rotate-90" }}
          Interdiff
        </a>
      {{ end }}
    </div>
  </div>
{{ end }}

{{ define "submissionCommits" }}
  {{ $item := index . 0 }}
  {{ $root := index . 3 }}
  {{ $round := $item.RoundNumber }}
  {{ $patches := $item.AsFormatPatch }}
  {{ if $patches }}
    <details class="group/commit">
      <summary class="list-none cursor-pointer flex items-center gap-2">
        <span>{{ i "git-commit-horizontal" "w-4 h-4" }}</span>
        {{ len $patches }} commit{{ if ne (len $patches) 1 }}s{{ end }}
        <div class="text-sm text-gray-500 dark:text-gray-400">
          <span class="group-open/commit:hidden inline">Expand</span>
          <span class="hidden group-open/commit:inline">Collapse</span>
        </div>
      </summary>
      {{ range $patches }}
        {{ template "submissionCommit" (list . $item $root) }}
      {{ end }}
    </details>
  {{ end }}
{{ end }}

{{ define "submissionCommit" }}
  {{ $patch := index . 0 }}
  {{ $item := index . 1 }}
  {{ $root := index . 2 }}
  {{ $round := $item.RoundNumber }}
  {{ with $patch }}
    <div id="commit-{{.SHA}}" class="py-1 relative w-full md:max-w-3/5 md:w-fit flex flex-col text-gray-600 dark:text-gray-300">
      <div class="flex items-baseline gap-2">
        <div class="text-xs">
          <!-- attempt to resolve $fullRepo: this is possible only on non-deleted forks and branches -->
          {{ $fullRepo := "" }}
          {{ if and $root.Pull.IsForkBased $root.Pull.PullSource.Repo }}
            {{ $fullRepo = printf "%s/%s" (resolve $root.Pull.PullSource.Repo.Did) $root.Pull.PullSource.Repo.Slug }}
          {{ else if $root.Pull.IsBranchBased }}
            {{ $fullRepo = $root.RepoInfo.FullName }}
          {{ end }}

          <!-- if $fullRepo was resolved, link to it, otherwise just span without a link -->
          {{ if $fullRepo }}
            <a href="/{{ $fullRepo }}/commit/{{ .SHA }}" class="font-mono text-gray-600 dark:text-gray-300">{{ slice .SHA 0 8 }}</a>
          {{ else }}
            <span class="font-mono">{{ slice .SHA 0 8 }}</span>
          {{ end }}
        </div>

        <div>
          <span>{{ .Title | description }}</span>
          {{ if gt (len .Body) 0 }}
            <button
              class="py-1/2 px-1 mx-2 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600"
              hx-on:click="document.getElementById('body-{{$round}}-{{.SHA}}').classList.toggle('hidden')"
              >
              {{ i "ellipsis" "w-3 h-3" }}
            </button>
          {{ end }}
          {{ if gt (len .Body) 0 }}
            <p id="body-{{$round}}-{{.SHA}}" class="hidden mt-1 pb-2">{{ nl2br .Body }}</p>
          {{ end }}
        </div>
      </div>
    </div>
  {{ end }}
{{ end }}

{{ define "mergeStatus" }}
  {{ if .Pull.State.IsClosed }}
  <div class="bg-gray-50 dark:bg-gray-700 border border-black dark:border-gray-500 rounded shadow-sm px-6 py-2 relative">
    <div class="flex items-center gap-2 text-black dark:text-white">
      {{ i "ban" "w-4 h-4" }}
      <span class="font-medium">Closed without merging</span
      >
    </div>
  </div>
  {{ else if .Pull.State.IsMerged }}
  <div class="bg-purple-50 dark:bg-purple-900 border border-purple-500 rounded shadow-sm px-6 py-2 relative">
    <div class="flex items-center gap-2 text-purple-500 dark:text-purple-300">
      {{ i "git-merge" "w-4 h-4" }}
      <span class="font-medium">Pull request successfully merged</span
      >
    </div>
  </div>
  {{ else if .Pull.State.IsAbandoned }}
  <div class="bg-red-50 dark:bg-red-900 border border-red-500 rounded shadow-sm px-6 py-2 relative">
    <div class="flex items-center gap-2 text-red-500 dark:text-red-300">
      {{ i "git-pull-request-closed" "w-4 h-4" }}
      <span class="font-medium">This pull has been deleted (possibly by jj abandon or jj squash)</span>
    </div>
  </div>
  {{ end }}
{{ end }}

{{ define "submissionPipeline" }}
  {{ $item := index . 0 }}
  {{ $root := index . 3 }}
  {{ $pipeline := index $root.Pipelines $item.SourceRev }}
  {{ with $pipeline }}
    {{ $id := .Id }}
    {{ if .Statuses }}
      <details class="group/pipeline">
        <summary class="cursor-pointer list-none flex items-center gap-2">
          {{ template "repo/pipelines/fragments/pipelineSymbol" (dict "Pipeline" $pipeline "ShortSummary" false) }}
          <div class="text-sm text-gray-500 dark:text-gray-400">
            <span class="group-open/pipeline:hidden inline">Expand</span>
            <span class="hidden group-open/pipeline:inline">Collapse</span>
          </div>
        </summary>
          <div class="my-2 grid grid-cols-1 bg-white dark:bg-gray-800 rounded border border-gray-200 dark:border-gray-700 divide-y divide-gray-200 dark:divide-gray-700">
            {{ range $name, $all := .Statuses }}
            <a href="/{{ $root.RepoInfo.FullName }}/pipelines/{{ $id }}/workflow/{{ $name }}" class="no-underline hover:no-underline hover:bg-gray-100/25 hover:dark:bg-gray-700/25">
              <div
                class="flex gap-2 items-center justify-between p-2">
                {{ $lastStatus := $all.Latest }}
                {{ $kind := $lastStatus.Status.String }}

                <div id="left" class="flex items-center gap-2 flex-shrink-0">
                  {{ template "repo/pipelines/fragments/workflowSymbol" $all }}
                  {{ $name }}
                </div>
                <div id="right" class="flex items-center gap-2 flex-shrink-0">
                  <span class="font-bold">{{ $kind }}</span>
                  {{ if .TimeTaken }}
                  {{ template "repo/fragments/duration" .TimeTaken }}
                  {{ else }}
                  {{ template "repo/fragments/shortTimeAgo" $lastStatus.Created }}
                  {{ end }}
                </div>
              </div>
            </a>
            {{ end }}
          </div>
      </details>
    {{ end }}
  {{ end }}
{{ end }}

{{ define "submissionComments" }}
  {{ $item := index . 0 }}
  {{ $idx := index . 1 }}
  {{ $lastIdx := index . 2 }}
  {{ $root := index . 3 }}
  {{ $round := $item.RoundNumber }}
  {{ $c := len $item.Comments }}
  <details class="relative ml-10 group/comments group/collapse" {{ if or (eq $c 0) (eq $root.ActiveRound $round) }}open{{ end }}>
    <summary class="cursor-pointer list-none">
      <div class="collapse-trigger hidden group-open/comments:block absolute -left-8 top-0 bottom-0 w-16 transition-colors flex items-center justify-center group/border z-4">
        <div class="absolute left-1/2 -translate-x-1/2 top-0 bottom-0 w-0.5 group-open/comments:bg-gray-200 dark:group-open/comments:bg-gray-700 group-has-[.collapse-trigger:hover]/collapse:bg-gray-400 dark:group-has-[.collapse-trigger:hover]/collapse:bg-gray-500 transition-colors"> </div>
      </div>
      <div class="group-open/comments:hidden block relative group/summary py-4">
        <div class="absolute -left-8 top-0 bottom-0 w-16 transition-colors flex items-center justify-center z-4">
          <div class="absolute left-1/2 -translate-x-1/2 h-1/3 top-0 bottom-0 w-0.5 bg-gray-200 dark:bg-gray-700 group-hover/summary:bg-gray-400 dark:group-hover/summary:bg-gray-500 transition-colors"></div>
        </div>
        <span class="text-gray-500 dark:text-gray-400 text-sm group-hover/summary:text-gray-600 dark:group-hover/summary:text-gray-300 transition-colors flex items-center gap-2 -ml-2 relative">
          {{ i "circle-plus" "size-4 z-5" }}
          Expand {{ $c }} comment{{ if ne $c 1 }}s{{ end }}
        </span>
      </div>
    </summary>
    <div id="pull-comments-{{ $round }}">
      {{ range $item.Comments }}
        {{ template "fragments/comment/pullComment"
          (dict "LoggedInUser" $root.LoggedInUser
                "Reactions"    (index (asReactionMapMap $root.Reactions) .FeedCommentAtUri)
                "UserReacted"  (index (asReactionStatusMapMap $root.UserReacted) .FeedCommentAtUri)
                "Comment"      .) }}
      {{ end }}
    </div>
    {{ if gt $c 0}}
      <button class="collapse-trigger flex items-center gap-2 -ml-2 relative cursor-pointer text-sm text-gray-500 dark:text-gray-400 group-has-[.collapse-trigger:hover]/collapse:text-gray-600 dark:group-has-[.collapse-trigger:hover]/collapse:text-gray-300 mt-4 pb-4 transition-colors" hx-on:click="this.closest('details').open = false">
        <span class="bg-gray-50 dark:bg-slate-900 dark:rounded-full">{{ i "circle-chevron-up" "size-4 z-5" }}</span> Collapse comment{{ if ne $c 1 }}s{{ end }}
      </button>
    {{ end }}

    <div class="relative -ml-10">
      {{ if eq $lastIdx $item.RoundNumber }}
        {{ block "mergeStatus" $root }} {{ end }}
        <div id="resubmit-banner"></div>
        <div id="pull-action-error" class="error"></div>
      {{ end }}
    </div>
    <div hx-include="this" class="relative -ml-10 bg-gray-50 dark:bg-gray-900">
      {{ if $root.LoggedInUser }}
        <input name="subject-uri" type="hidden" value="{{ $root.Pull.AtUri }}">
        <input name="pull-round-idx" type="hidden" value="{{ $item.RoundNumber }}">
      {{ end }}
      {{ template "repo/pulls/fragments/pullActions"
        (dict
          "LoggedInUser" $root.LoggedInUser
          "Pull" $root.Pull
          "RepoInfo" $root.RepoInfo
          "RoundNumber" $item.RoundNumber
          "MergeCheck" $root.MergeCheck
          "ResubmitCheck" $root.ResubmitCheck
          "BranchDeleteStatus" $root.BranchDeleteStatus
          "Stack" $root.Stack
          "Loading" (eq $lastIdx $item.RoundNumber)) }}
    </div>
  </details>
{{ end }}

{{ define "loginPrompt" }}
  <div class="bg-amber-50 dark:bg-amber-900 border border-amber-500 rounded shadow-sm p-2 relative flex gap-2 items-center">
    <a href="/signup" class="btn-create py-0 hover:no-underline hover:text-white flex items-center gap-2">
      Sign up
    </a>
    <span class="text-gray-500 dark:text-gray-400">or</span>
    <a href="/login" class="underline">Login</a>
    to add to the discussion
  </div>
{{ end }}
