/ div id=dom_id(report, :page_nav)
= turbo_frame_tag(dom_id(report, :page_nav)) do
  - if current_page
    ul.nav.nav-underline
      li.nav-item 
        = link_to("Baum", report_path(report, page_id: current_page.id, pnm: :n), class: "nav-link #{@page_nav_mode != :comment ? "active" : nil}", data: { hotkey: "b", controller: :hotkey })
      li.nav-item 
        = link_to("Notizen", report_path(report, page_id: current_page.id, pnm: :c), class: "nav-link #{@page_nav_mode == :comment ? "active" : nil}", data: { hotkey: "n", controller: :hotkey })
  - if @page_nav_mode != :comment || current_page.nil?
    - if report.pages.any?
      nav.mt-3 id=dom_id(report, :page_nav_spy)
        ul data={ controller: :sortable }
          - report.pages.each do |page|
            - is_current = current_page == page
            li  data={ "sortable-url": page_path(page), "form-name": "page", "position-attribute": "position" }
              details.tree open=current_page_displayed(page) class=""
                summary.d-flex class=(is_current ? "active" : nil)
                  .content.flex-fill
                    i.bi.me-1 class="bi-file-earmark-check#{is_current ? "" : "" }"
                    - if is_current
                        span id=dom_id(page, :title) =< "#{page.position} #{page.path}" 
                    - else
                      =< link_to(report_path(report, page_id: page.id), data: { "turbo-frame": :_top }) do
                        span id=dom_id(page, :title) =< "#{page.position} #{page.path}" 
                  i.bi.bi-grip-vertical.align-self-end.handle
                ul id=dom_id(page, :page_nav_elements) data={ controller: "sortable", "linked-element-id": "element_list" }
                  - page.elements.each do |element| 
                    = render partial: "elements/page_nav_row", locals: { element: element, current_page: current_page == element.page }
                    /li 
                      - if current_page == page
                        =< link_to("##{dom_id(element)}", data: { "turbo": false }) do
                          i.bi.bi-boxes.me-1
                          =< "#{element.number} #{element.title}"
                      - else 
                        =< link_to(report_path(report, page_id: page.id, anchor: dom_id(element)), data: { "turbo": false }) do
                          i.bi.bi-boxes.me-1
                          =< "#{element.number} #{element.title}"
    = turbo_frame_tag "new_page_frame" do
      = render partial: "reports/new_page_button", locals: { report: report }
  - else
    - if current_page
      = turbo_frame_tag(dom_id(current_page, :notes)) do 
        = render partial: "pages/notes", locals: { page: current_page }
