class EnterpriseTooltip extends Directive('hn.enterprise')
    constructor: () ->
        return {
        link: (scope, elem, attrs) ->
            box = $('#sidebar-tooltip')
            text = attrs.enterpriseTooltip || ''

            scope.$watch( () ->
                return attrs.enterpriseTooltip
            , (newText) ->
                text = newText
            )

            elem.on({
                'focus': () ->
                    top = elem.offset().top
                    boxWithText = box.addClass('active').html(text)
                    boxWithText.offset(top: top)
                    containerHeight = box.parent().height()
                    boxHeight = box.height()
                    boxBottom = box.offset().top + boxHeight
                    if boxBottom > containerHeight and boxWithText.height() > 300
                        box.addClass('mid-arrow')
                        boxWithText.offset(top: 350)
                    else
                        box.addClass('top-arrow')
                'blur': () ->
                    box.removeClass('active mid-arrow top-arrow')
            })
        }
