<% filter_params = params.permit(Submissions::Filter::ALLOWED_PARAMS).compact_blank %>
<% is_show_tabs = (@pagy.count.nil? || @pagy.count >= 5) || params[:status].present? || filter_params.present? %>
<% if Docuseal.demo? %><%= render 'shared/demo_alert' %><% end %>
<div class="flex justify-between items-center w-full mb-4">
  <div class="flex items-center flex-grow min-w-0">
    <div class="mr-2">
      <%= render 'dashboard/toggle_view', selected: 'submissions' %>
    </div>
    <h1 class="text-2xl truncate md:text-3xl sm:text-4xl font-bold md:block <%= 'hidden' if params[:q].present? %>">
      <%= t('submissions') %>
    </h1>
  </div>
  <div class="flex space-x-2">
    <% if params[:q].present? || @pagy.pages > 1 || filter_params.present? %>
      <%= render 'shared/search_input' %>
    <% end %>
    <% if can?(:create, ::Template) %>
      <span class="hidden sm:block">
        <%= render 'templates/upload_button' %>
      </span>
      <%= link_to new_template_path, class: 'white-button !border gap-2', data: { turbo_frame: :modal } do %>
        <%= svg_icon('plus', class: 'w-6 h-6 stroke-2') %>
        <span class="hidden md:block"><%= t('create') %></span>
      <% end %>
    <% end %>
  </div>
</div>
<% view_archived_html = capture do %>
  <% if current_account.submissions.where.not(archived_at: nil).exists? %>
    <div>
      <a href="<%= submissions_archived_index_path %>" class="link text-sm"><%= t('view_archived') %></a>
    </div>
  <% end %>
<% end %>
<% if is_show_tabs %>
  <div class="flex items-center flex-col md:flex-row md:flex-wrap gap-2 mb-4">
    <div class="flex items-center md:items-end flex-col md:flex-row gap-2 w-full md:w-fit">
      <a href="<%= url_for(params.to_unsafe_h.except(:status)) %>" class="<%= params[:status].blank? ? 'border-neutral-700' : 'border-neutral-300' %> flex h-10 px-2 py-1 text-lg items-center justify-between border text-center text-neutral font-semibold rounded-xl w-full md:w-48 hover:border-neutral-600">
        <div class="flex items-center space-x-1">
          <%= svg_icon('list', class: 'w-5 h-5') %>
          <span class="font-normal"><%= t('all') %></span>
        </div>
      </a>
      <a href="<%= url_for(params.to_unsafe_h.merge(status: :pending)) %>" class="<%= params[:status] == 'pending' ? 'border-neutral-700' : 'border-neutral-300' %> flex h-10 px-2 py-1 text-lg items-center justify-between border text-center text-neutral font-semibold rounded-xl w-full md:w-48 hover:border-neutral-600">
        <div class="flex items-center space-x-1">
          <%= svg_icon('clock', class: 'w-5 h-5') %>
          <span class="font-normal"><%= t('pending') %></span>
        </div>
      </a>
      <a href="<%= url_for(params.to_unsafe_h.merge(status: :completed)) %>" class="<%= params[:status] == 'completed' ? 'border-neutral-700' : 'border-neutral-300' %> flex h-10 px-2 py-1 text-lg items-center justify-between border text-center text-neutral font-semibold rounded-xl w-full md:w-48 hover:border-neutral-600">
        <div class="flex items-center space-x-1">
          <%= svg_icon('circle_check', class: 'w-5 h-5') %>
          <span class="font-normal"><%= t('completed') %></span>
        </div>
      </a>
    </div>
    <div class="flex items-end flex-col md:flex-row gap-2 w-full md:w-fit">
      <%= render 'submissions_filters/applied_filters', filter_params: %>
      <%= render 'submissions_filters/filter_button', filter_params: %>
      <%= render 'submissions_filters/actions', filter_params: %>
    </div>
  </div>
<% end %>
<% if @pagy.count.nil? || @pagy.count > 0 %>
  <div class="space-y-4">
    <%= render partial: 'templates/submission', collection: @submissions, locals: { with_template: true } %>
  </div>
<% end %>
<% if params[:q].blank? && params[:status].blank? && filter_params.blank? && @pagy.count.present? && @pagy.count < 5 %>
  <%= render 'templates/dropzone' %>
<% end %>
<% if @submissions.present? || (params[:q].blank? && filter_params.blank?) %>
  <% if @pagy.pages > 1 %>
    <%= render 'shared/pagination', pagy: @pagy, items_name: 'submissions', left_additional_html: view_archived_html %>
  <% else %>
    <div class="mt-2">
      <%= view_archived_html %>
    </div>
  <% end %>
<% elsif params[:q].present? || filter_params.present? %>
  <div class="text-center">
    <div class="mt-16 text-3xl font-semibold">
      <%= t('submissions_not_found') %>
    </div>
  </div>
<% end %>
