h1 = Submission.model_name.human(count: 2)

= render(layout: 'shared/form_filters') do |f|
  .col-auto
    = f.label(:exercise_id_eq, t('activerecord.attributes.submission.exercise'), class: 'visually-hidden form-label')
    = f.collection_select(:exercise_id_eq, Exercise.with_submissions, :id, :title, class: 'form-control', prompt: t('activerecord.attributes.submission.exercise'))
  .col-auto
    = f.label(:cause_eq, t('activerecord.attributes.submission.cause'), class: 'visually-hidden form-label')
    = f.select(:cause_eq, Submission.select(:cause).distinct.map(&:cause).sort, class: 'form-control', prompt: t('activerecord.attributes.submission.cause'))

.table-responsive
  table.table.mt-4
    thead
      tr
        th = sort_link(@search, :exercise_id, t('activerecord.attributes.submission.exercise'))
        th = sort_link(@search, :user_id, t('activerecord.attributes.submission.contributor'))
        th = sort_link(@search, :cause, t('activerecord.attributes.submission.cause'))
        th = sort_link(@search, :score, t('activerecord.attributes.submission.score'))
        th = sort_link(@search, :created_at, t('shared.created_at'))
        th colspan=2 = t('shared.actions')
    tbody
      - @submissions.each do |submission|
        tr
          td = link_to_if(submission.exercise && policy(submission.exercise).show?, submission.exercise, submission.exercise)
          td = link_to_if(submission.contributor.is_a?(User) && policy(submission.contributor).show?, submission.contributor, submission.contributor)
          td = t("submissions.causes.#{submission.cause}")
          td = submission.score
          td = l(submission.created_at, format: :short)
          td = link_to(t('shared.show'), submission) if policy(submission).show? && submission.exercise
          td = link_to(t('shared.statistics'), statistics_submission_path(submission)) if policy(submission).statistics?

= render('shared/pagination', collection: @submissions)
