$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 gradingShown
      $if examGradingRule /= ExamGradingManual
        <dt .deflist__dt>
          _{MsgExamGradingRule}
          $if not gradingVisible
            \ ^{isVisible False}
        <dd .deflist__dd>
          $case examGradingRule
            $of ExamGradingManual
              _{MsgExamGradingManual'}
            $of ExamGradingKey{..}
              ^{gradingKeyW examGradingKey}
      $if examBonusRule /= ExamNoBonus
        <dt .deflist__dt>
          _{MsgExamBonusRule}
          $if not gradingVisible
            \ ^{isVisible False}
        <dd .deflist__dd>
          ^{examBonusW examBonusRule}
    $if occurrenceAssignmentsShown
      <dt .deflist__dt>
        _{MsgExamOccurrenceRuleParticipant}
        $if not occurrenceAssignmentsVisible
          \ ^{isVisible False}
      <dd .deflist__dd>
        _{classifyExamOccurrenceRule examOccurrenceRule}
    $maybe registerWdgt <- registerWidget
      <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}
          $if occurrenceAssignmentsShown
            <th .table__th>
              _{MsgExamRoomRegistered}
              $if not occurrenceAssignmentsVisible
                \ ^{isVisible False}
          <th .table__th>_{MsgExamRoom}
          $if not examTimes
            <th .table__th>_{MsgExamRoomTime}
          <th .table__th>_{MsgExamRoomDescription}
      <tbody>
        $forall (Entity _occId ExamOccurrence{examOccurrenceName, examOccurrenceRoom, examOccurrenceStart, examOccurrenceEnd, examOccurrenceDescription}, registered) <- occurrences
          <tr .table__row :occurrenceAssignmentsShown && not registered:.occurrence--not-registered>
            $if occurrenceNamesShown
              <td .table__td #exam-occurrence__#{examOccurrenceName}>#{examOccurrenceName}
            $if occurrenceAssignmentsShown
              <td .table__td>
                $if registered
                  #{iconOK}
            <td .table__td>#{examOccurrenceRoom}
            $if not examTimes
              <td .table__td>
                ^{formatTimeRangeW SelFormatDateTime examOccurrenceStart examOccurrenceEnd}
            <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>
          <th .table__th>_{MsgExamPartName}
          <th .table__th>_{MsgExamPartMaxPoints}
          <th .table__th>_{MsgExamPartResultPoints}
      <tbody>
        $forall Entity partId ExamPart{examPartName, examPartWeight, examPartMaxPoints} <- examParts
          <tr .table__row>
            <td .table__td>#{examPartName}
            <td .table__td>
              $maybe mPoints <- examPartMaxPoints
                #{showFixed True (fromRational examPartWeight * mPoints)}
            <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}

$# TODO: Statistics
