text: import ToolTip from'./tooltip-component';import{getTouchEvent as touchSafeEvent}from'../../_internal/lib/lib';const TOOL_TIP_KEY='__FC_tooltipText',MOVE_HANDLER='__FC_onTooltipMove',OUT_HANDLER='__FC_onTooltipOut',OVER_HANDLER='__FC_onTooltipOver';let moveHandler=function(a,b,c){c=touchSafeEvent(c);let d=b.universe.getBoundingClientRect(),e=c.clientX,f=c.clientY;e-=d.left,f-=d.top,e+=11,f+=11,ToolTipController._draw.call(b,e,f,this.data(TOOL_TIP_KEY),a)},outHandler=function(a){ToolTipController._hide(a)};class ToolTipController{constructor(a){let b=this,c=b.config={};b.universe=a,b.toolTips={implicit:[],explicit:[]},b.hideImplicitToolTip=function(a){let d=c.lastActiveToolip;d&&a.target!==d.getData('targetElement').node&&(ToolTipController._hide(d),b.config.lastActiveToolip=void 0)}}_createToolTip(a){let b;return b=new ToolTip(this.universe),this.toolTips[a].push(b),b}enableToolTip(a,b){let c,d=this,e=d.toolTips.implicit,f=e.length,g=d.config;return b?a.data(TOOL_TIP_KEY)?(0<f&&(c=e[f-1],c.setUniverse(this.universe),c.getData('active')&&c.show(b)),a.data(TOOL_TIP_KEY,b),d):(c=d._getAvailableToolTip('implicit'),d.disableToolTip(a),a.data(TOOL_TIP_KEY,b),a.data(MOVE_HANDLER,moveHandler.bind(a,c,d)),a.data(OUT_HANDLER,outHandler.bind(a,c)),a.data(OVER_HANDLER,function(b){return function(f){d.draw(f,a.data(TOOL_TIP_KEY),c),c.setData('targetElement',b),g.lastActiveToolip=c}}(a)),a.on('fc-mousemove',a.data(MOVE_HANDLER)),a.on('fc-mouseout',a.data(OUT_HANDLER)),a.on('fc-mouseover',a.data(OVER_HANDLER)),d):(d.disableToolTip(a),d)}disableToolTip(a){let b=a.data(OUT_HANDLER),c=a.data(MOVE_HANDLER),d=a.data(OVER_HANDLER);return c&&a.off('fc-mousemove',c),b&&a.off('fc-mouseout',b),d&&a.off('fc-mouseover',d),a.removeData(TOOL_TIP_KEY),this}draw(a,b,c){let d,e,f=this.universe.getBoundingClientRect();return a=touchSafeEvent(a),d=a.clientX,e=a.clientY,c=c||this._getAvailableToolTip('explicit'),c.setStyle(this.config.tooltipStyle),c.setUniverse(this.universe),d-=f.left,e-=f.top,d+=11,e+=11,ToolTipController._draw.call(this,d,e,b,c),c}drawAt(a,b,c,d){return d=d||this._getAvailableToolTip('explicit'),d.setStyle(this.config.tooltipStyle),ToolTipController._draw.call(this,a,b,c,d),d}static _draw(a,b,c,d){d.setStyle(this.config.tooltipStyle),d.show(c),d.update(a,b)}_getAvailableToolTip(a){let b,c,d=this.toolTips[a];for(var e=0,f=d.length;e<f;e++)if(b=d[e],c=!1===b.getData('active'),c)return b;return this._createToolTip(a)}setStyle(a){let b=this,c=b.config,d=c.tooltipStyle||(c.tooltipStyle={});for(var e in a)d[e]=a[e]}hide(a){return ToolTipController._hide(a,'dispose'),this}hideAll(){var a,b,c=this;for(a in c.toolTips)for(b=0;b<c.toolTips[a].length;b++)ToolTipController._hide(c.toolTips[a][b],'dispose')}static _hide(a,b){a&&(b?a.dispose():a.hide())}}export default{extension:ToolTipController,name:'ToolTipController',type:'plugin'};