import{r as a}from"./index-Az39ZADK.js";import{j as v}from"./chunk-UIGDSWPH-BWkP6tD5.js";import{a as P}from"./root-loader-C5P2c7MU.js";import{o as u,l as y,a as E,s as R}from"./types-Cl2NuNg4.js";const g=u({type:y("epicshop:file-change"),data:u({filePaths:E(R())})});function k({watchPaths:h}){const o=P(),s=v(),c=a.useRef(s);a.useEffect(()=>{c.current=s},[s]);const n=new URLSearchParams;for(const e of h)n.append("watch",e);const r=n.toString(),d=o.protocol==="https:"?"wss:":"ws:",m=o.hostname,S=o.port,i=`${d}//${m}:${S}/__ws?${r}`;a.useEffect(()=>{if(!r)return;let e=null;function l(){e&&e.close();try{e=new WebSocket(i)}catch(t){console.error("🐨 EpicShop WebSocket failed to connect:",t);return}e.onmessage=t=>{const p=g.safeParse(JSON.parse(t.data));if(!p.success)return;const{data:f}=p;f.type==="epicshop:file-change"&&(console.log("🐨 Revalidating due to file changes:",f.data.filePaths),c.current.revalidate())},e.onclose=t=>{t.code===1006&&setTimeout(()=>{l()},1e3)},e.onerror=t=>{console.error("🐨 EpicShop WebSocket error:",t)}}return l(),()=>{e?.close()}},[r,i])}const I=ENV.EPICSHOP_DEPLOYED?()=>null:k;export{I as u};
//# sourceMappingURL=revalidation-ws-BahUMYqf.js.map
