{% from "_macros.html" import icon %}
{#
  A plan the model proposed in Plan mode.

  Rendered from `message.plan_json` rather than parsed back out of the prose, so
  the Execute button sends exactly what was proposed. Every line is model output
  and is escaped; a step is shown as text, never as Markdown, because a plan is
  the last thing that should be able to emit a link.

  Execute switches the chat to Edit, never Auto -- the plan was written under a
  mode where every command stopped for approval, and a button that also removed
  the asking is not the button anybody pressed. The confirm dialog says so.
#}
<section class="plan">
  <h3 class="plan__title">
    {{ icon("check", "icon--sm") }}
    {{ message.plan_json.title or "A plan" }}
  </h3>

  <ol class="plan__steps">
    {% for step in message.plan_json.steps %}
    <li>{{ step }}</li>
    {% endfor %}
  </ol>

  {% if chat.kind == "agent" %}
  <div class="btn-row">
    <button class="btn btn--primary btn--sm" type="button"
            hx-post="/api/chats/{{ chat.id }}/messages/{{ message.id }}/execute-plan"
            hx-target="#thread" hx-swap="beforeend"
            hx-confirm="Switch this chat to Edit mode and carry out this plan? Every command will still be shown to you before it runs."
            data-confirm-label="Carry it out"
            data-confirm-danger="false">
      {{ icon("send", "icon--sm") }} Carry out this plan
    </button>
    <span class="plan__note">Switches to Edit — commands still ask.</span>
  </div>
  {% endif %}
</section>
