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


module.exports =
class Tooltip
  constructor: (@parent, content, {@cond, @delay}={}) ->
    @cond  = (-> true) unless @cond?
    @delay = 150       unless @delay?

    @view = @tooltipView content
    document.body.appendChild @view
    @showOnHover()
    this

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


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

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

  destroy: ->
    if document.body.contains @view
      document.body.removeChild @view
    @parent.onmouseover = @oldOnMouseOver
    @parent.onmouseout = @oldOnMouseOut

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