"use strict";const u=require("react/jsx-runtime"),l=require("../vendor.cjs"),t=require("react"),ce=require("react-dom"),f=require("../tools/tools.cjs"),G=require("./tooltip-arrow.cjs"),J=require("./tooltip-inner.cjs"),E=function(Q){var V,W;const{arrowProps:d,as:X="div",className:L,container:o,dropOldClass:x,fade:q=!0,html:S,inner:A,innerProps:Y,offset:Z,onChange:y,placement:n="top",style:j,trigger:b,triggerType:h="hover",triggerWrapper:$,variables:I,visible:v,...ee}=Q,[R,T]=t.useState(!1),[s,g]=t.useState(!1),k=t.useRef(null),[B,D]=t.useState(typeof o!="string"?o:null),[H,O]=t.useState(!1),te=t.useRef(()=>{p(!0)}),ne=t.useRef(()=>{p(!0)}),oe=t.useRef(()=>{p(!1)}),se=t.useRef(()=>{O(!0)}),re=t.useRef(()=>{O(!1)}),N=t.useRef(null),{floatingStyles:ie,middlewareData:_,refs:i}=l.useFloating({middleware:[l.offset(()=>Z??8,[s]),l.shift(e=>e,[s]),l.flip(e=>e,[s]),l.size(e=>e,[s]),l.arrow(e=>({...e,element:k}),[s])],onOpenChange:g,open:s,placement:f.findTruthyClassOrDefault([["bottom",n==="bottom"],["left",n==="start"||n==="left"],["right",n==="end"||n==="right"],["top",n==="top"]],"right"),whileElementsMounted:l.autoUpdate}),p=t.useCallback(e=>{y==null||y(e)},[y]),P=t.useMemo(()=>{const e=f.classx(!x&&"tooltip",q&&"fade",s&&"show",n&&{"bs-tooltip-bottom":n==="bottom","bs-tooltip-end":n==="end"||n==="right","bs-tooltip-start":n==="start"||n==="left","bs-tooltip-top":n==="top"},L),c=f.stylex((a,M)=>({tKey:f.convertBsKeyToVar(M)}),I,j);return{className:e,style:c}},[L,x,q,n,s,j,I]),w=t.useMemo(()=>f.isArray(h)?h:[h],[h]),K=t.useMemo(()=>e=>({...e}),[]);return t.useEffect(()=>{if(v&&!R){T(!0);return}const e=i.floating.current;if(!e)return;const c=()=>{T(!!v)};e.addEventListener("transitionend",c);let a;return v?a=requestAnimationFrame(()=>g(!0)):g(!1),()=>{e.removeEventListener("transitionend",c),a&&cancelAnimationFrame(a)}},[i.floating,R,v]),t.useEffect(()=>{if(typeof o=="string"){const e=o.startsWith("#")?document.getElementById(o.slice(1)):document.querySelector(o);D(e)}else D(o)},[o]),t.useEffect(()=>{const e=te.current,c=ne.current,a=oe.current,M=se.current,le=re.current,z=N.current,r=[];if(w.includes("focus")&&r.push({fn:e,type:"focus"}),w.includes("hover")?(r.push({fn:c,type:"mouseenter"}),r.push({fn:a,type:"mouseleave"})):(r.push({fn:M,type:"mouseenter"}),r.push({fn:le,type:"mouseleave"})),r.length){let m=i.reference.current;z&&(m=z);const U=()=>{H||(g(!1),p(!1))};return document.body.addEventListener("click",U),m&&r.forEach(({fn:F,type:C})=>m.addEventListener(C,F)),()=>{document.body.removeEventListener("click",U),m&&r.forEach(({fn:F,type:C})=>m.removeEventListener(C,F))}}},[H,p,i.reference,w]),u.jsxs(u.Fragment,{children:[b&&($?u.jsx("span",{className:"d-inline-block",ref:N,tabIndex:0,children:b(i.setReference,K)}):b(i.setReference,K)),ce.createPortal(R&&u.jsxs(X,{...ee,...P,ref:i.setFloating,style:{...P.style,...ie},children:[u.jsx(G.TooltipArrow,{...f.mergeProps(d,{style:{...d==null?void 0:d.style,left:(V=_.arrow)==null?void 0:V.x,top:(W=_.arrow)==null?void 0:W.y}}),onRef:e=>k.current=e}),(A||S)&&u.jsx(J.TooltipInner,{...Y,html:S,children:A})]}),B||document.body)]})};E.Arrow=G.TooltipArrow;E.Inner=J.TooltipInner;E.displayName="BRL.Tooltip";exports.Tooltip=E;
//# sourceMappingURL=tooltip.cjs.map
