<div data-controller="sortable">
  <%= form_with url: helpers.spina.sort_admin_pages_path, data: {sortable_target: "form"} do |f| %>
  <% end %>
  
  <div data-controller="infinite-scroll">
    <% if paginated %>
      <turbo-frame id="pages">
        <turbo-frame id="pages-<%= @pages.current_page %>" data-sortable-target="list">
          <%= render Spina::Pages::PageComponent.with_collection(@pages, sortable: sortable, draggable: draggable) %>
          
          <% if @pages.next_page %>
            <turbo-frame id="pages-<%= @pages.next_page %>" data-action="turbo:frame-load->infinite-scroll#load">
              <%= link_to t('spina.ui.load_more'), helpers.path_to_next_page(@pages), class: "btn btn-default", data: {infinite_scroll_target: "button"} %>
            </turbo-frame>
          <% end %>
        </turbo-frame>
      </turbo-frame>
    <% else %>
      <div data-sortable-target="list">
        <%= render Spina::Pages::PageComponent.with_collection(@pages, sortable: sortable, draggable: draggable) %>
      </div>
    <% end %>
  </div>
</div>