$newline never
$maybe Entity _ ExamResult{examResultResult} <- result
  $if gradingShown
    <section>
      <h2>
        _{MsgExamResult}
        $if gradingShown && not gradingVisible
          \ ^{isVisible False}
      <p .result>
        $case examResultResult
          $of ExamAttended grade
            $if examShowGrades
              _{grade}
            $else
              $if view (passingGrade . _Wrapped) grade
                _{MsgExamPassed}
              $else
                _{MsgExamNotPassed}
          $of ExamNoShow
            _{MsgExamNoShow}
          $of ExamVoided
            _{MsgExamVoided}

$maybe desc <- examDescription
  <section>
    #{desc}

<section>
  <dl .deflist>
    $if not examVisible
      <dt .deflist__dt>_{MsgExamVisibleFrom}
      <dd .deflist__dd>
        $maybe from <- examVisibleFrom
          ^{formatTimeW SelFormatDateTime from}
        $nothing
          _{MsgNever}
        \ ^{isVisible False}
    $maybe regFrom <- examRegisterFrom
      <dt .deflist__dt>_{MsgExamRegisterFrom}
      <dd .deflist__dd>^{formatTimeW SelFormatDateTime regFrom}
    $maybe regTo <- examRegisterTo
      <dt .deflist__dt>_{MsgExamRegisterTo}
      <dd .deflist__dd>^{formatTimeW SelFormatDateTime regTo}
    $maybe deregUntil <- examDeregisterUntil
      <dt .deflist__dt>_{MsgExamDeregisterUntil}
      <dd .deflist__dd>^{formatTimeW SelFormatDateTime deregUntil}
    $maybe publishAssignments <- examPublishOccurrenceAssignments
      <dt .deflist__dt>_{MsgExamPublishOccurrenceAssignmentsParticipant}
      <dd .deflist__dd>^{formatTimeW SelFormatDateTime publishAssignments}
    $if examTimes
      <dt .deflist__dt>_{MsgExamTime}
      <dd .deflist__dd>
        $maybe start <- examStart
          ^{formatTimeRangeW SelFormatDateTime start examEnd}
    $maybe finished <- examFinished
      <dt .deflist__dt>_{MsgExamFinishedParticipant}
      <dd .deflist__dd>^{formatTimeW SelFormatDateTime finished}
    $if examClosedShown
      $maybe closed <- examClosed
        <dt .deflist__dt>_{MsgExamClosed} ^{isVisible False}
        <dd .deflist__dd>^{formatTimeW SelFormatDateTime closed}
    $if gradingShown
      $maybe gradingRule <- examGradingRule
        <dt .deflist__dt>
          _{MsgExamGradingRule}
          $if not gradingVisible
            \ ^{isVisible False}
        <dd .deflist__dd>
          $case gradingRule
            $of ExamGradingKey{..}
              ^{gradingKeyW examGradingKey}
      $maybe bonusRule <- examBonusRule
        <dt .deflist__dt>
          _{MsgExamBonusRule}
          $if not gradingVisible
            \ ^{isVisible False}
        <dd .deflist__dd>
          ^{examBonusW bonusRule}
    $if examOccurrenceRule /= ExamRoomManual
      $if occurrenceAssignmentsShown
        <dt .deflist__dt>
          _{MsgExamOccurrenceRuleParticipant}
          $if not occurrenceAssignmentsVisible
            \ ^{isVisible False}
        <dd .deflist__dd>
          _{classifyExamOccurrenceRule examOccurrenceRule}
    $maybe registerWdgt <- registerWidget Nothing
      <dt .deflist__dt>_{MsgExamRegistration}
      <dd .deflist__dd>^{registerWdgt}


$if not (null occurrences)
  <section>
    <h2>
      $if examTimes
        _{MsgExamOccurrences}
      $else
        _{MsgExamRooms}
    <table .table .table--striped .table--hover>
      <thead>
        <tr .table__row .table__row--head>
          $if occurrenceNamesShown
            <th .table__th>
              _{MsgExamRoomName}
              \ ^{isVisible False}
          <th .table__th>_{MsgExamRoom}
          $if not examTimes
            <th .table__th>_{MsgExamRoomTime}
          $if showOccurrenceRegisterColumn
            <th .table__th>
              $if examOccurrenceRule == ExamRoomFifo
                _{MsgExamRoomRegistered}
              $else
                _{MsgExamRoomAssigned}
              $if not occurrenceAssignmentsVisible
                \ ^{isVisible False}
          <th .table__th>_{MsgExamRoomDescription}
      <tbody>
        $forall (occurrence, registered) <- occurrences
          $with Entity _occId ExamOccurrence{examOccurrenceName, examOccurrenceRoom, examOccurrenceStart, examOccurrenceEnd, examOccurrenceDescription} <- occurrence
            $with registerWdgt <- registerWidget (Just occurrence)
              <tr .table__row :markUnregisteredOccurrences (Just occurrence) && not registered:.occurrence--not-registered>
                $if occurrenceNamesShown
                  <td .table__td #exam-occurrence__#{examOccurrenceName}>#{examOccurrenceName}
                <td .table__td>#{examOccurrenceRoom}
                $if not examTimes
                  <td .table__td>
                    ^{formatTimeRangeW SelFormatDateTime examOccurrenceStart examOccurrenceEnd}
                $if showOccurrenceRegisterColumn
                  <td .table__td>
                    $maybe registerWdgt' <- registerWdgt
                      ^{registerWdgt'}
                    $nothing
                      $if registered
                        #{iconOK}
                <td .table__td>
                  $maybe desc <- examOccurrenceDescription
                    #{desc}

$if gradingShown && not (null examParts)
  <section>
    <h2>
      _{MsgExamParts}
      $if gradingShown && not gradingVisible
        \ ^{isVisible False}
    <table .table .table--striped .table--hover >
      <thead>
        <tr .table__row .table__row--head>
          $if partNumbersShown
            <th .table__th>
              _{MsgExamPartNumber} ^{isVisible False}
          <th .table__th>_{MsgExamPartName}
          $if showMaxPoints
            <th .table__th>_{MsgExamPartMaxPoints}
          $if showAchievedPoints
            <th .table__th>_{MsgExamPartResultPoints}
      <tbody>
        $forall Entity partId ExamPart{examPartNumber, examPartName, examPartWeight, examPartMaxPoints} <- examParts
          <tr .table__row>
            $if partNumbersShown
              <td .table__td>#{examPartNumber}
            <td .table__td>
              $maybe pName <- examPartName
                #{pName}
              $nothing
                _{MsgExamPartNumbered examPartNumber}
            $if showMaxPoints
              <td .table__td>
                $maybe mPoints <- examPartMaxPoints
                  #{showFixed True (fromRational examPartWeight * mPoints)}
            $if showAchievedPoints
              <td .table__td>
                $case fmap (examPartResultResult . entityVal) (results !? partId)
                  $of Nothing
                  $of Just (ExamAttended ps)
                    #{showFixed True ps}
                  $of Just ExamNoShow
                    _{MsgExamNoShow}
                  $of Just ExamVoided
                    _{MsgExamVoided}
      <tfoot>
        $maybe mPoints <- fmap (examBonusBonus . entityVal) bonus
          $if showMaxPoints
            <tr .table__row .table__row--sum>
              $if partNumbersShown
                <td>
              <td>
              <td .table__td>
                #{showFixed True sumMaxPoints}
              <td>
          <tr .table__row>
            $if partNumbersShown
              <td .table__td>
            <td .table__td>
              <a href=@{CourseR tid ssh csh SheetListR}>
                _{MsgExamBonusAchieved}
            $if showMaxPoints
              <td .table__td>
            $if showAchievedPoints
              <td .table__td :noBonus:.no-bonus>
                #{showFixed True mPoints}
          <tr .table__row .table__row--sum>
            $if partNumbersShown
              <td>
            <td>
            $if showMaxPoints
              <td>
            $if showAchievedPoints
              <td .table__td>
                $case sumPoints
                  $of ExamAttended ps
                    #{showFixed True ps}
                  $of _
        $nothing
            <tr .table__row .table__row--sum>
              $if partNumbersShown
                <td>
              <td>
              $if showMaxPoints
                <td .table__td>
                  #{showFixed True sumMaxPoints}
              $if showAchievedPoints
                <td .table__td>
                  $case sumPoints
                    $of ExamAttended ps
                      #{showFixed True ps}
                    $of _
            
          

$# TODO: Statistics
