<%= content_for :title, t(:'assets.title') %>

<% if request.query_string.blank? %>
  
<turbo-stream action="append" targets="body">
    <template>  
      <div id="overlay" class="overlay" data-controller="utils assets" data-action="click->utils#closeOverlay" data-assets-url-value="<%= url_for(controller: 'attachments', action: 'new', screen_id: params[:screen_id] ) %>">
          
        <div class="inner-window-container">
          <%= button_tag 'close', class: 'close-overlay', data: { action: "click->utils#closeOverlay" } %>

          <div id="inner-window">
            <%= render partial: 'list', formats: :html %>        

            <div class="form-ctrls form-ctrls-overlay">      
              <%= button_tag t(:'ui.append'), data: { action: "click->assets#appendAttachments" } %>
            </div>            
          </div>
        </div>
      </div>
    </template>
  </turbo-stream>

<% else %>

  <turbo-stream action="<%= @assets.first_page? ? 'update' : 'append' %>" target="assets">
    <template>
        <%= render partial: 'asset', 
                   collection: @assets, 
                   formats: :html %>    
    </template>
  </turbo-stream>

  <turbo-stream action="replace" target="asset__sort">
    <template>
      <%= render partial: 'sort', formats: :html %>
    </template>
  </turbo-stream>

  <turbo-stream action="replace" target="load-more">
    <template>
      <% if @assets.blank? or @assets.last_page? %>
        <div id='load-more'></div>
      <% else %>
        <%= tag.div nil,
                    id: 'load-more',
                    data: {
                      controller: "load-more",
                      load_more_list_id_value: "results",
                      load_more_url_value: path_to_next_page(@assets)
                    } %>
      <% end %>
    </template>
  </turbo-stream>

<% end %>