<%= render partial: 'template_folders/folder', collection: @template_folders, as: :folder %>
<%= render 'shared/infinite_scroll', pagy: @pagy if turbo_native_app? && @templates.blank? %>
<% end %>
<% if @pagy.count.nil? || @pagy.count > 0 %>
<%= render partial: 'templates/template', collection: @templates %>
<%= render 'shared/infinite_scroll', pagy: @pagy if turbo_native_app? && @templates.present? %>
<% templates_order_select_html = capture do %>
<% if params[:q].blank? && @pagy.pages > 1 && !can?(:manage, :countless) %>
<%= render 'shared/templates_order_select', with_recently_used: @pagy.count.present? && @pagy.count < 10_000, selected_order: %>
<% end %>
<% end %>
<%= render 'shared/pagination', pagy: @pagy, items_name: @templates.present? ? 'templates' : 'template_folders', right_additional_html: templates_order_select_html %>
<% elsif params[:q].present? %>
<%= t('templates_not_found') %>
<% if @related_submissions.present? %>
<%= render partial: 'templates/submission', collection: @related_submissions, locals: { with_template: true } %>
<%= render 'shared/pagination', pagy: @related_submissions_pagy, items_name: 'submissions', next_page_path: submissions_path(q: params[:q], folder: @template_folder.full_name) %>
<% end %>
<% end %>