{% from "_macros.html" import icon %}
{#
  The whole thread. Returned after a rewind or a compaction, either of which
  changes an arbitrary number of messages at once -- replacing the lot is
  simpler and less error-prone than working out which individual bubbles to
  remove. Also included by chat/index.html, so the conversation is described in
  exactly one place.

  Deliberately has no root element: it is swapped with innerHTML into #thread,
  and an outerHTML swap would take the container with it.
#}
{% if compacted %}
{# Summarised turns are kept and still readable -- they have only stopped being
   sent. A compaction that summarised badly is then a bad turn rather than a
   lost conversation. #}
<details class="compacted">
  <summary class="compacted__summary">
    {{ icon("archive", "icon--sm") }}
    <span>{{ compacted | length }} earlier messages, summarised</span>
    {{ icon("chevron-down", "icon--sm reasoning__chevron") }}
  </summary>
  <p class="compacted__note">
    These are no longer sent to the model; a summary of them goes instead. They
    are kept here so nothing is lost.
  </p>
  <div class="compacted__body">
    {% for message in compacted %}
      {% with body_html = bodies.get(message.id, "") %}
        {% include "chat/_message.html" %}
      {% endwith %}
    {% endfor %}
  </div>
</details>
{% endif %}

{% for message in messages %}
  {% with body_html = bodies.get(message.id, "") %}
    {% include "chat/_message.html" %}
  {% endwith %}
{% endfor %}
