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{DialogTriggerEventEnum as h,DialogAnimationTypeEnum as m,Dialog as d}from"@vibe/dialog/mockedClassNames";import{TooltipPositions as c,TooltipTheme as T}from"./TooltipConstants.js";import{getStyle as u}from"../../helpers/typesciptCssModulesHelper.js";import w from"./Tooltip.module.scss.js";import{getTestId as g,ComponentDefaultTestId as y}from"../../tests/testIds.js";import{Icon as S}from"@vibe/icon/mockedClassNames";import{Flex as f}from"@vibe/layout/mockedClassNames";var v={lastTooltipHideTS:null,openTooltipsCount:0},D=function(h){function m(e){var o;return t(this,m),(o=i(this,m,[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(m,p),o(m,[{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,g=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(w.tooltip,u(w,s(t)),p),dir:g},c&&r.createElement("img",{className:w.image,src:c,alt:""}),r.createElement("div",{className:a(w.content)},d&&r.createElement(f,{gap:"xs"},T&&r.createElement(S,{iconSize:"20",icon:T}),r.createElement("div",{className:w.title},d)),e)):null):null}},{key:"onTooltipShow",value:function(){if(!this.wasShown){var e=this.props.onTooltipShow;v.openTooltipsCount++,this.wasShown=!0,e&&e()}}},{key:"onTooltipHide",value:function(){if(this.wasShown){var e=this.props.onTooltipHide;v.lastTooltipHideTS=Date.now(),v.openTooltipsCount--,this.wasShown=!1,e&&e()}}},{key:"getTimeSinceLastTooltip",value:function(){return v.openTooltipsCount>0?0:v.lastTooltipHideTS?Date.now()-v.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 h=this.renderTooltipContent,m=Object.assign(Object.assign({},this.props),{position:p,"data-testid":l||g(y.TOOLTIP,s),tooltip:i,content:h,tooltipClassName:a(w.arrow,u(w,t),n),onDialogDidHide:this.onTooltipHide,onDialogDidShow:this.onTooltipShow,getDynamicShowDelay:this.getShowDelay});return r.createElement(d,Object.assign({},m,{animationType:"expand"}),o)}}])}();D.positions=c,D.hideShowTriggers=h,D.themes=T,D.animationTypes=m,D.defaultProps={moveBy:{main:4,secondary:0},theme:"dark",position:"top",hideDelay:100,showDelay:300,disableDialogSlide:!0,animationType:m.EXPAND,withoutDialog:!1,tip:!0,hideWhenReferenceHidden:!1,modifiers:[],showTrigger:D.hideShowTriggers.MOUSE_ENTER,hideTrigger:D.hideShowTriggers.MOUSE_LEAVE,showOnDialogEnter:!0,referenceWrapperClassName:"",addKeyboardHideShowTriggersByDefault:!0,open:!1};export{D as default};
//# sourceMappingURL=Tooltip.js.map
