'use strict';

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

var React = require('react');
var classNames = require('clsx');
var reactPopperTooltip = require('react-popper-tooltip');
var reactTransitionGroup = require('react-transition-group');
var Portal = require('@prom-ui/core/Portal');

function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }

function _interopNamespaceCompat(e) {
  if (e && typeof e === 'object' && 'default' in e) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var React__namespace = /*#__PURE__*/_interopNamespaceCompat(React);
var classNames__default = /*#__PURE__*/_interopDefaultCompat(classNames);

function _extends() {
  _extends = Object.assign ? Object.assign.bind() : function (target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];
      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }
    return target;
  };
  return _extends.apply(this, arguments);
}

var css = {"content":"Tooltip__content___M5WYU","arrow":"Tooltip__arrow___sHrj0","animation":"Tooltip__animation___DYqdH","root":"Tooltip__root___Xkx-7","white":"Tooltip__white___6gvS7","black":"Tooltip__black___e8sBo","enter":"Tooltip__enter___amIjy","enterActive":"Tooltip__enterActive___oLDm5","enterDone":"Tooltip__enterDone___aZSAB","exit":"Tooltip__exit___FtdvP","exitActive":"Tooltip__exitActive___Vnj23","exitDone":"Tooltip__exitDone___er4Mu"};

var Tooltip = function Tooltip(_ref) {
  var children = _ref.children,
    content = _ref.content,
    isVisible = _ref.isVisible,
    onVisibleChange = _ref.onVisibleChange,
    classes = _ref.classes,
    _ref$isRenderPortal = _ref.isRenderPortal,
    isRenderPortal = _ref$isRenderPortal === void 0 ? true : _ref$isRenderPortal,
    _ref$isCloseOnOutside = _ref.isCloseOnOutsideClick,
    isCloseOnOutsideClick = _ref$isCloseOnOutside === void 0 ? true : _ref$isCloseOnOutside,
    _ref$isCloseOnTrigger = _ref.isCloseOnTriggerHidden,
    isCloseOnTriggerHidden = _ref$isCloseOnTrigger === void 0 ? true : _ref$isCloseOnTrigger,
    _ref$isDefaultVisible = _ref.isDefaultVisible,
    isDefaultVisible = _ref$isDefaultVisible === void 0 ? false : _ref$isDefaultVisible,
    _ref$isFollowCursor = _ref.isFollowCursor,
    isFollowCursor = _ref$isFollowCursor === void 0 ? false : _ref$isFollowCursor,
    _ref$isInteractive = _ref.isInteractive,
    isInteractive = _ref$isInteractive === void 0 ? false : _ref$isInteractive,
    _ref$isShowArrow = _ref.isShowArrow,
    isShowArrow = _ref$isShowArrow === void 0 ? true : _ref$isShowArrow,
    _ref$delayHide = _ref.delayHide,
    delayHide = _ref$delayHide === void 0 ? 0 : _ref$delayHide,
    _ref$delayShow = _ref.delayShow,
    delayShow = _ref$delayShow === void 0 ? 0 : _ref$delayShow,
    _ref$trigger = _ref.trigger,
    trigger = _ref$trigger === void 0 ? 'hover' : _ref$trigger,
    _ref$placement = _ref.placement,
    placement = _ref$placement === void 0 ? 'auto' : _ref$placement,
    _ref$theme = _ref.theme,
    theme = _ref$theme === void 0 ? 'white' : _ref$theme,
    _ref$offset = _ref.offset,
    offset = _ref$offset === void 0 ? [0, 12] : _ref$offset,
    _ref$padding = _ref.padding,
    padding = _ref$padding === void 0 ? 16 : _ref$padding,
    _ref$width = _ref.width,
    width = _ref$width === void 0 ? 'auto' : _ref$width,
    _ref$zIndex = _ref.zIndex,
    zIndex = _ref$zIndex === void 0 ? 900 : _ref$zIndex;
  var _usePopperTooltip = reactPopperTooltip.usePopperTooltip({
      trigger: trigger,
      placement: placement,
      delayHide: delayHide,
      delayShow: delayShow,
      onVisibleChange: onVisibleChange,
      offset: offset,
      defaultVisible: isDefaultVisible,
      closeOnOutsideClick: isCloseOnOutsideClick,
      closeOnTriggerHidden: isCloseOnTriggerHidden,
      visible: isVisible,
      followCursor: isFollowCursor,
      interactive: isInteractive
    }),
    getArrowProps = _usePopperTooltip.getArrowProps,
    getTooltipProps = _usePopperTooltip.getTooltipProps,
    setTooltipRef = _usePopperTooltip.setTooltipRef,
    setTriggerRef = _usePopperTooltip.setTriggerRef,
    visible = _usePopperTooltip.visible;
  return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.cloneElement(children, {
    ref: setTriggerRef
  }), /*#__PURE__*/React__namespace.createElement(reactTransitionGroup.CSSTransition, {
    classNames: css,
    timeout: 166,
    "in": visible,
    unmountOnExit: true
  }, /*#__PURE__*/React__namespace.createElement(Portal.Portal, {
    isActive: isRenderPortal
  }, /*#__PURE__*/React__namespace.createElement("div", _extends({
    ref: setTooltipRef
  }, getTooltipProps({
    className: classNames__default.default(css.root, css[theme], classes === null || classes === void 0 ? void 0 : classes.root),
    style: {
      width: width,
      zIndex: zIndex
    }
  })), /*#__PURE__*/React__namespace.createElement("div", {
    className: classNames__default.default(css.animation, classes === null || classes === void 0 ? void 0 : classes.animation)
  }, isShowArrow && /*#__PURE__*/React__namespace.createElement("div", getArrowProps({
    className: classNames__default.default(css.arrow, classes === null || classes === void 0 ? void 0 : classes.arrow)
  })), /*#__PURE__*/React__namespace.createElement("div", {
    className: classNames__default.default(css.content, classes === null || classes === void 0 ? void 0 : classes.content),
    style: {
      padding: padding
    }
  }, content))))));
};
Tooltip.displayName = 'Tooltip';

exports.Tooltip = Tooltip;

require('./style.development.css');
