text: "use strict";
  
  exports.__esModule = true;
  exports.default = void 0;
  
  var _react = _interopRequireWildcard(require("react"));
  
  var _icons = require("../icons");
  
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  
  const IndicatorButtonTooltip = ({
    content,
    overrideShow,
    show,
    testId,
    closable,
    onClose,
    onAppear,
    onDisappear
  }) => {
    const tooltipRef = (0, _react.useRef)(null);
    const [visible, setVisible] = (0, _react.useState)(overrideShow || show);
    const shouldShow = (0, _react.useMemo)(() => overrideShow || show, [overrideShow, show]);
  
    const onCloseClick = event => {
      event.preventDefault();
      event.stopPropagation();
  
      if (onClose) {
        onClose();
      }
    };
  
    (0, _react.useEffect)(() => {
      if (shouldShow) {
        setVisible(true);
      }
    }, [shouldShow]);
    (0, _react.useEffect)(() => {
      // check to make sure that tootip fades out before setting it to 'display: none'
      const onTransitionEnd = event => {
        const {
          propertyName,
          target
        } = event;
  
        if (target !== tooltipRef.current) {
          return;
        }
  
        if (tooltipRef.current) {
          if (window && propertyName === `opacity`) {
            const opacity = window.getComputedStyle(tooltipRef.current).getPropertyValue(`opacity`);
  
            if (opacity === `0`) {
              if (typeof onDisappear === `function`) {
                onDisappear();
              }
  
              setVisible(false);
            } else {
              if (typeof onAppear === `function`) {
                onAppear();
              }
            }
          }
        }
      };
  
      if (tooltipRef.current) {
        tooltipRef.current.addEventListener(`transitionend`, onTransitionEnd);
      }
  
      return () => {
        if (tooltipRef.current) {
          tooltipRef.current.removeEventListener(`transitionend`, onTransitionEnd);
        }
      };
    }, []);
    return /*#__PURE__*/_react.default.createElement("div", {
      "data-gatsby-preview-indicator": "tooltip",
      "data-gatsby-preview-indicator-visible": `${overrideShow || show}`,
      "data-gatsby-preview-indicator-removed": `${!visible}`,
      "data-testid": `${testId}-tooltip`,
      ref: tooltipRef
    }, /*#__PURE__*/_react.default.createElement("div", {
      "data-gatsby-preview-indicator": "tooltip-inner"
    }, content, closable && /*#__PURE__*/_react.default.createElement("span", {
      "data-gatsby-preview-indicator": "tooltip-close-btn",
      onClick: onCloseClick
    }, _icons.closeIcon)));
  };
  
  var _default = IndicatorButtonTooltip;
  exports.default = _default;