import{s as e}from"./chunk-Bj-mKKzh.js";import{Hr as t,Nr as n,Wi as r,d as i,na as a,sa as o}from"./src-BOCweS1p.js";import{Ho as s,sa as c}from"./app-server-manager-signals-Yn0WSnoY.js";import{n as l}from"./jsx-runtime-CiQ1k8xo.js";import{F as u,R as d,V as f,h as p,lt as m,n as h,r as g,u as _}from"./vscode-api-DjORcpSo.js";import{o as v,s as y}from"./thread-context-inputs-C9hcxtXy.js";import{t as b}from"./use-global-state-baOKTuK6.js";var x=a({dirs:r(o()).optional(),hostId:o().optional()}),S=f(p,({params:e,source:t},{queryClient:n})=>({enabled:e?.dirs==null||e.dirs.length>0,meta:{gitOrigins:{dirs:e?.dirs,hostId:e?.hostId}},placeholderData:()=>C(n,e),queryFn:()=>h(`git-origins`,{params:e,source:t}),queryKey:g(`git-origins`,e),staleTime:_.FIVE_SECONDS}));function C(e,t){if(!(t?.dirs==null||t.dirs.length===0))for(let n of e.getQueryCache().findAll({queryKey:g(`git-origins`)})){let r=x.safeParse(n.meta?.gitOrigins);if(!r.success||r.data.hostId!==t.hostId||r.data.dirs==null)continue;let i=new Set(r.data.dirs);if(!t.dirs.every(e=>i.has(e)))continue;let a=e.getQueryData(n.queryKey);if(a!=null)return a}}var w=m(),T=e(l(),1);function E(e,t,n){if(t==null||e==null)return null;let r=i(n);return e.find(e=>e.hostId===t&&i(e.remotePath)===r)??null}function D({sourceWorkspaceRoot:e,sourceGitRoot:t,destinationWorkspaceRoot:n,destinationGitRoot:r}){let i=A(e,t);return i!=null&&A(n,r)===i}function O({sourceWorkspaceRoot:e,sourceGitRoot:t,destinationWorkspaceRoots:n,destinationGitOrigins:r}){return n.find(n=>D({sourceWorkspaceRoot:e,sourceGitRoot:t,destinationWorkspaceRoot:n,destinationGitRoot:r?.find(e=>j(e.dir)===j(n))?.root??null}))??null}var k=d(p,({sourceHostId:e,sourceGitRoot:t,sourceWorkspaceRoot:n},{get:r})=>{if(e!==`local`||t==null||n==null)return[];let a=r(v),o=new Map;for(let e of r(y)){if(a.find(t=>t.hostId===e.hostId)==null)continue;let t=o.get(e.hostId);if(t!=null){t.projects.push(e);continue}o.set(e.hostId,{hostId:e.hostId,hostDisplayName:s(e.hostId,a).display_name,projects:[e]})}let c=[];for(let{hostDisplayName:e,hostId:a,projects:s}of o.values()){let o=r(S,{params:{hostId:a,dirs:s.map(e=>e.remotePath)},source:`local_remote_dropdown`});if(o?.isPending){c.push({status:`loading`,hostDisplayName:e,hostId:a});continue}if(o?.isError){c.push({status:`error`,hostDisplayName:e,hostId:a});continue}let l=s.find(e=>{let r=i(e.remotePath),a=o?.data?.origins.find(e=>i(e.dir)===r);return D({sourceWorkspaceRoot:n,sourceGitRoot:t,destinationWorkspaceRoot:e.remotePath,destinationGitRoot:a?.root??null})});l!=null&&c.push({status:`ready`,hostDisplayName:e,project:l})}return c});function A(e,t){if(e==null||t==null)return null;let n=j(e),r=j(t);if(n===r)return``;let i=r===`/`?r:`${r}/`;return n.startsWith(i)?n.slice(i.length):null}function j(e){let t=n(e.trim()).replace(/\/+/g,`/`);return t===`/`?t:t.replace(/\/+$/,``)}function M(e,n){c(e,t.ACTIVE_REMOTE_PROJECT_ID,n??void 0)}function N(e,n){return c(e,t.REMOTE_PROJECTS,n)}function P(){let e=(0,w.c)(21),n=u(p),{data:r,isLoading:i}=b(t.REMOTE_PROJECTS),{data:a}=b(t.ACTIVE_REMOTE_PROJECT_ID),o;e[0]===r?o=e[1]:(o=r??[],e[0]=r,e[1]=o);let s=o,l;e[2]!==s||e[3]!==a?(l=s.find(e=>e.id===a)??null,e[2]=s,e[3]=a,e[4]=l):l=e[4];let d=l,f,m;e[5]!==i||e[6]!==n||e[7]!==d||e[8]!==a?(f=()=>{i||a==null||d!=null||c(n,t.ACTIVE_REMOTE_PROJECT_ID,void 0)},m=[i,n,d,a],e[5]=i,e[6]=n,e[7]=d,e[8]=a,e[9]=f,e[10]=m):(f=e[9],m=e[10]),(0,T.useEffect)(f,m);let h=a??null,g;e[11]===n?g=e[12]:(g=e=>M(n,e),e[11]=n,e[12]=g);let _;e[13]===n?_=e[14]:(_=e=>N(n,e),e[13]=n,e[14]=_);let v;return e[15]!==s||e[16]!==d||e[17]!==h||e[18]!==g||e[19]!==_?(v={selectedRemoteProject:d,selectedRemoteProjectId:h,setSelectedRemoteProjectId:g,remoteProjects:s,setRemoteProjects:_},e[15]=s,e[16]=d,e[17]=h,e[18]=g,e[19]=_,e[20]=v):v=e[20],v}export{P as a,M as i,E as n,S as o,k as r,O as t};
//# sourceMappingURL=remote-projects-B8AFbAx_.js.map