<commit_before>###
#    Copyright (c) ppy Pty Ltd <<EMAIL>>.
#
#    This file is part of osu!web. osu!web is distributed with the hope of
#    attracting more community contributions to the core ecosystem of osu!.
#
#    osu!web is free software: you can redistribute it and/or modify
#    it under the terms of the Affero GNU General Public License version 3
#    as published by the Free Software Foundation.
#
#    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
#    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#    See the GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
###

{a, button, div, i, p, span} = ReactDOMFactories
el = React.createElement

bn = 'beatmap-discussions'
lp = 'beatmaps.discussions'

sortPresets =
  updated_at:
    text: osu.trans('beatmaps.discussions.sort.updated_at')
    sort: (a, b) ->
      if a.updated_at == b.updated_at
        b.id - a.id
      else
        Date.parse(b.updated_at) - Date.parse(a.updated_at)

  created_at:
    text: osu.trans('beatmaps.discussions.sort.created_at')
    sort: (a, b) ->
      if a.created_at == b.created_at
        a.id - b.id
      else
        Date.parse(a.created_at) - Date.parse(b.created_at)

  # there's obviously no timeline field
  timeline:
    text: osu.trans('beatmaps.discussions.sort.timeline')
    sort: (a, b) ->
      if a.timestamp == b.timestamp
        a.id - b.id
      else
        a.timestamp - b.timestamp


class BeatmapDiscussions.Discussions extends React.PureComponent
  constructor: (props) ->
    super props

    @state =
      sort:
        generalAll: 'updated_at'
        general: 'updated_at'
        timeline: 'timeline'


  render: =>
    discussions = @props.currentDiscussions[@props.mode]

    div className: 'osu-page osu-page--small osu-page--full',
      div
        className: bn

        div className: 'page-title',
          osu.trans('beatmaps.discussions.title')

        div className: "#{bn}__toolbar",
          div className: "#{bn}__toolbar-content #{bn}__toolbar-content--left",
            div
              className: "#{bn}__toolbar-item"
              @renderSortOptions()
          div className: "#{bn}__toolbar-content #{bn}__toolbar-content--right",
            a
              href: '#'
              className: "#{bn}__toolbar-item #{bn}__toolbar-item--link"
              'data-type': 'collapse'
              onClick: @expand
              el IconExpand,
                expand: false
                parentClass: "#{bn}__toolbar-link-content"
              span className: "#{bn}__toolbar-link-content",
                osu.trans('beatmaps.discussions.collapse.all-collapse')

            a
              href: '#'
              className: "#{bn}__toolbar-item #{bn}__toolbar-item--link"
              'data-type': 'expand'
              onClick: @expand
              el IconExpand,
                parentClass: "#{bn}__toolbar-link-content"
              span className: "#{bn}__toolbar-link-content",
                osu.trans('beatmaps.discussions.collapse.all-expand')


        if discussions.length == 0
          div className: "#{bn}__discussions #{bn}__discussions--empty",
            osu.trans 'beatmaps.discussions.empty.empty'

        else if _.size(@props.currentDiscussions.byFilter[@props.currentFilter][@props.mode]) == 0
          div className: "#{bn}__discussions #{bn}__discussions--empty",
            osu.trans 'beatmaps.discussions.empty.hidden'

        else
          div
            className: "#{bn}__discussions"
            @timelineCircle()

            if @isTimelineVisible()
              div className: "#{bn}__timeline-line hidden-xs"

            div null,
              @sortedDiscussions().map @discussionPage

            @timelineCircle()


  renderSortOptions: =>
    presets =
      switch @props.mode
        when 'timeline'
          ['timeline', 'updated_at']
        else
          ['created_at', 'updated_at']

    div
      className: 'sort sort--beatmapset-discussions'
      div
        className: 'sort__items'
        span className: 'sort__item sort__item--title', osu.trans('sort._')
        for preset in presets
          button
            type: 'button'
            className: "sort__item sort__item--button #{if @currentSort() == preset then 'sort__item--active' else ''}"
            'data-sort-preset': preset
            onClick: @changeSort
            sortPresets[preset].text


  discussionPage: (discussion) =>
    return if !discussion.id?

    className = "#{bn}__discussion"
    visible = @props.currentDiscussions.byFilter[@props.currentFilter][@props.mode][discussion.id]?
    className += ' u-hide-by-height' unless visible

    div
      key: discussion.id
      className: className
      el BeatmapDiscussions.Discussion,
        discussion: discussion
        users: @props.users
        currentUser: @props.currentUser
        beatmapset: @props.beatmapset
        currentBeatmap: @props.currentBeatmap<commit_msg>sort buttons should have react key<commit_after>###
#    Copyright (c) ppy Pty Ltd <<EMAIL>>.
#
#    This file is part of osu!web. osu!web is distributed with the hope of
#    attracting more community contributions to the core ecosystem of osu!.
#
#    osu!web is free software: you can redistribute it and/or modify
#    it under the terms of the Affero GNU General Public License version 3
#    as published by the Free Software Foundation.
#
#    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
#    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#    See the GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
###

{a, button, div, i, p, span} = ReactDOMFactories
el = React.createElement

bn = 'beatmap-discussions'
lp = 'beatmaps.discussions'

sortPresets =
  updated_at:
    text: osu.trans('beatmaps.discussions.sort.updated_at')
    sort: (a, b) ->
      if a.updated_at == b.updated_at
        b.id - a.id
      else
        Date.parse(b.updated_at) - Date.parse(a.updated_at)

  created_at:
    text: osu.trans('beatmaps.discussions.sort.created_at')
    sort: (a, b) ->
      if a.created_at == b.created_at
        a.id - b.id
      else
        Date.parse(a.created_at) - Date.parse(b.created_at)

  # there's obviously no timeline field
  timeline:
    text: osu.trans('beatmaps.discussions.sort.timeline')
    sort: (a, b) ->
      if a.timestamp == b.timestamp
        a.id - b.id
      else
        a.timestamp - b.timestamp


class BeatmapDiscussions.Discussions extends React.PureComponent
  constructor: (props) ->
    super props

    @state =
      sort:
        generalAll: 'updated_at'
        general: 'updated_at'
        timeline: 'timeline'


  render: =>
    discussions = @props.currentDiscussions[@props.mode]

    div className: 'osu-page osu-page--small osu-page--full',
      div
        className: bn

        div className: 'page-title',
          osu.trans('beatmaps.discussions.title')

        div className: "#{bn}__toolbar",
          div className: "#{bn}__toolbar-content #{bn}__toolbar-content--left",
            div
              className: "#{bn}__toolbar-item"
              @renderSortOptions()
          div className: "#{bn}__toolbar-content #{bn}__toolbar-content--right",
            a
              href: '#'
              className: "#{bn}__toolbar-item #{bn}__toolbar-item--link"
              'data-type': 'collapse'
              onClick: @expand
              el IconExpand,
                expand: false
                parentClass: "#{bn}__toolbar-link-content"
              span className: "#{bn}__toolbar-link-content",
                osu.trans('beatmaps.discussions.collapse.all-collapse')

            a
              href: '#'
              className: "#{bn}__toolbar-item #{bn}__toolbar-item--link"
              'data-type': 'expand'
              onClick: @expand
              el IconExpand,
                parentClass: "#{bn}__toolbar-link-content"
              span className: "#{bn}__toolbar-link-content",
                osu.trans('beatmaps.discussions.collapse.all-expand')


        if discussions.length == 0
          div className: "#{bn}__discussions #{bn}__discussions--empty",
            osu.trans 'beatmaps.discussions.empty.empty'

        else if _.size(@props.currentDiscussions.byFilter[@props.currentFilter][@props.mode]) == 0
          div className: "#{bn}__discussions #{bn}__discussions--empty",
            osu.trans 'beatmaps.discussions.empty.hidden'

        else
          div
            className: "#{bn}__discussions"
            @timelineCircle()

            if @isTimelineVisible()
              div className: "#{bn}__timeline-line hidden-xs"

            div null,
              @sortedDiscussions().map @discussionPage

            @timelineCircle()


  renderSortOptions: =>
    presets =
      switch @props.mode
        when 'timeline'
          ['timeline', 'updated_at']
        else
          ['created_at', 'updated_at']

    div
      className: 'sort sort--beatmapset-discussions'
      div
        className: 'sort__items'
        span className: 'sort__item sort__item--title', osu.trans('sort._')
        for preset in presets
          button
            key: preset
            type: 'button'
            className: "sort__item sort__item--button #{if @currentSort() == preset then 'sort__item--active' else ''}"
            'data-sort-preset': preset
            onClick: @changeSort
            sortPresets[preset].text


  discussionPage: (discussion) =>
    return if !discussion.id?

    className = "#{bn}__discussion"
    visible = @props.currentDiscussions.byFilter[@props.currentFilter][@props.mode][discussion.id]?
    className += ' u-hide-by-height' unless visible

    div
      key: discussion.id
      className: className
      el BeatmapDiscussions.Discussion,
        discussion: discussion
        users: @props.users
        currentUser: @props.currentUser
        beatmapset: @props.beatmapset
        currentBeatmap: @props.currentBeatmap
{'fraction_non_alphanumeric': 0.11354600989042955, 'fraction_numerical': 0.0005817899738194512, 'mean_word_length': 2.2433962264150944, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3835783', 'n_tokens_mistral': 3082, 'n_tokens_neox': 2965, 'n_words': 728}