{% from "_macros.html" import icon %}
{#
  The file moved between being opened and being saved -- another editor, a
  build, a checkout.

  Three answers, and none of them is silent. Never save over somebody else's
  change without saying so; never throw away what was typed here without saying
  so either. What you wrote is held in the form below, so Overwrite is one
  click and not a retype.

  Sent at 200 rather than 409 on purpose: htmx does not swap an error status,
  and a card offering three buttons cannot be offered from a response the panel
  will not render.
#}
<div class="canvas__conflict">
  <div class="alert alert--warning" role="alert">
    {{ icon("warning", "alert__icon") }}
    <span>
      <strong>{{ conflict.title }}</strong> changed after you opened it, so
      nothing was written. Your version is below.
    </span>
  </div>

  <details class="canvas__theirs">
    <summary>What is there now</summary>
    <pre class="canvas__code"><code>{{ conflict.text }}</code></pre>
  </details>

  <form class="canvas__form"
        hx-post="/api/chats/{{ chat.id }}/canvas/save"
        hx-target="#canvas-inner" hx-swap="innerHTML">
    <input type="hidden" name="key" value="{{ conflict.key }}">
    {# Deliberately empty. An empty token is what tells `_check_stamp` to write
       regardless, which is exactly what Overwrite means -- somebody has now
       been shown both versions and chosen. #}
    <input type="hidden" name="revision" value="">
    <label class="visually-hidden" for="canvas-mine">Your version</label>
    <textarea class="canvas__editor" id="canvas-mine" name="text"
              spellcheck="false" data-canvas-editor>{{ mine }}</textarea>
    <div class="canvas__actions">
      <button class="btn btn--danger btn--sm" type="submit">
        {{ icon("check", "icon--sm") }} Overwrite with mine
      </button>
      <button class="btn btn--sm" type="button"
              hx-post="/api/chats/{{ chat.id }}/canvas/tabs"
              hx-vals='{"key": {{ conflict.key | tojson }}}'
              hx-target="#canvas-inner" hx-swap="innerHTML">
        Discard mine and reload
      </button>
    </div>
  </form>
</div>
