import{r as a}from"./index-CqIc3cxq.js";import{l as v}from"./chunk-EPOLDU6W-BCLmut3y.js";import{a as P}from"./root-loader-BOzEMapJ.js";import{o as u,l as E,i as R,s as g}from"./schemas-Uj5SZtvt.js";const k=u({type:E("epicshop:file-change"),data:u({filePaths:R(g())})});function w({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 f=k.safeParse(JSON.parse(t.data));if(!f.success)return;const{data:p}=f;p.type==="epicshop:file-change"&&(console.log("🐨 Revalidating due to file changes:",p.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 $=ENV.EPICSHOP_DEPLOYED?()=>null:w;export{$ as u};
//# sourceMappingURL=revalidation-ws-BJWJviUX.js.map
