<%# locals: (chat:) %>

<nav class="flex items-center justify-between">
  <% path = chat.new_record? ? chats_path : chats_path(previous_chat_id: chat.id) %>

  <div class="flex items-center gap-2 grow">
    <%= link_to path, id: "chat-nav-back", class: "w-9 h-9 flex items-center justify-center rounded-lg hover:bg-surface-hover" do %>
      <%= icon("menu", color: "gray" ) %>
    <% end %>

    <div class="grow">
      <%= render "chats/chat_title", chat: chat, ctx: "chat" %>
    </div>
  </div>

  <%= contextual_menu icon: "more-vertical", id: "chat-menu" do %>
    <%= contextual_menu_item "Start new chat", url: new_chat_path, icon: "plus" %>

    <% unless chat.new_record? %>
      <%= contextual_menu_item "Edit chat title", url: edit_chat_path(chat, ctx: "chat"), icon: "pencil", turbo_frame: dom_id(chat, "title") %>
      <%= contextual_menu_destructive_item "Delete chat", chat_path(chat), turbo_confirm: "Are you sure you want to delete this chat?" %>
    <% end %>
  <% end %>
</nav>
