import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import _defineProperty from"@babel/runtime/helpers/defineProperty";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["tooltipProps"],_excluded2=["mode","content","closeOnClickOutside","appearTimeout","exitTimeout"];function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import React,{useCallback,useRef}from"react";import{Tooltip}from"../../components/Tooltip";import{useDebounce}from"../../hooks/useDebounce";import{useFlag}from"../../hooks/useFlag";import{useForkRef}from"../../hooks/useForkRef";import{useMutableRef}from"../../hooks/useMutableRef";export var withTooltipPropMode=["mouseover","click"];export var withTooltipPropModeDefault=withTooltipPropMode[0];export var appearTimeoutDefault=400;export var exitTimeoutDefault=200;export function withTooltip(a){return function(b){return React.forwardRef(function(c,d){var e=c.tooltipProps,f=void 0===e?{}:e,g=_objectWithoutProperties(c,_excluded),h=_objectSpread(_objectSpread({},a),f),i=h.mode,j=void 0===i?"mouseover":i,k=h.content,l=h.closeOnClickOutside,m=!(void 0!==l)||l,n=h.appearTimeout,o=void 0===n?appearTimeoutDefault:n,p=h.exitTimeout,q=void 0===p?exitTimeoutDefault:p,r=_objectWithoutProperties(h,_excluded2),s=useFlag(),t=_slicedToArray(s,2),u=t[0],v=t[1],w=useRef(null),x=useRef({tooltip:!1,acnor:!1}),y=useMutableRef([g.onMouseEnter,g.onMouseLeave,r.onMouseEnter,r.onMouseLeave,g.onClick,j,m]),z=useDebounce(useCallback(function(){"mouseover"===y.current[5]&&(x.current.acnor||x.current.tooltip)&&v.on()},[]),o),A=useDebounce(useCallback(function(){"mouseover"!==y.current[5]||x.current.acnor||x.current.tooltip||v.off()},[]),q),B=useCallback(function(a){var b,c;x.current.acnor=!0,z(),null===(b=(c=y.current)[0])||void 0===b?void 0:b.call(c,a)},[]),C=useCallback(function(a){var b,c;x.current.acnor=!1,A(),null===(b=(c=y.current)[1])||void 0===b?void 0:b.call(c,a)},[]),D=useCallback(function(a){var b,c;x.current.tooltip=!0,z(),null===(b=(c=y.current)[2])||void 0===b?void 0:b.call(c,a)},[]),E=useCallback(function(a){var b,c;x.current.tooltip=!1,A(),null===(b=(c=y.current)[3])||void 0===b?void 0:b.call(c,a)},[]),F=useCallback(function(){"click"===y.current[5]&&y.current[6]&&v.off()},[j,m]),G=useCallback(function(a){var b,c;"click"===y.current[5]&&v.toggle(),null===(b=(c=y.current)[4])||void 0===b?void 0:b.call(c,a)},[]);return React.createElement(React.Fragment,null,React.createElement(b,Object.assign({},g,{onClick:G,onMouseEnter:B,onMouseLeave:C,ref:useForkRef([w,d])})),React.createElement(Tooltip,Object.assign({},r,{isOpen:u&&!!k,className:r.className,anchorRef:w,onClickOutside:F,onMouseEnter:D,onMouseLeave:E}),k))})}}
//# sourceMappingURL=withTooltip.js.map