<% @page_title = @query ? "Search results for \"#{@query}\"" : "Search" %>

<% content_for :header do %>
  <div class="header__actions header__actions--start">
    <%= back_link_to "Home", root_path, "keydown.left@document->hotkey#click keydown.esc@document->hotkey#click" %>
  </div>

  <h1 class="header__title" data-bridge--title-target="header"><%= @page_title %></h1>
<% end %>

<div class="search-perma margin-block-start">
  <%= render "form", query_terms: @query, turbo_action: "advance", target_turbo_frame: "bar_content" %>
  <%= turbo_frame_tag "bar_content" do %>
    <% if @card %>
      <%= auto_submit_form_with url: card_path(@card), method: :get, data: { turbo_action: "advance", turbo_frame: "_top", search_redirect: true } %>
    <% else %>
      <%= render "results", page: @page, query: @query %>
    <% end %>
  <% end %>
</div>
