<commit_before>kd                        = require 'kd'
globals                   = require 'globals'
nick                      = require 'app/util/nick'
CustomLinkView            = require 'app/customlinkview'
HelpSupportModal          = require 'app/commonviews/helpsupportmodal'
IDEStatusBarAvatarView    = require './idestatusbaravatarview'
isSoloProductLite         = require 'app/util/issoloproductlite'
isPlanFree                = require 'app/util/isPlanFree'
isKoding                  = require 'app/util/isKoding'
ButtonViewWithProgressBar = require 'app/commonviews/buttonviewwithprogressbar'

PROGRESS_DELAYS             = [
    { delay : 500,  progress : 15 }
    { delay : 1500, progress : 30 }
    { delay : 2500, progress : 75 }
    { delay : 3250, progress : 90 }
  ]

module.exports = class IDEStatusBar extends kd.View

  constructor: (options = {}, data) ->

    options.cssClass = 'IDE-StatusBar'

    super options, data

    @participantAvatars = {}
    @avatarTimers       = {}

    @on 'ShowAvatars',          @bound 'showAvatars'
    @on 'ParticipantLeft',      @bound 'dimParticipantAvatar'
    @on 'ParticipantJoined',    @bound 'addParticipantAvatar'
    @on 'CollaborationLoading', @bound 'handleCollaborationLoading'
    @on 'CollaborationEnded',   @bound 'handleCollaborationEnded'
    @on 'CollaborationStarted', @bound 'handleCollaborationStarted'
    @on 'ParticipantWatched',   @bound 'decorateWatchedAvatars'
    @on 'ParticipantUnwatched', @bound 'decorateUnwatchedAvatars'

    { mainController, router, appManager } = kd.singletons

    @addSubView @status = new kd.CustomHTMLView cssClass : 'status'

    @addSubView @collaborationLinkContainer = new kd.CustomHTMLView
      cssClass: 'collaboration-link-container'

    superKey = if globals.os is 'mac' then '⌘' else 'CTRL'

    @collaborationLinkContainer.addSubView @collaborationLink = new kd.CustomHTMLView
      cssClass   : 'collaboration-link'
      partial    : ''
      bind       : 'mouseenter mouseleave'
      mouseleave : -> @tooltip.hide()
      mouseenter : ->
        @tooltip.setTitle 'Click to share!'
        @tooltip.show()
        @tooltip.once 'ReceivedClickElsewhere', @tooltip.bound 'hide'

      click      : ->
        link = @getElement()
        @utils.selectText link

        try
          copied = document.execCommand 'copy'
          throw "couldn't copy"  unless copied
          tooltipPartial = 'Copied to clipboard!'
        catch
          tooltipPartial = "Hit #{superKey} + C to copy!"

        @tooltip.setTitle tooltipPartial
        @tooltip.show()
        @tooltip.once 'ReceivedClickElsewhere', @tooltip.bound 'hide'

    @collaborationLink.setTooltip
      title     : 'Click to share!'
      placement : 'above'
      sticky    : yes

    @addSubView new kd.CustomHTMLView
      tagName  : 'i'
      cssClass : 'icon help'
      click    : -> new HelpSupportModal

    @addSubView new kd.CustomHTMLView
      tagName  : 'i'
      cssClass : 'icon shortcuts'
      click    : (event) =>
        kd.utils.stopDOMEvent event
        router.handleRoute '/Account/Shortcuts'

    @addSubView @share = new ButtonViewWithProgressBar
      cssClass        : 'share fr hidden'
      buttonOptions   :
        title         : 'Loading'
        cssClass      : 'start-session transparent'
        callback      : @bound 'handleShareButtonClick'


    if isKoding() and isSoloProductLite()
      isPlanFree (err, isFree) =>
        return  if err
        return  unless isFree

        @share.destroy()
        @share = null

    @addSubView @video = new CustomLinkView
      href       : '#'
      cssClass   : 'appear-in-button share fr hidden'
      attributes :
        target   : '_blank'
        title    : 'Start a video chat using appear.in'

    @addSubView @avatars = new kd.CustomHTMLView cssClass : 'avatars fr hidden'

    mainController.isFeatureDisabled 'collaboration', (collabDisabled) =>
      @_collabDisable = collabDisabled
      @avatars.show()  unless collabDisabled


  handleShareButtonClick: (event) ->

    { appManager } = kd.singletons

    kd.utils.stopDOMEvent event

    return  if @share.hasClass 'loading'
    return  unless appManager.frontApp.isMachineRunning()

    if @share.hasClass 'active'
    then @handleSessionEnd()
    else @startSession()


  startSession: ->

    console.log 'startSession'

    { appManager } = kd.singletons

    appManager.tell 'IDE', 'setInitialSessionSetting', 'readOnly', yes
    appManager.tell 'IDE', 'setInitialSessionSetting', 'muteHost', no

    @share.updateProgress 0 # Make sure initial value is 0

    PROGRESS_DELAYS.forEach (item) =>
      kd.utils.killWait item.timer  if item.timer # Kill already defined waits
      item.timer = kd.utils.wait item.delay, => @share.updateProgress item.progress

    appManager.tell 'IDE', 'startCollaborationSession', (err) => @resetProgress()  if err


  resetProgress: -> @share.resetProgress()


  showInformation: ->

    @status.updatePartial 'Click the plus button above to create a new panel'


  createParticipantAvatar: (nickname, isOnline) -><commit_msg>Collaboration: Remove deprecated settings.<commit_after>kd                        = require 'kd'
globals                   = require 'globals'
nick                      = require 'app/util/nick'
CustomLinkView            = require 'app/customlinkview'
HelpSupportModal          = require 'app/commonviews/helpsupportmodal'
IDEStatusBarAvatarView    = require './idestatusbaravatarview'
isSoloProductLite         = require 'app/util/issoloproductlite'
isPlanFree                = require 'app/util/isPlanFree'
isKoding                  = require 'app/util/isKoding'
ButtonViewWithProgressBar = require 'app/commonviews/buttonviewwithprogressbar'

PROGRESS_DELAYS             = [
    { delay : 500,  progress : 15 }
    { delay : 1500, progress : 30 }
    { delay : 2500, progress : 75 }
    { delay : 3250, progress : 90 }
  ]

module.exports = class IDEStatusBar extends kd.View

  constructor: (options = {}, data) ->

    options.cssClass = 'IDE-StatusBar'

    super options, data

    @participantAvatars = {}
    @avatarTimers       = {}

    @on 'ShowAvatars',          @bound 'showAvatars'
    @on 'ParticipantLeft',      @bound 'dimParticipantAvatar'
    @on 'ParticipantJoined',    @bound 'addParticipantAvatar'
    @on 'CollaborationLoading', @bound 'handleCollaborationLoading'
    @on 'CollaborationEnded',   @bound 'handleCollaborationEnded'
    @on 'CollaborationStarted', @bound 'handleCollaborationStarted'
    @on 'ParticipantWatched',   @bound 'decorateWatchedAvatars'
    @on 'ParticipantUnwatched', @bound 'decorateUnwatchedAvatars'

    { mainController, router, appManager } = kd.singletons

    @addSubView @status = new kd.CustomHTMLView cssClass : 'status'

    @addSubView @collaborationLinkContainer = new kd.CustomHTMLView
      cssClass: 'collaboration-link-container'

    superKey = if globals.os is 'mac' then '⌘' else 'CTRL'

    @collaborationLinkContainer.addSubView @collaborationLink = new kd.CustomHTMLView
      cssClass   : 'collaboration-link'
      partial    : ''
      bind       : 'mouseenter mouseleave'
      mouseleave : -> @tooltip.hide()
      mouseenter : ->
        @tooltip.setTitle 'Click to share!'
        @tooltip.show()
        @tooltip.once 'ReceivedClickElsewhere', @tooltip.bound 'hide'

      click      : ->
        link = @getElement()
        @utils.selectText link

        try
          copied = document.execCommand 'copy'
          throw "couldn't copy"  unless copied
          tooltipPartial = 'Copied to clipboard!'
        catch
          tooltipPartial = "Hit #{superKey} + C to copy!"

        @tooltip.setTitle tooltipPartial
        @tooltip.show()
        @tooltip.once 'ReceivedClickElsewhere', @tooltip.bound 'hide'

    @collaborationLink.setTooltip
      title     : 'Click to share!'
      placement : 'above'
      sticky    : yes

    @addSubView new kd.CustomHTMLView
      tagName  : 'i'
      cssClass : 'icon help'
      click    : -> new HelpSupportModal

    @addSubView new kd.CustomHTMLView
      tagName  : 'i'
      cssClass : 'icon shortcuts'
      click    : (event) =>
        kd.utils.stopDOMEvent event
        router.handleRoute '/Account/Shortcuts'

    @addSubView @share = new ButtonViewWithProgressBar
      cssClass        : 'share fr hidden'
      buttonOptions   :
        title         : 'Loading'
        cssClass      : 'start-session transparent'
        callback      : @bound 'handleShareButtonClick'


    if isKoding() and isSoloProductLite()
      isPlanFree (err, isFree) =>
        return  if err
        return  unless isFree

        @share.destroy()
        @share = null

    @addSubView @video = new CustomLinkView
      href       : '#'
      cssClass   : 'appear-in-button share fr hidden'
      attributes :
        target   : '_blank'
        title    : 'Start a video chat using appear.in'

    @addSubView @avatars = new kd.CustomHTMLView cssClass : 'avatars fr hidden'

    mainController.isFeatureDisabled 'collaboration', (collabDisabled) =>
      @_collabDisable = collabDisabled
      @avatars.show()  unless collabDisabled


  handleShareButtonClick: (event) ->

    { appManager } = kd.singletons

    kd.utils.stopDOMEvent event

    return  if @share.hasClass 'loading'
    return  unless appManager.frontApp.isMachineRunning()

    if @share.hasClass 'active'
    then @handleSessionEnd()
    else @startSession()


  startSession: ->

    @share.updateProgress 0 # Make sure initial value is 0

    PROGRESS_DELAYS.forEach (item) =>
      kd.utils.killWait item.timer  if item.timer # Kill already defined waits
      item.timer = kd.utils.wait item.delay, => @share.updateProgress item.progress

    kd.singletons.appManager.tell 'IDE', 'startCollaborationSession', (err) =>
      @resetProgress()  if err


  resetProgress: -> @share.resetProgress()


  showInformation: ->

    @status.updatePartial 'Click the plus button above to create a new panel'


  createParticipantAvatar: (nickname, isOnline) ->
{'fraction_non_alphanumeric': 0.09754399920453416, 'fraction_numerical': 0.004971661529283087, 'mean_word_length': 2.6271186440677967, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3101530', 'n_tokens_mistral': 3113, 'n_tokens_neox': 2916, 'n_words': 705}