'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
/**
 * Created by geweimin on 17/6/19.
 */

var hiddenToolTips = function hiddenToolTips() {
  document.getElementById('toolTips').style.visibility = 'hidden';
};

var showToolTips = function showToolTips(ele, content, setting) {
  var clientRect = ele.getBoundingClientRect();
  var toolTips = document.querySelector('#toolTips');
  var arrow = document.querySelector('#tipsArrow');
  var tipContent = document.querySelector('#tipContent');
  if (!toolTips) {
    toolTips = document.createElement('div');
    toolTips.className = 'toolTips';
    toolTips.id = 'toolTips';
    arrow = document.createElement('span');
    arrow.className = 'tipsArrow';
    arrow.id = 'tipsArrow';
    toolTips.appendChild(arrow);
    tipContent = document.createElement('div');
    tipContent.className = 'tipContent';
    tipContent.id = 'tipContent';
    toolTips.appendChild(tipContent);
  } else {
    toolTips.style.visibility = 'visible';
  }
  toolTips.style.top = clientRect.top + clientRect.height + 5 + 'px';
  toolTips.style.left = clientRect.left + 'px';
  document.getElementsByTagName('body')[0].append(toolTips);
  var tipContentChild = "<table cellSpacing=0 cellPadding=0 class='need-border'>";
  tipContentChild += '<div style=\'white-space: nowrap;\'>' + content + '</div>';
  tipContentChild += '</table>';
  tipContent.innerHTML = tipContentChild;
};

var addToolTips = exports.addToolTips = function addToolTips(ele, content, event, setting) {
  if (event === 'hover') {
    ele.addEventListener('mouseover', function (e) {
      showToolTips(ele, content, setting);
    });

    ele.addEventListener('mouseout', function (e) {
      hiddenToolTips();
    });
  } else if (event === 'click') {
    ele.addEventListener('click', function (e) {
      var toolTips = document.getElementById('toolTips');
      if (toolTips && toolTips.style.visibility === 'hidden') {
        showToolTips(ele, content, setting);
      } else {
        hiddenToolTips();
      }
    });
  } else {
    showToolTips(ele, content, setting);
    setTimeout(function () {
      hiddenToolTips();
    }, 2000);
  }
};