<commit_before>package views.html.user.show

import lila.api.Context
import lila.app.mashup.UserInfo.Angle
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.String.html.richText
import lila.user.User

import controllers.routes

object header {

  private val dataToints = attr("data-toints")
  private val dataTab    = attr("data-tab")

  def apply(
      u: User,
      info: lila.app.mashup.UserInfo,
      angle: lila.app.mashup.UserInfo.Angle,
      social: lila.app.mashup.UserInfo.Social
  )(implicit ctx: Context) =
    frag(
      div(cls := "box__top user-show__header")(
        if (u.isPatron)
          h1(cls := s"user-link ${if (isOnline(u.id)) "online" else "offline"}")(
            a(href := routes.Plan.index)(patronIcon),
            userSpan(u, withPowerTip = false, withOnline = false)
          )
        else
          h1(userSpan(u, withPowerTip = false)),
        div(
          cls := List(
            "trophies" -> true,
            "packed"   -> (info.countTrophiesAndPerfCups > 7)
          )
        )(
          views.html.user.bits.perfTrophies(u, info.ranks),
          otherTrophies(info),
          u.plan.active option
            a(
              href := routes.Plan.index,
              cls := "trophy award patron icon3d",
              ariaTitle(s"Patron since ${showDate(u.plan.sinceDate)}")
            )(patronIconChar)
        ),
        u.disabled option span(cls := "closed")("CLOSED")
      ),
      div(cls := "user-show__social")(
        div(cls := "number-menu")(
          u.noBot option a(
            href := routes.UserTournament.path(u.username, "recent"),
            cls := "nm-item tournament_stats",
            dataToints := u.toints
          )(
            splitNumber(trans.nbTournamentPoints.pluralSame(u.toints))
          ),
          a(href := routes.Study.byOwnerDefault(u.username), cls := "nm-item")(
            splitNumber(trans.`nbStudies`.pluralSame(info.nbStudies))
          ),
          ctx.noKid option a(
            cls := "nm-item",
            href := routes.ForumPost.search("user:" + u.username, 1).url
          )(
            splitNumber(trans.nbForumPosts.pluralSame(info.nbForumPosts))
          ),
          ctx.noKid && (info.ublog.isDefined || ctx.is(u)) option a(
            cls := "nm-item",
            href := routes.Ublog.index(u.username)
          )(
            splitNumber(s"${info.ublog.??(_.nbPosts)} blog posts")
          ),
          (ctx.isAuth && !ctx.is(u)) option
            a(cls := "nm-item note-zone-toggle")(splitNumber(s"${social.notes.size} Notes"))
        ),
        div(cls := "user-actions btn-rack")(
          (ctx is u) option frag(
            a(
              cls := "btn-rack__btn",
              href := routes.Account.profile,
              titleOrText(trans.editProfile.txt()),
              dataIcon := ""
            ),
            a(
              cls := "btn-rack__btn",
              href := routes.Relation.blocks(),
              titleOrText(trans.listBlockedPlayers.txt()),
              dataIcon := ""
            )
          ),
          isGranted(_.UserModView) option
            a(
              cls := "btn-rack__btn mod-zone-toggle",
              href := routes.User.mod(u.username),
              titleOrText("Mod zone (Hotkey: m)"),
              dataIcon := ""
            ),
          a(
            cls := "btn-rack__btn",
            href := routes.User.tv(u.username),
            titleOrText(trans.watchGames.txt()),
            dataIcon := ""
          ),
          (ctx.isAuth && !ctx.is(u)) option
            views.html.relation.actions(
              u.id,
              relation = social.relation,
              followable = social.followable,
              blocked = social.blocked
            ),
          a(
            cls := "btn-rack__btn",
            href := routes.User.download(u.username),
            titleOrText(trans.exportGames.txt()),
            dataIcon := ""
          ),
          (ctx.isAuth && ctx.noKid && !ctx.is(u)) option a(
            titleOrText(trans.reportXToModerators.txt(u.username)),
            cls := "btn-rack__btn",
            href := s"${routes.Report.form}?username=${u.username}",
            dataIcon := ""
          )
        )
      ),
      (!ctx.is(u)) option div(cls := "note-zone")(
        postForm(action := s"${routes.User.writeNote(u.username)}?note")(
          textarea(
            name := "text",
            placeholder := "Write a private note about this user"
          ),
          if (isGranted(_.ModNote))
            div(cls := "mod-note")(
              submitButton(cls := "button")(trans.send()),
              div(
                div(form3.cmnToggle("note-mod", "mod", checked = true)),
                label(`for` := "note-mod")("For moderators only")
              ),
              isGranted(_.Admin) option div(
                div(form3.cmnToggle("note-dox", "dox", checked = false)),
                label(`for` := "note-dox")("Doxing info")
              )
            )
          else
            frag(
              input(tpe := "hidden", name := "mod", value := "false"),
              submitButton(cls := "button")(trans.send())
            )
        ),
        social.notes.isEmpty option div("No note yet"),
        social.notes
          .filter { n =>
            ctx.me.exists(n.isFrom) ||
            isGranted(_.Admin) ||
            (!n.dox && isGranted(_.ModNote))
          }
          .map { note =>
            div(cls := "note")(
              p(cls := "note__text")(richText(note.text, expandImg = false)),
              p(cls := "note__meta")(
                userIdLink(note.from.some),
                br,
                note.dox option "dox ",
                momentFromNow(note.date),
                (ctx.me.exists(note.isFrom) && !note.mod) option frag(
                  br,
                  postForm(action := routes.User.deleteNote(note._id))(
                    submitButton(
                      cls := "button-empty button-red confirm button text",
                      style := "float:right",
                      dataIcon := ""
                    )("Delete")
                  )
                )
              )
            )
          }
      ),
      isGranted(_.UserModView) option div(cls := "mod-zone mod-zone-full none"),
      standardFlash(),
      angle match {
        case Angle.Games(Some(searchForm)) => views.html.search.user(u, searchForm)
        case _ =>
          val profile   = u.profileOrDefault
          val hideTroll = u.marks.troll && !ctx.is(u)
          div(id := "us_profile")(
            if (info.ratingChart.isDefined && (!u.lame || ctx.is(u) || isGranted(_.UserModView)))
              div(cls := "rating-history")(spinner)
            else
              ctx.is(u) option newPlayer(u),
            div(cls := "profile-side")(
              div(cls := "user-infos")(
                !ctx.is(u) option frag(
                  u.lame option div(cls := "warning tos_warning")(
                    span(dataIcon := "", cls := "is4"),
                    trans.thisAccountViolatedTos()
                  )
                ),
                ctx.noKid && !hideTroll option frag(
                  profile.nonEmptyRealName map { name =>
                    strong(cls := "name")(name)
                  },
                  profile.nonEmptyBio map { bio =><commit_msg>Hide profile bio of accounts in kid mode<commit_after>package views.html.user.show

import lila.api.Context
import lila.app.mashup.UserInfo.Angle
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.String.html.richText
import lila.user.User

import controllers.routes

object header {

  private val dataToints = attr("data-toints")
  private val dataTab    = attr("data-tab")

  def apply(
      u: User,
      info: lila.app.mashup.UserInfo,
      angle: lila.app.mashup.UserInfo.Angle,
      social: lila.app.mashup.UserInfo.Social
  )(implicit ctx: Context) =
    frag(
      div(cls := "box__top user-show__header")(
        if (u.isPatron)
          h1(cls := s"user-link ${if (isOnline(u.id)) "online" else "offline"}")(
            a(href := routes.Plan.index)(patronIcon),
            userSpan(u, withPowerTip = false, withOnline = false)
          )
        else
          h1(userSpan(u, withPowerTip = false)),
        div(
          cls := List(
            "trophies" -> true,
            "packed"   -> (info.countTrophiesAndPerfCups > 7)
          )
        )(
          views.html.user.bits.perfTrophies(u, info.ranks),
          otherTrophies(info),
          u.plan.active option
            a(
              href := routes.Plan.index,
              cls := "trophy award patron icon3d",
              ariaTitle(s"Patron since ${showDate(u.plan.sinceDate)}")
            )(patronIconChar)
        ),
        u.disabled option span(cls := "closed")("CLOSED")
      ),
      div(cls := "user-show__social")(
        div(cls := "number-menu")(
          u.noBot option a(
            href := routes.UserTournament.path(u.username, "recent"),
            cls := "nm-item tournament_stats",
            dataToints := u.toints
          )(
            splitNumber(trans.nbTournamentPoints.pluralSame(u.toints))
          ),
          a(href := routes.Study.byOwnerDefault(u.username), cls := "nm-item")(
            splitNumber(trans.`nbStudies`.pluralSame(info.nbStudies))
          ),
          ctx.noKid option a(
            cls := "nm-item",
            href := routes.ForumPost.search("user:" + u.username, 1).url
          )(
            splitNumber(trans.nbForumPosts.pluralSame(info.nbForumPosts))
          ),
          ctx.noKid && (info.ublog.isDefined || ctx.is(u)) option a(
            cls := "nm-item",
            href := routes.Ublog.index(u.username)
          )(
            splitNumber(s"${info.ublog.??(_.nbPosts)} blog posts")
          ),
          (ctx.isAuth && !ctx.is(u)) option
            a(cls := "nm-item note-zone-toggle")(splitNumber(s"${social.notes.size} Notes"))
        ),
        div(cls := "user-actions btn-rack")(
          (ctx is u) option frag(
            a(
              cls := "btn-rack__btn",
              href := routes.Account.profile,
              titleOrText(trans.editProfile.txt()),
              dataIcon := ""
            ),
            a(
              cls := "btn-rack__btn",
              href := routes.Relation.blocks(),
              titleOrText(trans.listBlockedPlayers.txt()),
              dataIcon := ""
            )
          ),
          isGranted(_.UserModView) option
            a(
              cls := "btn-rack__btn mod-zone-toggle",
              href := routes.User.mod(u.username),
              titleOrText("Mod zone (Hotkey: m)"),
              dataIcon := ""
            ),
          a(
            cls := "btn-rack__btn",
            href := routes.User.tv(u.username),
            titleOrText(trans.watchGames.txt()),
            dataIcon := ""
          ),
          (ctx.isAuth && !ctx.is(u)) option
            views.html.relation.actions(
              u.id,
              relation = social.relation,
              followable = social.followable,
              blocked = social.blocked
            ),
          a(
            cls := "btn-rack__btn",
            href := routes.User.download(u.username),
            titleOrText(trans.exportGames.txt()),
            dataIcon := ""
          ),
          (ctx.isAuth && ctx.noKid && !ctx.is(u)) option a(
            titleOrText(trans.reportXToModerators.txt(u.username)),
            cls := "btn-rack__btn",
            href := s"${routes.Report.form}?username=${u.username}",
            dataIcon := ""
          )
        )
      ),
      (!ctx.is(u)) option div(cls := "note-zone")(
        postForm(action := s"${routes.User.writeNote(u.username)}?note")(
          textarea(
            name := "text",
            placeholder := "Write a private note about this user"
          ),
          if (isGranted(_.ModNote))
            div(cls := "mod-note")(
              submitButton(cls := "button")(trans.send()),
              div(
                div(form3.cmnToggle("note-mod", "mod", checked = true)),
                label(`for` := "note-mod")("For moderators only")
              ),
              isGranted(_.Admin) option div(
                div(form3.cmnToggle("note-dox", "dox", checked = false)),
                label(`for` := "note-dox")("Doxing info")
              )
            )
          else
            frag(
              input(tpe := "hidden", name := "mod", value := "false"),
              submitButton(cls := "button")(trans.send())
            )
        ),
        social.notes.isEmpty option div("No note yet"),
        social.notes
          .filter { n =>
            ctx.me.exists(n.isFrom) ||
            isGranted(_.Admin) ||
            (!n.dox && isGranted(_.ModNote))
          }
          .map { note =>
            div(cls := "note")(
              p(cls := "note__text")(richText(note.text, expandImg = false)),
              p(cls := "note__meta")(
                userIdLink(note.from.some),
                br,
                note.dox option "dox ",
                momentFromNow(note.date),
                (ctx.me.exists(note.isFrom) && !note.mod) option frag(
                  br,
                  postForm(action := routes.User.deleteNote(note._id))(
                    submitButton(
                      cls := "button-empty button-red confirm button text",
                      style := "float:right",
                      dataIcon := ""
                    )("Delete")
                  )
                )
              )
            )
          }
      ),
      isGranted(_.UserModView) option div(cls := "mod-zone mod-zone-full none"),
      standardFlash(),
      angle match {
        case Angle.Games(Some(searchForm)) => views.html.search.user(u, searchForm)
        case _ =>
          val profile   = u.profileOrDefault
          val hideTroll = u.marks.troll && !ctx.is(u)
          div(id := "us_profile")(
            if (info.ratingChart.isDefined && (!u.lame || ctx.is(u) || isGranted(_.UserModView)))
              div(cls := "rating-history")(spinner)
            else
              ctx.is(u) option newPlayer(u),
            div(cls := "profile-side")(
              div(cls := "user-infos")(
                !ctx.is(u) option frag(
                  u.lame option div(cls := "warning tos_warning")(
                    span(dataIcon := "", cls := "is4"),
                    trans.thisAccountViolatedTos()
                  )
                ),
                ctx.noKid && !hideTroll && !u.kid option frag(
                  profile.nonEmptyRealName map { name =>
                    strong(cls := "name")(name)
                  },
                  profile.nonEmptyBio map { bio =>
{'fraction_non_alphanumeric': 0.14326955354145687, 'fraction_numerical': 0.0010741859684457872, 'mean_word_length': 1.492220177346495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '905476', 'n_tokens_mistral': 4518, 'n_tokens_neox': 4380, 'n_words': 770}