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