{% load static %}
{% load form_tags %}
<div id="agent-session-content"
     hx-get="{% url 'scrobbles:agent-session-partial' object.id %}"
     hx-trigger="{% if object.logdata.pending %}every 5s{% else %}none{% endif %}"
     hx-swap="outerHTML"
     hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
    {% if object.logdata.as_html %}
        {{ object.logdata|agent_session_html:object.id|safe }}
    {% else %}
        <p class="text-muted">No conversation yet.</p>
    {% endif %}
    {% if not object.logdata.pending %}
    <form class="mt-3"
          hx-post="{% url 'scrobbles:agent-session-followup' object.id %}"
          hx-target="#agent-session-content"
          hx-swap="outerHTML">
        <div class="mb-2">
            {% csrf_token %}
            <textarea name="prompt" class="form-control" rows="2"
                      placeholder="Ask a follow-up..."></textarea>
        </div>
        <button type="submit" class="btn btn-sm btn-primary">Ask</button>
    </form>
    {% endif %}
</div>
