 'use strict'
 path = require 'path'
 SubAtom = require 'sub-atom'
+
+# debug = do ->
+#   log = ''
+#   length = 0
+#   timeout = null
+#
+#   (message) ->
+#     clearTimeout timeout
+#     timeout = setTimeout ->
+#       fs.writeFileSync "#{__dirname}/../log", log
+#     , 500
 
 class AutohideTreeView
   treeView = null


  getHiddenWidth: -> atom.config.get 'autohide-tree-view.hiddenWidth'

  enableHoverEvents: ->
    treeViewEl.classList.add 'autohide-hover-events'

  disableHoverEvents: ->
    treeViewEl.classList.remove 'autohide-hover-events'

module.exports = new AutohideTreeView()

  enable: (treeViewPkg) ->
    try
      treeViewPkg ?= atom.packages.getActivePackage 'tree-view'
      return unless treeViewPkg?
      @enabled = true
      treeView = treeViewPkg.mainModule.createView()
      treeViewEl = atom.views.getView treeView
      treeViewEl.classList.add 'autohide', 'autohide-hover-events'
      @applyHiddenWidth()
      @applyAnimate()
      @hide true
    catch e
      console.error e

