<%= render 'title', template: @template %> <% is_filter_active = params.slice(:author, :created_at, :completed_at).to_unsafe_h.any?(&:present?) %> <% is_show_tabs = @pagy.pages > 1 || params[:q].present? || params[:status].present? || is_filter_active %> <% if !@pagy.count.zero? || params[:q].present? || params[:status].present? || is_filter_active %>

<%= t('submissions') %>

<% if params[:q].present? || params[:status].present? || is_filter_active || @pagy.pages > 1 %> <%= render 'shared/search_input', title_selector: 'h2' %> <% end %> <%= link_to new_template_submissions_export_path(@template), class: 'hidden md:flex btn btn-ghost text-base', data: { turbo_frame: 'modal' } do %> <%= svg_icon('download', class: 'w-6 h-6 stroke-2') %> <%= t('export') %> <% end %> <% if !@template.archived_at? && can?(:create, Submission) %> <%= link_to new_template_submission_path(@template), class: 'white-button !border', data: { turbo_frame: 'modal' } do %> <%= svg_icon('plus', class: 'w-6 h-6 stroke-2') %> <%= t('add_recipients_html') %> <% end %> <% end %>
<% end %> <% if is_show_tabs %>
<%= svg_icon('list', class: 'w-5 h-5') %> <%= t('all') %>
<%= params[:status].blank? ? @pagy.count : @base_submissions.count %>
<%= svg_icon('clock', class: 'w-5 h-5') %> <%= t('pending') %>
<%= params[:status] == 'pending' ? @pagy.count : @base_submissions.pending.count %>
<%= svg_icon('circle_check', class: 'w-5 h-5') %> <%= t('completed') %>
<%= params[:status] == 'completed' ? @pagy.count : @base_submissions.completed.count %>
<% if completed_at_range.present? %>
<%= link_to filter_templates_path(params.to_unsafe_h.except(:controller, :action).merge(filter: 'completed_at')), data: { turbo_frame: 'modal' }, class: 'flex items-center space-x-1' do %> <%= svg_icon('calendar_check', class: 'w-5 h-5 shrink-0') %> <% if completed_at_range.begin&.to_date == completed_at_range.end&.to_date %> <%= l(completed_at_range.begin.to_date, locale: current_account.locale) %> <% else %> <%= completed_at_range.begin ? l(completed_at_range.begin.to_date, locale: current_account.locale) : '∞' %> - <%= completed_at_range.end ? l(completed_at_range.end.to_date, locale: current_account.locale) : t('today') %> <% end %> <% end %> <%= link_to url_for(params.to_unsafe_h.except(:completed_at)), class: 'rounded-lg ml-1 hover:bg-neutral-700 hover:text-white' do %> <%= svg_icon('x', class: 'w-5 h-5') %> <% end %>
<% end %> <% if @created_at_range.present? %>
<%= link_to filter_templates_path(params.to_unsafe_h.except(:controller, :action).merge(filter: 'created_at')), data: { turbo_frame: 'modal' }, class: 'flex items-center space-x-1' do %> <%= svg_icon('calendar', class: 'w-5 h-5 shrink-0') %> <% if created_at_range.begin&.to_date == created_at_range.end&.to_date %> <%= l(created_at_range.begin.to_date, locale: current_account.locale) %> <% else %> <%= created_at_range.begin ? l(created_at_range.begin.to_date, locale: current_account.locale) : '∞' %> - <%= created_at_range.end ? l(created_at_range.end.to_date, locale: current_account.locale) : t('today') %> <% end %> <% end %> <%= link_to url_for(params.to_unsafe_h.except(:created_at)), class: 'rounded-lg ml-1 hover:bg-neutral-700 hover:text-white' do %> <%= svg_icon('x', class: 'w-5 h-5') %> <% end %>
<% end %> <% if params[:author].present? %>
<%= link_to filter_templates_path(params.to_unsafe_h.except(:controller, :action).merge(filter: 'author')), data: { turbo_frame: 'modal' }, class: 'flex items-center space-x-1 w-full md:w-36' do %> <%= svg_icon('user', class: 'w-5 h-5 shrink-0') %> <%= params[:author] %> <% end %> <%= link_to url_for(params.to_unsafe_h.except(:author)), class: 'rounded-lg ml-1 hover:bg-neutral-700 hover:text-white' do %> <%= svg_icon('x', class: 'w-5 h-5') %> <% end %>
<% end %>
<% end %> <% if @submissions.present? %>
<%= render partial: 'submission', collection: @submissions, locals: { template: @template } %>
<% else %>

<%= t('there_are_no_submissions') %>

<% if @template.archived_at.blank? && params[:q].blank? %>

<%= t('send_an_invitation_to_fill_and_complete_the_form') %>

<% if can?(:create, Submission) %> <%= link_to new_template_submission_path(@template, with_link: true), class: 'base-button mt-6', data: { turbo_frame: 'modal' } do %> <%= svg_icon('plus', class: 'w-6 h-6 stroke-2') %> <%= t('send_to_recipients') %> <% end %> <% end %> <% if @template.submitters.size == 1 %> <%= link_to start_form_url(slug: @template.slug), class: 'white-button mt-6', target: '_blank', rel: 'noopener' do %> <%= svg_icon('writing', class: 'w-6 h-6') %> <%= t('sign_it_yourself') %> <% end %> <% else %> <%= link_to new_template_submission_path(@template, selfsign: true), class: 'white-button mt-6', data: { turbo_frame: 'modal' } do %> <%= svg_icon('writing', class: 'w-6 h-6') %> <%= t('sign_it_yourself') %> <% end %> <% end %>
<% end %>
<% end %> <% view_archived_html = capture do %> <% if @template.submissions.where.not(archived_at: nil).exists? && !@template.archived_at? %>
<%= t('view_archived') %>
<% end %> <% end %> <% if @pagy.pages > 1 %> <%= render 'shared/pagination', pagy: @pagy, items_name: 'submissions', left_additional_html: view_archived_html %> <% else %>
<%= view_archived_html %>
<% end %>