import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import { Children, createElement, Fragment, cloneElement } from 'react';
import _pt from 'prop-types';
import { DisableReachStyleCheck } from '../../utils/helpers/DisableReachStyleCheck.esm.js';
import { useTransition, animated as extendedAnimated } from '../../../node_modules/react-spring/web.esm.js';
import { useTooltip } from '../../../node_modules/@reach/tooltip/dist/tooltip.esm.esm.js';
import TooltipContent from './TooltipContent.esm.js';

var AnimatedTooltipContent = extendedAnimated(TooltipContent);
var transitionConfig = {
  from: {
    opacity: 0,
    transform: "translateY(10px)"
  },
  enter: {
    opacity: 1,
    transform: "translateY(0px)"
  },
  leave: {
    opacity: 0,
    transform: "translateY(10px)"
  }
};
function Tooltip(_ref) {
  var children = _ref.children,
      id = _ref.id,
      label = _ref.label,
      rest = _objectWithoutProperties(_ref, ["children", "id", "label"]);

  // COPIED FROM @reach/tooltip source:
  //
  // We need to pass some properties from the child into useTooltip
  // to make sure users can maintain control over the trigger's ref and events
  var child = Children.only(children);

  var _useTooltip = useTooltip({
    id: id,
    onMouseEnter: child.props.onMouseEnter,
    onMouseMove: child.props.onMouseMove,
    onMouseLeave: child.props.onMouseLeave,
    onFocus: child.props.onFocus,
    onBlur: child.props.onBlur,
    onKeyDown: child.props.onKeyDown,
    onMouseDown: child.props.onMouseDown,
    ref: child.ref
  }),
      _useTooltip2 = _slicedToArray(_useTooltip, 3),
      trigger = _useTooltip2[0],
      tooltipParams = _useTooltip2[1],
      isVisible = _useTooltip2[2];

  var transitions = useTransition(isVisible ? tooltipParams : null, null, transitionConfig);
  return /*#__PURE__*/createElement(Fragment, null, cloneElement(child, trigger), transitions.map(function (_ref2) {
    var tooltip = _ref2.item,
        transitionStyles = _ref2.props,
        key = _ref2.key;

    if (!tooltip) {
      return null;
    }

    return /*#__PURE__*/createElement(AnimatedTooltipContent, _extends({
      key: key,
      label: label,
      tooltipParams: tooltip,
      style: transitionStyles
    }, rest));
  }), /*#__PURE__*/createElement(DisableReachStyleCheck, {
    reachComponent: "tooltip"
  }));
}
Tooltip.propTypes = {
  label: _pt.node.isRequired,
  children: _pt.node.isRequired
};
Tooltip.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "Tooltip",
  "props": {
    "label": {
      "required": true,
      "tsType": {
        "name": "ReactReactNode",
        "raw": "React.ReactNode"
      },
      "description": ""
    },
    "children": {
      "required": true,
      "tsType": {
        "name": "ReactReactNode",
        "raw": "React.ReactNode"
      },
      "description": ""
    },
    "position": {
      "required": false,
      "tsType": {
        "name": "TooltipPosition"
      },
      "description": ""
    }
  }
};

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
  STORYBOOK_REACT_CLASSES["src/components/Tooltip/Tooltip.tsx"] = {
    name: "Tooltip",
    docgenInfo: Tooltip.__docgenInfo,
    path: "src/components/Tooltip/Tooltip.tsx"
  };
}

export default Tooltip;
//# sourceMappingURL=Tooltip.esm.js.map
