<commit_before>kd                   = require 'kd'
KDView               = kd.View
KDModalView          = kd.ModalView
KDTabPaneView        = kd.TabPaneView
KDCustomHTMLView     = kd.CustomHTMLView
KDTabHandleContainer = kd.TabHandleContainer

Machine                      = require 'app/providers/machine'
isKoding                     = require 'app/util/isKoding'
MachineSettingsSpecsView     = require './machinesettingsspecsview'
MachineSettingsGuidesView    = require './machinesettingsguidesview'
MachineSettingsGeneralView   = require './machinesettingsgeneralview'
MachineSettingsDomainsView   = require './machinesettingsdomainsview'
MachineSettingsModalTabView  = require './machinesettingsmodaltabview'
MachineSettingsAdvancedView  = require './machinesettingsadvancedview'
MachineSettingsDiskUsageView = require './machinesettingsdiskusageview'
MachineSettingsVMSharingView = require './machinesettingsvmsharingview'
MachineSettingsSnapshotsView = require './machinesettingssnapshotsview'


PANE_CONFIG = [
  { title: 'General',       viewClass: MachineSettingsGeneralView   }
  { title: 'Specs',         viewClass: MachineSettingsSpecsView     }
  { title: 'Disk Usage',    viewClass: MachineSettingsDiskUsageView }
  { title: 'Domains',       viewClass: MachineSettingsDomainsView   }
  { title: 'VM Sharing',    viewClass: MachineSettingsVMSharingView }
  { title: 'Snapshots',     viewClass: MachineSettingsSnapshotsView }
  { title: 'Advanced',      viewClass: MachineSettingsAdvancedView  }
  { title: 'Common guides', viewClass: MachineSettingsGuidesView    }
]


module.exports = class MachineSettingsModal extends KDModalView

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

    options.cssClass  = 'machine-settings-modal AppModal'
    options.title     = 'VM Settings'
    options.width     = 805
    options.height    = 445
    options.overlay  ?= yes

    super options, data

    @panesByTitle = {}

    @createTabView()
    @createPanes()
    @tweakStyling_()

    @tabView.showPaneByIndex 0

    { onboarding } = kd.singletons
    onboarding.run 'VMSettingsOpened', yes
    @on 'KDModalViewDestroyed', -> onboarding.stop 'VMSettingsOpened'


  createTabView: ->

    tabHandleContainer = new KDTabHandleContainer cssClass: 'AppModal-nav'

    @addSubView tabHandleContainer

    @addSubView @tabView   = new MachineSettingsModalTabView
      hideHandleCloseIcons : yes
      maxHandleWidth       : 190
      tabHandleContainer   : tabHandleContainer

    tabHandleContainer.unsetClass 'kdtabhandlecontainer'


  createPanes: ->

    machine                     = @getData()
    isMachineRunning            = machine.status.state is Machine.State.Running
    disabledTabsForNotRunningVM = [ 'Disk Usage', 'Domains', 'VM Sharing', 'Snapshots' ]
    disabledTabsForManagedVM    = [ 'Specs', 'Domains', 'Snapshots' ]
    disabledTabsForTeams        = [ 'Domains', 'Advanced', 'Snapshots' ]

    for item in PANE_CONFIG when item.title and item.viewClass

      subView    = new item.viewClass item.viewOptions, machine
      isDisabled = not isMachineRunning and disabledTabsForNotRunningVM.indexOf(item.title) > -1

      if machine.isManaged()
        isDisabled = disabledTabsForManagedVM.indexOf(item.title) > -1

      unless isKoding()
        isDisabled = disabledTabsForTeams.indexOf(item.title) > -1

      @tabView.addPane pane = new KDTabPaneView
        name     : item.title
        cssClass : 'AppModal-content'
        view     : subView
        disabled : isDisabled

      pane.tabHandle.setClass 'disabled'  if isDisabled
      subView.once 'ModalDestroyRequested', @bound 'destroy'

      @panesByTitle[item.title] = pane


  # MachineSettingsModal has same UI with AccountSettingsModal.
  # However to reuse ASM styling I needed to add/remove some classes.<commit_msg>Teams: Disable advanced settings if machine isnt managed.<commit_after>kd                   = require 'kd'
KDView               = kd.View
KDModalView          = kd.ModalView
KDTabPaneView        = kd.TabPaneView
KDCustomHTMLView     = kd.CustomHTMLView
KDTabHandleContainer = kd.TabHandleContainer

Machine                      = require 'app/providers/machine'
isKoding                     = require 'app/util/isKoding'
MachineSettingsSpecsView     = require './machinesettingsspecsview'
MachineSettingsGuidesView    = require './machinesettingsguidesview'
MachineSettingsGeneralView   = require './machinesettingsgeneralview'
MachineSettingsDomainsView   = require './machinesettingsdomainsview'
MachineSettingsModalTabView  = require './machinesettingsmodaltabview'
MachineSettingsAdvancedView  = require './machinesettingsadvancedview'
MachineSettingsDiskUsageView = require './machinesettingsdiskusageview'
MachineSettingsVMSharingView = require './machinesettingsvmsharingview'
MachineSettingsSnapshotsView = require './machinesettingssnapshotsview'


PANE_CONFIG = [
  { title: 'General',       viewClass: MachineSettingsGeneralView   }
  { title: 'Specs',         viewClass: MachineSettingsSpecsView     }
  { title: 'Disk Usage',    viewClass: MachineSettingsDiskUsageView }
  { title: 'Domains',       viewClass: MachineSettingsDomainsView   }
  { title: 'VM Sharing',    viewClass: MachineSettingsVMSharingView }
  { title: 'Snapshots',     viewClass: MachineSettingsSnapshotsView }
  { title: 'Advanced',      viewClass: MachineSettingsAdvancedView  }
  { title: 'Common guides', viewClass: MachineSettingsGuidesView    }
]


module.exports = class MachineSettingsModal extends KDModalView

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

    options.cssClass  = 'machine-settings-modal AppModal'
    options.title     = 'VM Settings'
    options.width     = 805
    options.height    = 445
    options.overlay  ?= yes

    super options, data

    @panesByTitle = {}

    @createTabView()
    @createPanes()
    @tweakStyling_()

    @tabView.showPaneByIndex 0

    { onboarding } = kd.singletons
    onboarding.run 'VMSettingsOpened', yes
    @on 'KDModalViewDestroyed', -> onboarding.stop 'VMSettingsOpened'


  createTabView: ->

    tabHandleContainer = new KDTabHandleContainer cssClass: 'AppModal-nav'

    @addSubView tabHandleContainer

    @addSubView @tabView   = new MachineSettingsModalTabView
      hideHandleCloseIcons : yes
      maxHandleWidth       : 190
      tabHandleContainer   : tabHandleContainer

    tabHandleContainer.unsetClass 'kdtabhandlecontainer'


  createPanes: ->

    machine                     = @getData()
    isMachineRunning            = machine.status.state is Machine.State.Running
    disabledTabsForNotRunningVM = [ 'Disk Usage', 'Domains', 'VM Sharing', 'Snapshots' ]
    disabledTabsForManagedVM    = [ 'Specs', 'Domains', 'Snapshots' ]
    disabledTabsForTeams        = [ 'Domains', 'Advanced', 'Snapshots' ]

    for item in PANE_CONFIG when item.title and item.viewClass

      subView    = new item.viewClass item.viewOptions, machine
      isDisabled = not isMachineRunning and disabledTabsForNotRunningVM.indexOf(item.title) > -1
      isManaged  = machine.isManaged()

      if isManaged
        isDisabled = disabledTabsForManagedVM.indexOf(item.title) > -1

      unless isKoding()
        isDisabled = disabledTabsForTeams.indexOf(item.title) > -1 and not isManaged

      @tabView.addPane pane = new KDTabPaneView
        name     : item.title
        cssClass : 'AppModal-content'
        view     : subView
        disabled : isDisabled

      pane.tabHandle.setClass 'disabled'  if isDisabled
      subView.once 'ModalDestroyRequested', @bound 'destroy'

      @panesByTitle[item.title] = pane


  # MachineSettingsModal has same UI with AccountSettingsModal.
  # However to reuse ASM styling I needed to add/remove some classes.
{'fraction_non_alphanumeric': 0.08379888268156424, 'fraction_numerical': 0.003377939456931272, 'mean_word_length': 3.3150224215246635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '4435967', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2130, 'n_words': 471}