{{ define "title" }}Issues &middot; {{ .RepoInfo.FullName }} &middot; Tangled{{ end }}

{{ define "extrameta" }}
    {{ $title := "Issues"}}
    {{ $url := printf "https://tangled.org/%s/issues" .RepoInfo.FullName }}

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

{{ define "repoContent" }}
  {{ $active := .FilterState }}

  {{ $open :=
     (dict
       "Key" "open"
       "Value" "Open"
       "Icon" "circle-dot"
       "Meta" (scaleFmt .RepoInfo.Stats.IssueCount.Open)) }}
  {{ $closed :=
     (dict
       "Key" "closed"
       "Value" "Closed"
       "Icon" "ban"
       "Meta" (scaleFmt .RepoInfo.Stats.IssueCount.Closed)) }}
  {{ $values := list $open $closed }}

  <div class="grid gap-2 grid-cols-[auto_1fr_auto] grid-row-2">
    <form id="search-form" class="flex relative col-span-3 sm:col-span-1 sm:col-start-2" method="GET">
      <div class="flex-1 flex relative">
        <input
          id="search-q"
          class="flex-1 py-1 pl-2 pr-10 mr-[-1px] rounded-r-none peer"
          type="text"
          name="q"
          value="{{ .FilterQuery }}"
          placeholder="Search issues..."
        >
        <a
          {{ if $active }}href="?q=state:{{ $active }}"{{ else }}href="?"{{ end }}
          class="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hidden peer-[:not(:placeholder-shown)]:block"
        >
          {{ i "x" "w-4 h-4" }}
        </a>
      </div>
      <button
        type="submit"
        class="p-2 text-gray-400 border rounded-r border-gray-300 dark:border-gray-600"
      >
        {{ i "search" "w-4 h-4" }}
      </button>
    </form>
    <div class="sm:row-start-1">
      {{ template "fragments/tabSelector" (dict "Name" "state" "Values" $values "Active" $active "Include" "#search-q" "Form" "search-form") }}
    </div>
    <a
      href="/{{ .RepoInfo.FullName }}/issues/new"
      class="col-start-3 btn-create text-sm flex items-center justify-center gap-2 no-underline hover:no-underline hover:text-white"
    >
      {{ i "circle-plus" "w-4 h-4" }}
      <span>New</span>
    </a>
  </div>
  <div class="error" id="issues"></div>
{{ end }}

{{ define "repoAfter" }}
  <div class="mt-2">
    {{ template "repo/issues/fragments/issueListing" 
        (dict
          "Issues" .Issues
          "RepoPrefix" .RepoInfo.FullName
          "LabelDefs" .LabelDefs
          "VouchRelationships" .VouchRelationships
          "BaseFilterQuery" $.BaseFilterQuery
          "BasePath" (printf "/%s/issues" .RepoInfo.FullName))
    }}
  </div>
  {{if gt .IssueCount .Page.Limit }}
    {{ template "fragments/pagination" (dict
        "Page" .Page
        "TotalCount" .IssueCount
        "BasePath" (printf "/%s/issues" .RepoInfo.FullName)
        "QueryParams" (queryParams "q" .FilterQuery)
    ) }}
  {{ end }}
{{ end }}
