{{ define "fragments/comment/edit" }}
  <form
    class="pt-2"
    hx-patch="/comment"
    hx-swap="outerHTML"
    hx-trigger="submit, keydown[(ctrlKey || metaKey) && key=='Enter'] from:find textarea"
    hx-indicator="find button[type='submit']"
    hx-disabled-elt="find button[type='submit']"
  >
    <input name="aturi" type="hidden" value="{{ .Comment.AtUri }}">
    {{ template "fragments/markdownEditor"
      (dict "Name"         "body"
            "Value"        .Comment.EditableBody
            "Placeholder" "Describe this pull request. Markdown is supported.") }}
    <div id="comment-error" class="error"></div>
    {{ template "editActions" $ }}
  </form>
{{ end }}

{{ define "editActions" }}
  <div class="flex flex-wrap items-stretch justify-end gap-2 text-gray-500 dark:text-gray-400 text-sm pt-2">
    {{ template "cancel" . }}
    {{ template "save" . }}
  </div>
{{ end }}

{{ define "save" }}
  <button
    type="submit"
    class="btn-create-flat flex gap-1 items-center group text-sm"
  >
    {{ i "loader-circle" "size-4 animate-spin hidden group-[.htmx-request]:inline" }}
    {{ i "check" "size-4 inline group-[.htmx-request]:hidden" }}
    Save
  </button>
{{ end }}

{{ define "cancel" }}
  <button
    class="btn-flat text-red-500 dark:text-red-400 flex gap-1 items-center group"
    hx-get="/comment?aturi={{ .Comment.AtUri }}"
    hx-target="closest form"
    hx-swap="outerHTML"
    hx-indicator="this"
    hx-disabled-elt="this"
  >
    {{ i "x" "size-4" }}
    Cancel
  </button>
{{ end }}
