<%= render 'shared/logo' %> <%= @submission.template.name %>
<% if last_submitter = @submission.submitters.select(&:completed_at?).max_by(&:completed_at) %> <%= svg_icon('download', class: 'w-6 h-6') %> Download <% end %>
<% @submission.template.schema.each do |item| %> <% document = @submission.template.documents.find { |a| item['attachment_uuid'] == a.uuid } %> " onclick="[event.preventDefault(), window[event.target.closest('a').href.split('#')[1]].scrollIntoView({ behavior: 'smooth', block: 'start' })]" class="block cursor-pointer">
<%= item['name'].presence || document.filename.base %>
<% end %>
<% fields_index = Templates.build_field_areas_index(@submission.template) %> <% values = @submission.submitters.reduce({}) { |acc, sub| acc.merge(sub.values) } %> <% attachments_index = ActiveStorage::Attachment.where(record: @submission.submitters, name: :attachments).preload(:blob).index_by(&:uuid) %> <% @submission.template.schema.each do |item| %> <% document = @submission.template.documents.find { |e| e.uuid == item['attachment_uuid'] } %> <% document.preview_images.sort_by { |a| a.filename.base.to_i }.each_with_index do |page, index| %>
" class="relative">
<% fields_index.dig(document.uuid, index)&.each do |(area, field)| %> <% value = values[field['uuid']] %> <% next if value.blank? %> <%= render 'submissions/value', area:, field:, attachments_index:, value:, locale: current_account.locale %> <% end %>
<% end %> <% end %>
<% colors = %w[bg-red-500 bg-sky-500 bg-emerald-500 bg-yellow-300 bg-purple-600] %> <% submitter_fields_index = @submission.template.fields.group_by { |f| f['submitter_uuid'] } %> <% @submission.template.submitters.each_with_index do |item, index| %> <% submitter = @submission.submitters.find { |e| e.uuid == item['uuid'] } %>
<%= @submission.template.submitters.find { |e| e['uuid'] == submitter&.uuid }&.dig('name') || "#{(index + 1).ordinalize} Submitter" %>
<%= svg_icon('mail', class: 'w-5 h-5') %> <%= submitter&.email || 'N/A' %>
<%= svg_icon('writing', class: 'w-5 h-5') %> <%= submitter&.completed_at? ? l(submitter.completed_at, format: :long) : 'Not completed yet' %>
<% if submitter && !submitter.completed_at? %> <% end %>
<% submitter_field_counters = Hash.new { 0 } %> <% submitter_fields_index[item['uuid']].to_a.each_with_index do |field, index| %> <% submitter_field_counters[field['type']] += 1 %> <% value = values[field['uuid']] %> <% next if value.blank? %>
<%= field['name'].presence || "#{field['type'].titleize} Field #{submitter_field_counters[field['type']]}" %>
<% if field['type'] == 'signature' %>
<% elsif field['type'] == 'image' %> <% elsif field['type'] == 'file' %> <% elsif field['type'] == 'checkbox' %> <%= svg_icon('check', class: 'w-6 h-6') %> <% elsif field['type'] == 'date' %> <%= l(Date.parse(value), locale: current_account.locale, format: :long) %> <% else %> <%= Array.wrap(value).join(', ') %> <% end %>
<% end %>
<% end %>