$newline never

$# SPDX-FileCopyrightText: 2022-2025 Sarah Vaupel <sarah.vaupel@uniworx.de>, Gregor Kleen <gregor.kleen@ifi.lmu.de>,Sarah Vaupel <vaupel.sarah@campus.lmu.de>,Steffen Jost <jost@tcs.ifi.lmu.de>,Winnie Ros <winnie.ros@campus.lmu.de>,Steffen Jost <s.jost@fraport.de>
$#
$# SPDX-License-Identifier: AGPL-3.0-or-later

<section .profile>
  <dl .deflist.profile-dl>
      <dt .deflist__dt>
        _{MsgIdent}
      <dd .deflist__dd .email>
        #{userIdent}
      <dt .deflist__dt>
        _{MsgAuthModeSet}
      <dd .deflist__dd>
        _{userAuthentication}
      $maybe avs <- avsId
        $with avsNoPers <- tshow (view _userAvsNoPerson avs)
          <dt .deflist__dt>
            _{MsgAvsPersonNo}
            ^{messageTooltip tooltipAvsPersNo}
            $maybe matnr <- userMatrikelnummer
              $if matnr /= avsNoPers
                ^{messageTooltip tooltipAvsPersNoDiffers}
          <dd .deflist__dd .ldap-primary-key>
            ^{modalAccess (text2widget avsNoPers) (text2widget avsNoPers) False (AdminAvsUserR cID)}
            $maybe matnr <- userMatrikelnummer
              $if matnr /= avsNoPers
                / #{matnr}
        $maybe avsError <- view _userAvsLastSynchError avs
          <dt .deflist__dt>
            _{MsgLastAvsSynchError}
          <dd .deflist__dd>  
            #{avsError}
        <dt .deflist__dt>
          _{MsgLastAvsSynchronisation}
        <dd .deflist__dd>
          ^{formatTimeW SelFormatDateTime (view _userAvsLastSynch avs)}
      $nothing
        $maybe matnr <- userMatrikelnummer
          <dt .deflist__dt>
            _{MsgTableMatrikelNr}
            ^{messageTooltip tooltipAvsPersNo}
            ^{usrAutomatic CU_UA_UserMatrikelnummer}
          <dd .deflist__dd>
            ^{modalAccess (text2widget matnr) (text2widget matnr) False (AdminAvsUserR cID)}
      <dt .deflist__dt>
        _{MsgNameSet} ^{usrAutomatic CU_UA_UserDisplayName}
      <dd .deflist__dd>
        ^{nameWidget userDisplayName userSurname}
      $maybe sex <- userSex 
        <dt .deflist__dt>
          _{MsgTableSex}
        <dd .deflist__dd>
          _{sex}
      $maybe bday <- userBirthday
        <dt .deflist__dt>
          _{MsgTableBirthday} ^{usrAutomatic CU_UA_UserBirthday}
        <dd .deflist__dd>
          ^{formatTimeW SelFormatDate bday}
      <dt .deflist__dt>
        _{MsgPrefersPostalExp}
      <dd .deflist__dd>
        $if userPrefersPostal /= actualPrefersPostal
          ^{messageTooltip tooltipInvalidEmail}
        #{iconLetterOrEmail userPrefersPostal}
      $maybe addr <- actualPostAddress
        <dt .deflist__dt>
          _{MsgAdminUserPostAddress} #
          ^{updateAutomatic postalAutomatic}
          $if isNothing userPostAddress
            ^{addressLinkdIcon}
        <dd .deflist__dd>
          #{addr}
        $if (not postalAutomatic)
          $maybe postUpdate <- userPostLastUpdate
            <dt .deflist__dt>
              _{MsgUserPostLastUpdate}
            <dd .deflist__dd>
              ^{formatTimeW SelFormatDateTime postUpdate}
      <dt .deflist__dt>
        _{MsgUserDisplayEmail} #
        ^{updateAutomatic emailAutomatic}
      <dd .deflist__dd .email>
        $maybe primaryEmail <- actualDisplayEmail
          #{mailtoHtml primaryEmail}
        $nothing
          ^{messageTooltip tooltipInvalidEmail}
          $if userDisplayEmail == ""
            _{MsgUtilNoneSet}
          $else 
            #{mailtoHtml userDisplayEmail}
      $if Just userEmail /= actualDisplayEmail
        <dt .deflist__dt>
          _{MsgUserSystemEmail}
        <dd .deflist__dd>
          $if not (validEmail' userEmail)
            ^{messageTooltip tooltipInvalidEmail}
          #{mailtoHtml userEmail}
      <dt .deflist__dt>
        _{MsgAdminUserPinPassword}
        ^{usrAutomatic CU_UA_UserPinPassword}
      <dd .deflist__dd>
        $maybe pass <- userPinPassword
          #{pass}
        $nothing
          _{MsgAdminUserNoPassword}
      $maybe telephonenr <- userTelephone
        <dt .deflist__dt>
          _{MsgUserTelephone}
        <dd .deflist__dd>
          #{telephonenr}
      $maybe mobilenr <- userMobile
        <dt .deflist__dt>
          _{MsgUserMobile} ^{usrAutomatic CU_UA_UserMobile}
        <dd .deflist__dd>
          #{mobilenr}
      $maybe companyDepartment <- userCompanyDepartment
        <dt .deflist__dt>
          _{MsgCompanyDepartment}
        <dd .deflist__dd>
          #{companyDepartment}
      $maybe companyPersonalNumber <- userCompanyPersonalNumber
        <dt .deflist__dt>
          _{MsgCompanyPersonalNumber} ^{usrAutomatic CU_UA_UserCompanyPersonalNumber}
        <dd .deflist__dd>
          #{companyPersonalNumber}
      $maybe compWgt <- companies
        <dt .deflist__dt>
          _{MsgCompany}
        <dd .deflist__dd>
          ^{compWgt}
      $if showAdminInfo
        <dt .deflist__dt>
          _{MsgUserCreated}
        <dd .deflist__dd>
          ^{formatTimeW SelFormatDateTime userCreated}
        <dt .deflist__dt>
          _{MsgAdminUserAuthentication}
        <dd .deflist__dd>
          $if null externalUsers && is _Nothing userPasswordHash
            _{MsgAuthKindNoLogin}
          $else
            <ul>
              $if is _Just userPasswordHash
                <li>_{MsgAuthKindPWHash}
              $forall (authIdent, sourceIdent, lsync) <- externalUsers
                <li>
                  $case sourceIdent
                    $of AuthSourceIdAzure _clientId
                      _{MsgAuthKindAzure}: #
                    $of AuthSourceIdLdap _sourceId
                      _{MsgAuthKindLDAP}: #
                  #{authIdent} #
                  <span .comment>
                    (_{MsgAdminUserAuthLastSync}: ^{formatTimeW SelFormatDateTime lsync})
        <dt .deflist__dt>
          _{MsgLastLogin}
        <dd .deflist__dd>
          $maybe llogin <- userLastAuthentication
            ^{formatTimeW SelFormatDateTime llogin}
          $nothing
            _{MsgNeverSet}
        <dt .deflist__dt>
          _{MsgTokensLastReset}
        <dd .deflist__dd>
          $maybe lastInvalidated <- userTokensIssuedAfter
            ^{formatTimeW SelFormatDateTime lastInvalidated}
          $nothing
            _{MsgNeverSet}
    $forall (function, schools) <- Map.toList functions
      <dt .deflist__dt>_{function}
      <dd .deflist__dd>
        <ul .list--inline .list--iconless .list--comma-separated>
          $forall ssh <- schools
            <li>
              #{ssh}
    $if not $ null lecture_corrector
      <dt .deflist__dt>_{MsgProfileCorrector}
      <dd .deflist__dd>
        <ul .list-ul>
          $forall (E.Value tid, E.Value ssh, E.Value csh) <- lecture_corrector
            <li .list-ul__item>
              <a href=@{CourseR tid ssh csh CShowR}>#{tid}-#{ssh}-#{csh}
    $if not $ null studies
      <dt .deflist__dt>_{MsgAdminFeaturesHeading}
      <dd .deflist__dd>
        <div .scrolltable>
          <table .table.table--striped.table--hover.table--condensed>
            <tr .table__row>
              <th .table__th>_{MsgTableStudyTerm}
              <th .table__th>_{MsgTableStudyFeatureDegree}
              <th .table__th>_{MsgTableStudyFeatureType}
              <th .table__th>_{MsgTableStudyFeatureAge}
              <th .table__th>_{MsgTableStudyFeatureValid}
              <th .table__th>_{MsgTableStudyFeatureUpdate}

            $forall ((Entity _ StudyFeatures{studyFeaturesType, studyFeaturesSemester, studyFeaturesValid, studyFeaturesFirstObserved, studyFeaturesLastObserved}), (Entity _ degree), (Entity _ field)) <- studies
              <tr.table__row>
                <td .table__td>_{field}
                <td .table__td>_{degree}
                <td .table__td>_{studyFeaturesType}
                <td .table__td>#{studyFeaturesSemester}
                <td .table__td>#{hasTickmark studyFeaturesValid}
                <td .table__td>
                  $maybe fObs <- studyFeaturesFirstObserved
                    ^{formatTimeRangeW SelFormatDateTime fObs $ Just studyFeaturesLastObserved}
                  $nothing
                    ^{formatTimeW SelFormatDateTime studyFeaturesLastObserved}
<section>

  ^{supervisorsWgt}
  
  ^{superviseesWgt}

  <div .container>
    <h2>_{MsgProfileQualifications}
    <div .container>
      ^{qualificationsTable}  
  
  ^{maybeTable MsgProfileEnrolledExams examsTable}

  ^{maybeTable MsgProfileCourses ownedCoursesTable}
  
  ^{maybeTable MsgProfileCourseParticipations enrolledCoursesTable}

  ^{maybeTable MsgProfileSubmissionGroups submissionGroupTable}

  ^{maybeTable' MsgProfileSubmissions Nothing (Just (msg2widget MsgProfileGroupSubmissionDates)) submissionTable}
  
  ^{maybeTable' MsgTableCorrector Nothing (Just (msg2widget MsgProfileCorrectorRemark <> simpleLinkI MsgProfileCorrections CorrectionsR)) correctionsTable}
  
^{profileRemarks}
