{% from "_macros.html" import icon %}
{#
  A single chat row. `chat_item` rather than `chat` so this can be included
  from a page that already has the open chat bound to `chat`.
#}
<div class="nav-item {% if chat and chat.id == chat_item.id %}is-active{% endif %}"
     data-chat-id="{{ chat_item.id }}">
  <a class="nav-item__link" href="/chat/{{ chat_item.id }}">
    {# The kind, in the one place a person looks. Legible even with the switch
       off, which is what it is for: a chat that can run commands should not look
       like one that cannot. #}
    {{ icon("terminal" if chat_item.kind == "agent" else "chat", "icon--sm") }}
    <span class="nav-item__label" id="chat-link-label-{{ chat_item.id }}">{{ chat_item.title }}</span>
    {# Toggled out of band by the unread poll; see /api/chats/unread. #}
    <span id="unread-{{ chat_item.id }}" class="unread-dot"
          {{ '' if chat_item.unread else 'hidden' }} title="New reply"></span>
  </a>
  <span class="nav-item__actions">
    {# Works from any page carrying the sidebar, not only from inside the chat.
       The response carries both out-of-band spans, so the heading follows if
       this happens to be the open chat. #}
    <button class="btn btn--icon btn--sm" type="button"
            hx-patch="/api/chats/{{ chat_item.id }}" hx-swap="none"
            data-prompt="What should this chat be called?"
            data-prompt-title="Rename chat" data-prompt-field="title"
            data-prompt-value="{{ chat_item.title }}"
            aria-label="Rename chat" title="Rename chat">
      {{ icon("pencil", "icon--sm") }}
    </button>
    <button class="btn btn--icon btn--sm" type="button"
            hx-delete="/api/chats/{{ chat_item.id }}"
            hx-confirm="Delete “{{ chat_item.title }}”? This cannot be undone."
            data-confirm-title="Delete chat"
            hx-swap="none"
            aria-label="Delete chat">
      {{ icon("trash", "icon--sm") }}
    </button>
  </span>
</div>
