import{c as u}from"./react-sxgC8Nxl.js";import{i as d}from"./_virtual___federation_fn_import-DB-0B1B_.js";import{c as p,a as m,s as f,h as j,l as I,w as g,o as P,T as b}from"./index-fLATfv38.js";function h(e){e?localStorage.setItem("projectId",e):localStorage.removeItem("projectId")}function L(){const e=localStorage.getItem("projectId");if(e)return e;if(globalThis.location.search.includes("projectId=")){const r=new URLSearchParams(globalThis.location.search).get("projectId");if(r)return h(r),r}return null}const E=u(e=>({projects:[],projectsLoaded:!1,setProjects:t=>{e(r=>({projects:t,projectsLoaded:!0,...t.some(o=>o.id===r.currentProjectId)?void 0:{currentProjectId:t.length===1?t[0].id:null}}))},currentProjectId:L(),setCurrentProjectId:t=>{e(r=>({currentProjectId:r.projects.some(o=>o.id===t)?t:null}))},resetCurrentProjectId:()=>{e(t=>({currentProjectId:t.projects.length===1?t.projects[0].id:null}))}})),{createTypedEventEmitter:C}=await d("@baseplate-dev/utils");function v(e){return e instanceof b}function l({maxAttempts:e=5}){return()=>(({op:t,next:r})=>P(o=>{let c=null,s=e,i=!1;function a(){c?.unsubscribe(),c=r(t).subscribe({error(n){n.message.includes("Failed to execute")&&s!==0?(s--,setTimeout(a,500)):o.error(n)},next(n){o.next(n)},complete(){i&&o.complete()}})}return a(),()=>{i=!0,c?.unsubscribe()}}))}const S=C(),T=p({url:`${globalThis.location.origin.replace(/^http/,"ws")}/trpc`,onOpen(){S.emit("open",void 0)}}),R=m({links:[f({condition:e=>e.type==="subscription",true:[I({enabled:e=>e.direction==="down"&&e.result instanceof Error}),l({}),g({client:T})],false:[l({maxAttempts:10}),j({url:"/trpc"})]})]});export{S as a,v as i,h as s,R as t,E as u};
//# sourceMappingURL=trpc-BTCor25i.js.map
