{{ 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 }}">
    <textarea
      name="body"
      class="w-full p-2 rounded border border-gray-200 dark:border-gray-700"
      rows="5"
      autofocus>{{ .Comment.EditableBody }}</textarea>
    <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 flex gap-1 items-center group text-sm"
  >
    {{ i "check" "size-4" }}
    Save
    {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }}
  </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"
  >
    {{ i "x" "size-4" }}
    Cancel
  </button>
{{ end }}
