import{T as J}from"./vendor-vue-runtime-dom-B2rky8vu.js";import{d as K,u as Q,e as H,w as Y,b as Z,f as I,i as T,p as X,t as N,k as ee,x,j as te,m as oe,T as ae,n as V}from"./vendor-vue-runtime-core-DwK6Ry68.js";import{r}from"./vendor-vue-reactivity-CheHbvBM.js";import{b as q,a as ne,t as se}from"./vendor-vue-shared-DrzsEcag.js";const le=["aria-label"],re={class:"ccb-tooltip__text"},de=K({__name:"Tooltip",props:{text:{},placement:{default:"top"},maxWidth:{default:240},offset:{default:8},disabled:{type:Boolean,default:!1},target:{},interactive:{type:Boolean,default:!0},hideDelay:{default:80},showDefaultIcon:{type:Boolean,default:!0},bubbleClass:{}},setup(F){const e=F,y=Q(),h=r(null),w=r(null),f=r(!1),E=r({}),L=r({}),n=r(null),m=r(!1),p=r(!1);let b=null;const _=H(()=>!!(e.text||y.content)),O=H(()=>!!y.default),d=()=>{b&&(window.clearTimeout(b),b=null)},j=()=>{if(e.target instanceof HTMLElement)return e.target;const o=h.value;return e.target?(o==null?void 0:o.closest(e.target))||document.querySelector(e.target):o},B=()=>{var R;const o=n.value||h.value;if(!o)return;const t=o.getBoundingClientRect(),c=window.innerWidth,l=8,G=((R=w.value)==null?void 0:R.offsetWidth)||e.maxWidth,s={position:"fixed",maxWidth:`${e.maxWidth}px`,zIndex:"100000"};let i=0,v=0;const a={};switch(e.placement){case"bottom":v=t.bottom+e.offset,i=t.left+t.width/2,s.transform="translateX(-50%)",a.left="50%",a.top="-4px",a.transform="translateX(-50%) rotate(45deg)";break;case"left":v=t.top+t.height/2,i=t.left-e.offset,s.transform="translate(-100%, -50%)",a.top="50%",a.right="-4px",a.transform="translateY(-50%) rotate(45deg)";break;case"right":v=t.top+t.height/2,i=t.right+e.offset,s.transform="translateY(-50%)",a.top="50%",a.left="-4px",a.transform="translateY(-50%) rotate(45deg)";break;case"top":default:v=t.top-e.offset,i=t.left+t.width/2,s.transform="translate(-50%, -100%)",a.left="50%",a.bottom="-4px",a.transform="translateX(-50%) rotate(45deg)";break}if(s.top=`${v}px`,s.left=`${i}px`,e.placement==="top"||e.placement==="bottom"){const D=G/2;i-D<l?(s.left=`${l}px`,s.transform=e.placement==="top"?"translateY(-100%)":"translateY(0)",a.left=`${t.left+t.width/2-l}px`):i+D>c-l&&(s.left=`${c-l}px`,s.transform=e.placement==="top"?"translate(-100%, -100%)":"translateX(-100%)",a.left="auto",a.right=`${c-l-(t.left+t.width/2)-4}px`)}E.value=s,L.value=a},k=async()=>{e.disabled||!_.value||(d(),f.value=!0,await V(),B())},P=()=>{d(),f.value=!1,m.value=!1,p.value=!1},g=()=>{d(),b=window.setTimeout(()=>{!m.value&&!p.value&&P()},e.hideDelay)},$=()=>{m.value=!0,k()},W=()=>{m.value=!1,g()},C=()=>{k()},S=o=>{var c,l;const t=o.relatedTarget;t&&((c=n.value)!=null&&c.contains(t)||(l=w.value)!=null&&l.contains(t))||g()},U=()=>{e.interactive&&(p.value=!0,d())},A=()=>{e.interactive&&(p.value=!1,g())},z=()=>{n.value&&(n.value.removeEventListener("mouseenter",$),n.value.removeEventListener("mouseleave",W),n.value.removeEventListener("focusin",C),n.value.removeEventListener("focusout",S))},M=async()=>{await V(),z(),n.value=j(),n.value&&(n.value.addEventListener("mouseenter",$),n.value.addEventListener("mouseleave",W),n.value.addEventListener("focusin",C),n.value.addEventListener("focusout",S))},u=()=>{f.value&&B()};return Y(()=>e.target,()=>{M()}),Y(f,o=>{o?(window.addEventListener("scroll",u,!0),window.addEventListener("resize",u)):(window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u))}),M(),Z(()=>{d(),z(),window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}),(o,t)=>(T(),I("span",{class:"ccb-tooltip",ref_key:"wrapperRef",ref:h},[O.value||o.showDefaultIcon?X(o.$slots,"default",{key:0},()=>[x("i",{class:"ccb-tooltip__icon ccb-icon-circle-question",tabindex:"0","aria-label":o.text},null,8,le)]):N("",!0),(T(),ee(ae,{to:"body"},[te(J,{name:"ccb-tooltip-fade"},{default:oe(()=>[f.value&&_.value?(T(),I("div",{key:0,ref_key:"bubbleRef",ref:w,class:ne(["ccb-tooltip__bubble",[`ccb-tooltip__bubble--${o.placement}`,o.bubbleClass,{"ccb-tooltip__bubble--interactive":o.interactive}]]),style:q(E.value),role:"tooltip",onMouseenter:U,onMouseleave:A},[X(o.$slots,"content",{},()=>[x("span",re,se(o.text),1)]),x("span",{class:"ccb-tooltip__arrow",style:q(L.value)},null,4)],38)):N("",!0)]),_:3})]))],512))}});export{de as _};
//# sourceMappingURL=Tooltip.vue_vue_type_script_setup_true_lang-STz1Wrqz.js.map
