{{ define "repo/issues/fragments/putIssue" }}
<!-- this form is used for new and edit, .Issue is passed when editing -->
<form
  {{ if eq .Action "edit" }}
    hx-post="/{{ .RepoInfo.FullName }}/issues/{{ .Issue.IssueId }}/edit"
  {{ else }}
    hx-post="/{{ .RepoInfo.FullName }}/issues/new"
  {{ end }}
  hx-trigger="submit, keydown[(ctrlKey || metaKey) && key=='Enter'] from:(#title,#body)"
  hx-swap="none"
  class="group">
  <div class="flex flex-col gap-2">
    <div>
      <label for="title">Title</label>
      <input type="text" name="title" id="title" class="w-full" value="{{ if .Issue }}{{ .Issue.Title }}{{ end }}" />
    </div>
    <div>
      <label for="body">Body</label>
      {{ template "fragments/markdownEditor"
        (dict "Name"        "body"
              "Value"       (and .Issue .Issue.Body)
              "BlobName"    "blob"
              "Rows"        15
              "Placeholder" "Describe your issue. Markdown is supported.") }}
    </div>
    <div class="flex justify-between">
      <div id="issues" class="error"></div>
      <div class="flex gap-2 items-stretch">
        <a 
          class="btn-flat flex items-center gap-2 no-underline hover:no-underline"
          type="button"
          {{ if .Issue }}
            href="/{{ .RepoInfo.FullName }}/issues/{{ .Issue.IssueId }}"
          {{ else }}
            href="/{{ .RepoInfo.FullName }}/issues"
          {{ end }}
          >
          {{ i "x" "w-4 h-4" }}
          Cancel
        </a>
        <button type="submit" class="btn-create-flat flex items-center gap-2">
          {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }}
          {{ if eq .Action "edit" }}
            {{ i "pencil" "w-4 h-4 inline group-[.htmx-request]:hidden" }}
          {{ else }}
            {{ i "circle-plus" "w-4 h-4 inline group-[.htmx-request]:hidden" }}
          {{ end }}
          {{ .Action | capitalize }}
        </button>
      </div>
    </div>
  </div>
</form>
{{ end }}
