+{CompositeDisposable, Emitter} = require 'atom'
+
 # Tooltip
 #
 # Tooltips that support arbitrary HTML content.


  hide: ->
    @view.classList.add 'dontshow'
    setTimeout (=> @hide_()), 100

  show: ->
    @view.style.display = 'block'
    setTimeout ( => @view.classList.remove 'dontshow'), 20

  destroy: ->
    document.body.removeChild @view

  tooltipView: (content) ->
    tt = document.createElement 'div'
    tt.classList.add 'ink-tooltip', 'dontshow'
    tt.style.display = 'none'
    if content then tt.appendChild content
    tt


module.exports =
class Tooltip
  constructor: (@parent, content, {@cond, @delay, @clas}={}) ->
    @cond  = (-> true) unless @cond?
    @delay = 150       unless @delay?
    @emitter = new Emitter()
    @view = @tooltipView content
    document.body.appendChild @view

    # remember old mouse listeners
    @oldOnMouseOver = @parent.onmouseover
    @oldOnMouseOut = @parent.onmouseout

    @showOnHover()
    this

  onDidShow: (f) ->
    @emitter.on('didShow', f)

  onDidHide: (f) ->
    @emitter.on('didHide', f)

  hide_: ->
    @view.classList.add 'dontshow'
