<div>
  <h2>_{MsgCorrectionSheets}

  _{MsgCourseParticipants nrParticipants}
  <table .table .table--striped .table--hover>
    <tr .table__row .table__row--head>
      <th .table__th rowspan=2>_{MsgSheet}
      $if groupsPossible
        <th .table__th rowspan=2>_{MsgNrSubmittorsTotal}
      <th .table__th rowspan=2>_{MsgNrSubmissionsTotal}
      <th .table__th colspan=2>_{MsgNrSubmissionsNotAssigned}
      <th .table__th rowspan=2>_{MsgNrSubmissionsNotCorrected}
      <th .table__th colspan=3>_{MsgCorrectionTime}
    <tr .table__row .table__row--head>
      <th .table__th>
      <th .table__th>_{MsgGenericNumChange}
      <th .table__th>_{MsgGenericMin}
      <th .table__th>_{MsgGenericAvg}
      <th .table__th>_{MsgGenericMax}
    $#  Always iterate over orderedSheetNames for consistent sorting! Newest first, except in this table
    $forall sheetName <- reverse orderedSheetNames
      $maybe CorrectionInfo{ciSubmittors, ciSubmissions, ciAssigned, ciCorrected, ciMin, ciTot, ciMax} <- Map.lookup sheetName sheetMap
        <tr .table__row>
          <td .table__td>^{simpleLink (toWidget sheetName) (CSheetR tid ssh csh sheetName SSubsR)}
          $if groupsPossible
            <td .table__td>#{ciSubmittors}
          <td .table__td>#{ciSubmissions}
          $maybe ((splus,sfailed),_,_) <- Map.lookup sheetName assignment
            $if 0 < Set.size sfailed
              <td .table__td>#{ciSubmissions - ciAssigned}
              <td .table__td .alert-danger>(-#{show (Set.size splus)}, failed: #{show (Set.size sfailed)})
            $elseif 0 < Set.size splus
              <td .table__td>#{ciSubmissions - ciAssigned}
              <td .table__td .alert-info>(-#{show (Set.size splus)})
            $else
              <td .table__td>#{ciSubmissions - ciAssigned}
              <td .table__td>
          $nothing
            <td .table__td>#{ciSubmissions - ciAssigned}
            <td .table__td>
          <td .table__td>#{ciSubmissions - ciCorrected}
          <td .table__td>#{showDiffDays ciMin}
          <td .table__td>#{showAvgsDays ciTot ciCorrected}
          <td .table__td>#{showDiffDays ciMax}


<div>
  <h2>_{MsgCorrectionCorrectors}

  <table .table .table--striped .table--hover>
    <tr .table__row .table__row--head>
      <th .table__th rowspan=2>_{MsgCorrector}
      <th .table__th colspan=2>_{MsgGenericAll}
      <th .table__th rowspan=2>_{MsgCorDeficitProportion}
      <th .table__th colspan=3>_{MsgCorrectionTime}

      $#  Always iterate over orderedSheetNames for consistent sorting! Newest first, except in this table
      $forall shn <- orderedSheetNames
        <th .table__th colspan=5>
          ^{simpleLink (toWidget shn) (CSheetR tid ssh csh shn SShowR)}
    <tr .table__row .table__row--head>
      <th .table__th>_{MsgNrSubmissionsTotal}
      <th .table__th>_{MsgNrSubmissionsNotCorrected}
      <th .table__th>_{MsgGenericMin}
      <th .table__th>_{MsgGenericAvg}
      <th .table__th>_{MsgGenericMax}
      $#  Always iterate over orderedSheetNames for consistent sorting! Newest first, except in this table
      $forall _shn <- orderedSheetNames
        <th .table__th>_{MsgCorProportion}
        <th .table__th>_{MsgNrSubmissionsTotalShort}
        <th .table__th>_{MsgGenericNumChange}
        <th .table__th>_{MsgNrSubmissionsNotCorrectedShort}
        <th .table__th>_{MsgGenericAvg}
    $forall (CorrectionInfo{ciCorrector, ciSubmissions=ciSubmissionsNr, ciCorrected, ciMin, ciTot, ciMax}) <- corrInfos
      $with (nameW,loadM, name) <- getCorrector ciCorrector
        $# TODO: User proper Tooltips instead of title attribute here, once Tooltips work with tables
        <tr .table__row title="#{name}">
          <td .table__td>^{nameW}
          <td .table__td>#{ciSubmissionsNr}
            $with total <- ciSubmissions corrMapSum
              $if total > 0
                \ (#{textPercent' True 0 ciSubmissionsNr total})
          <td .table__td .heated style="--hotness: #{heat ciSubmissionsNr ciCorrected}">#{ciSubmissionsNr - ciCorrected}
          <td .table__td>
              $maybe deficit <- getCorrDeficit ciCorrector
                #{rationalToFixed3 deficit}
          <td .table__td>#{showDiffDays ciMin}
          <td .table__td>#{showAvgsDays ciTot ciCorrected}
          <td .table__td>#{showDiffDays ciMax}
          $#  Always iterate over orderedSheetNames for consistent sorting! Newest first, except in this table
          $forall shn <- orderedSheetNames
            $maybe CorrectionInfo{ciSubmissions=sheetSubmissionsNr} <- Map.lookup shn sheetMap
              <td .table__td>
                $maybe SheetCorrector{sheetCorrectorLoad, sheetCorrectorState} <- Map.lookup shn loadM
                  #{showCompactCorrectorLoad sheetCorrectorLoad sheetCorrectorState}
                  $if sheetCorrectorState == CorrectorNormal
                    $maybe Load{byProportion=total} <- Map.lookup shn sheetLoad
                      $if total > 0
                        \ (#{textPercent' True 0 (byProportion sheetCorrectorLoad) total})
              $maybe CorrectionInfo{ciSubmissions,ciCorrected,ciTot} <- getCorrSheetStatus ciCorrector shn
                <td .table__td>#{ciSubmissions}
                  $if sheetSubmissionsNr > 0
                    \ (#{textPercent' True 0 ciSubmissions sheetSubmissionsNr})
                $maybe nrNew <- getCorrNewAssignment ciCorrector shn
                  $# <td .table__td>#{ciAssigned} `ciSubmissions` is here always identical to `ciAssigned` and also works for `ciCorrector == Nothing`. ciAssigned only useful in aggregate maps like `sheetMap`
                  <td .table__td .alert-info>(+#{nrNew})
                $nothing
                  <td .table__td>
                <td .table__td .heated style="--hotness: #{heat ciSubmissions ciCorrected}">#{ciSubmissions - ciCorrected}
                <td .table__td>#{showAvgsDays ciTot ciCorrected}
              $nothing
                <td .table__td>
                <td .table__td>
                <td .table__td>
                <td .table__td>
    $if not (null orderedSheetNames)
      <tr .table__row>
        <td .table__th>Σ
        $with ciSubmissionsNr <- ciSubmissions corrMapSum
          $with ciCorrectedNr <- ciCorrected   corrMapSum
            <td .table__th>#{ciSubmissionsNr}
            <td .table__td .heated style="--hotness: #{heat ciSubmissionsNr ciCorrectedNr}">#{ciSubmissionsNr - ciCorrectedNr}
        <td .table__th>#{ciCorrected   corrMapSum}
        <td .table__th>#{showDiffDays (ciMin corrMapSum)}
        <td .table__th>#{showAvgsDays (ciTot corrMapSum) (ciCorrected corrMapSum)}
        <td .table__th>#{showDiffDays (ciMax corrMapSum)}
        $#  Always iterate over orderedSheetNames for consistent sorting! Newest first, except in this table
        $forall shn <- orderedSheetNames
          $maybe CorrectionInfo{ciSubmissions} <- Map.lookup shn sheetMap
            <td .table__th>#{getLoadSum shn}
            <td .table__th>#{ciSubmissions}
            <td .table__td colspan=3>^{simpleLinkI (SomeMessage MsgMenuCorrectorsChange) (CSheetR tid ssh csh shn SEditR)}

      <tr .table__row .table__row--head>
        <th>
        <th colspan=2>
        <th>
        <th colspan=3>
        $#  Always iterate over orderedSheetNames for consistent sorting! Newest first, except in this table
        $forall shn <- orderedSheetNames
          <th .table__th colspan=5>
            ^{simpleLink (toWidget shn) (CSheetR tid ssh csh shn SShowR)}

  ^{btnWdgt}
 <div>
  <p>_{MsgAssignSubmissionsRandomWarning}
