{% extends "base.html" %}

{% block title %}Task {{ task.task_id }} - Dashboard{% endblock %}

{% block body %}
<div class="page" {% if is_active %}hx-ext="sse" sse-connect="/api/task/{{ task.task_id }}/events/stream?format=html"{% endif %}>
    <div class="card">
        <h1>Task: {{ task.task_id }}</h1>

        <div class="field">
            <div class="field-label">Subject</div>
            <div class="field-value">{{ task.display_title }}</div>
        </div>

        <div class="field">
            <div class="field-label">Repository</div>
            <div class="field-value">{{ task.repo_id or '-' }}</div>
        </div>

        <div class="field">
            <div class="field-label">Sender</div>
            <div class="field-value">{{ task.sender or '-' }}</div>
        </div>

        {% if task.conversation_id %}
        <div class="field">
            <div class="field-label">Conversation</div>
            <div class="field-value">
                <a href="/conversation/{{ task.conversation_id }}">{{ task.conversation_id }}</a>
            </div>
        </div>
        {% endif %}

        <div class="field">
            <div class="field-label">Status</div>
            <div class="field-value">
                {% include "components/task_status_badge.html" %}
            </div>
        </div>

        <div id="task-actions" {% if is_active %}sse-swap="task-actions" hx-swap="innerHTML"{% endif %}>
            {% include "components/action_buttons.html" %}
        </div>
    </div>
    {% if task.todos and is_active %}
    <div {% if is_active %}sse-swap="task-progress" hx-swap="innerHTML"{% endif %}>
        {% include "components/todo_progress.html" with context %}
    </div>
    {% elif is_active %}
    <div sse-swap="task-progress" hx-swap="innerHTML"></div>
    {% endif %}
    <div class="card" {% if is_active %}sse-swap="task-details" hx-swap="innerHTML"{% endif %}>
        {% include "components/task_details_card.html" %}
    </div>
    {{ replies_section|safe }}
</div>
{% if is_active %}
<div id="stream-status" class="stream-status">Connecting...</div>
{% endif %}
{% endblock %}

{% block scripts %}
{% if is_active %}
<script src="{{ static_url('vendor/htmx.min.js') }}"></script>
<script src="{{ static_url('vendor/sse.min.js') }}"></script>
<script src="{{ static_url('js/sse-fallback.js') }}"></script>
{% endif %}
{% endblock %}
