'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');

var useDelayedTooltip = function useDelayedTooltip(openDelay, closeDelay) {
  var _useState = React.useState(false),
    _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
    opened = _useState2[0],
    setOpened = _useState2[1];
  var openTimeoutRef = React.useRef(null);
  var closeTimeoutRef = React.useRef(null);
  var clearTimeouts = function clearTimeouts() {
    if (openTimeoutRef.current) {
      clearTimeout(openTimeoutRef.current);
      openTimeoutRef.current = null;
    }
    if (closeTimeoutRef.current) {
      clearTimeout(closeTimeoutRef.current);
      closeTimeoutRef.current = null;
    }
  };
  var showTooltip = function showTooltip() {
    clearTimeouts();
    openTimeoutRef.current = setTimeout(function () {
      setOpened(true);
    }, openDelay);
  };
  var hideTooltip = function hideTooltip() {
    clearTimeouts();
    closeTimeoutRef.current = setTimeout(function () {
      setOpened(false);
    }, closeDelay);
  };
  React.useEffect(function () {
    return clearTimeouts;
  }, []);
  return {
    opened: opened,
    setOpened: setOpened,
    showTooltip: showTooltip,
    hideTooltip: hideTooltip
  };
};

exports.useDelayedTooltip = useDelayedTooltip;
