import{inherits as o,createClass as e,classCallCheck as t,callSuper as i}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{isFunction as n,camelCase as s}from"es-toolkit";import a from"classnames";import r,{isValidElement as l,PureComponent as p}from"react";import{TooltipPositions as d,TooltipTheme as h}from"./TooltipConstants.js";import{getStyle as m}from"../../helpers/typesciptCssModulesHelper.js";import c from"./Tooltip.module.scss.js";import{getTestId as T,ComponentDefaultTestId as g}from"../../tests/testIds.js";import{HideShowEvent as u,AnimationType as w}from"../../../components/dialog/dist/Dialog/DialogConstants.js";import y from"../../../components/layout/dist/Flex/Flex.js";import S from"../../../components/icon/dist/Icon/Icon.js";import f from"../../../components/dialog/dist/Dialog/Dialog.js";var D={lastTooltipHideTS:null,openTooltipsCount:0},v=function(d){function h(o){var e;return t(this,h),(e=i(this,h,[o])).renderTooltipContent=e.renderTooltipContent.bind(e),e.getShowDelay=e.getShowDelay.bind(e),e.onTooltipShow=e.onTooltipShow.bind(e),e.onTooltipHide=e.onTooltipHide.bind(e),e.wasShown=!1,e}return o(h,p),e(h,[{key:"renderTooltipContent",value:function(){var o,e=this.props,t=e.theme,i=e.content,p=e.className,d=e.style,h=e.maxWidth,T=e.title,g=e.image,u=e.icon,w=e.dir;return i?(n(i)?o=i():(l(i)||"string"==typeof i&&i||Array.isArray(i)&&i.length>0)&&(o=i),o?r.createElement("div",{style:h?Object.assign(Object.assign({},d),{"--tooltip-max-width":"".concat(h,"px")}):d,className:a(c.tooltip,m(c,s(t)),p),dir:w},g&&r.createElement("img",{className:c.image,src:g,alt:""}),r.createElement("div",{className:a(c.content)},T&&r.createElement(y,{gap:"xs"},u&&r.createElement(S,{iconSize:"20",icon:u}),r.createElement("div",{className:c.title},T)),o)):null):null}},{key:"onTooltipShow",value:function(){if(!this.wasShown){var o=this.props.onTooltipShow;D.openTooltipsCount++,this.wasShown=!0,o&&o()}}},{key:"onTooltipHide",value:function(){if(this.wasShown){var o=this.props.onTooltipHide;D.lastTooltipHideTS=Date.now(),D.openTooltipsCount--,this.wasShown=!1,o&&o()}}},{key:"getTimeSinceLastTooltip",value:function(){return D.openTooltipsCount>0?0:D.lastTooltipHideTS?Date.now()-D.lastTooltipHideTS:1/0}},{key:"getShowDelay",value:function(){var o=this.props,e=o.showDelay,t=o.immediateShowDelay,i=this.getTimeSinceLastTooltip();return(0===t||t)&&1500>i?{showDelay:t,preventAnimation:!0}:{showDelay:e,preventAnimation:!1}}},{key:"render",value:function(){var o=this.props,e=o.children,t=o.theme,i=o.tip,n=o.arrowClassName,s=o.id,l=o["data-testid"],p=o.position;if(!e&&!o.forceRenderWithoutChildren)return null;if(o.withoutDialog)return this.renderTooltipContent();var d=this.renderTooltipContent,h=Object.assign(Object.assign({},this.props),{position:p,"data-testid":l||T(g.TOOLTIP,s),tooltip:i,content:d,tooltipClassName:a(c.arrow,m(c,t),n),onDialogDidHide:this.onTooltipHide,onDialogDidShow:this.onTooltipShow,getDynamicShowDelay:this.getShowDelay});return r.createElement(f,Object.assign({},h,{animationType:"expand"}),e)}}])}();v.positions=d,v.hideShowTriggers=u,v.themes=h,v.animationTypes=w,v.defaultProps={moveBy:{main:4,secondary:0},theme:"dark",position:"top",hideDelay:100,showDelay:300,disableDialogSlide:!0,animationType:w.EXPAND,withoutDialog:!1,tip:!0,hideWhenReferenceHidden:!1,modifiers:[],showTrigger:v.hideShowTriggers.MOUSE_ENTER,hideTrigger:v.hideShowTriggers.MOUSE_LEAVE,showOnDialogEnter:!0,referenceWrapperClassName:"",addKeyboardHideShowTriggersByDefault:!0,open:!1};export{v as default};
//# sourceMappingURL=Tooltip.js.map
