import{r as d,u as W,j as Z}from"./index-C_t8dRMU.js";import{S as $,O as tt,W as et,B as k,a as z,P as ot,C as nt,b as st,L as it,c as rt,V as _}from"./three-BZk_I9Ly.js";const m=60,q=120,V=40;function at(){try{const g=document.createElement("canvas");return!!(g.getContext("webgl2")||g.getContext("webgl"))}catch{return!1}}function pt({opacity:g=1}){const T=d.useRef(null),G=d.useRef(0),R=d.useRef({x:0,y:0}),U=d.useRef(W.getState().theme),[S]=d.useState(()=>at());return d.useEffect(()=>W.subscribe(u=>{U.current=u.theme}),[]),d.useEffect(()=>{if(!S)return;const n=T.current;if(!n)return;const u=n.clientWidth,b=n.clientHeight,N=new $,C=new tt(0,u,0,b,-100,100),c=new et({alpha:!0,antialias:!0});c.setSize(u,b),c.setPixelRatio(Math.min(window.devicePixelRatio,2)),n.appendChild(c.domElement);const r=[],v=new k,M=new Float32Array(m*3);for(let e=0;e<m;e++){const s=Math.random()*u,p=Math.random()*b,E=(Math.random()-.5)*.3,L=(Math.random()-.5)*.3;r.push({position:new _(s,p,0),velocity:new _(E,L,0),baseY:p}),M[e*3]=s,M[e*3+1]=p,M[e*3+2]=0}v.setAttribute("position",new z(M,3));const A=new ot({size:2,color:new nt("#007acc"),transparent:!0,opacity:.6,sizeAttenuation:!1}),H=new st(v,A);N.add(H);const a=new k,j=m*m,Y=new Float32Array(j*6),X=new Float32Array(j*6);a.setAttribute("position",new z(Y,3)),a.setAttribute("color",new z(X,3));const P=new it({vertexColors:!0,transparent:!0,opacity:.12,depthTest:!1}),J=new rt(a,P);N.add(J);const D=e=>{const s=n.getBoundingClientRect();R.current.x=e.clientX-s.left,R.current.y=e.clientY-s.top};n.addEventListener("mousemove",D);let F=0;const I=()=>{G.current=requestAnimationFrame(I),F+=.005;const e=U.current==="dark",s=0,p=.478,E=.8;A.color.setRGB(s,p,E),A.opacity=e?.5:.35,P.opacity=e?.08:.05;const L=v.attributes.position.array,K=R.current.x,Q=R.current.y;for(let o=0;o<m;o++){const t=r[o];t.position.x+=t.velocity.x,t.position.y+=t.velocity.y+Math.sin(F+o*.1)*.08;const y=K-t.position.x,h=Q-t.position.y,l=Math.sqrt(y*y+h*h);l<200&&l>1&&(t.position.x+=y/l*V*.005,t.position.y+=h/l*V*.005),t.position.x<-10&&(t.position.x=u+10),t.position.x>u+10&&(t.position.x=-10),t.position.y<-10&&(t.position.y=b+10),t.position.y>b+10&&(t.position.y=-10),L[o*3]=t.position.x,L[o*3+1]=t.position.y}v.attributes.position.needsUpdate=!0;let B=0;const f=a.attributes.position.array,x=a.attributes.color.array;for(let o=0;o<m;o++)for(let t=o+1;t<m;t++){const y=r[o].position.x-r[t].position.x,h=r[o].position.y-r[t].position.y,l=Math.sqrt(y*y+h*h);if(l<q){const w=1-l/q,i=B*6;f[i]=r[o].position.x,f[i+1]=r[o].position.y,f[i+2]=0,f[i+3]=r[t].position.x,f[i+4]=r[t].position.y,f[i+5]=0,x[i]=s*w,x[i+1]=p*w,x[i+2]=E*w,x[i+3]=s*w,x[i+4]=p*w,x[i+5]=E*w,B++}}a.setDrawRange(0,B*2),a.attributes.position.needsUpdate=!0,a.attributes.color.needsUpdate=!0,c.render(N,C)};I();const O=()=>{const e=n.clientWidth,s=n.clientHeight;C.right=e,C.bottom=s,C.updateProjectionMatrix(),c.setSize(e,s)};return window.addEventListener("resize",O),()=>{cancelAnimationFrame(G.current),n.removeEventListener("mousemove",D),window.removeEventListener("resize",O),c.dispose(),v.dispose(),A.dispose(),a.dispose(),P.dispose(),n.contains(c.domElement)&&n.removeChild(c.domElement)}},[S]),S?Z.jsxDEV("div",{ref:T,style:{position:"absolute",inset:0,zIndex:0,pointerEvents:"auto",opacity:g}},void 0,!1,{fileName:"/Users/thuliobittencourt/Documents/Projetos/ExpxAgents_2/dashboard/src/components/ThreeBackground.tsx",lineNumber:225,columnNumber:5},this):null}export{pt as ThreeBackground};
