import{Hr as e,Mt as t,bt as n,jt as r}from"./src-BOCweS1p.js";import{Wo as i,aa as a,mo as o,sa as s,uo as c}from"./app-server-manager-signals-Yn0WSnoY.js";import{f as l,n as u}from"./vscode-api-DjORcpSo.js";import{t as d}from"./thread-context-inputs-C9hcxtXy.js";import{i as f}from"./remote-projects-B8AFbAx_.js";import{t as p}from"./projectless-thread-JZqZP2Qh.js";var m=`New project`,h={create:g,getFolderPath:x,getId:b,getThreadStartCwd:S,remove:y,rename:v,select:_};async function g({addWritableRoot:t,existingLocalProjects:n,name:i,now:a,projectId:o,projectOrder:s,setGlobalSetting:c,sources:l}){return await c(e.LOCAL_PROJECTS,r({localProjects:n??{},projectId:o,project:{id:o,name:E(i,l),createdAt:a,updatedAt:a}})),await c(e.PROJECT_ORDER,[o,...(s??[]).filter(e=>e!==o)]),await Promise.all(w(l).map(e=>t({legacyRoot:null,projectId:o,root:e}))),{isLocalProject:!0,projectId:o}}function _(t,n){let r=C(n);return t.query.setData(a,e.ACTIVE_REMOTE_PROJECT_ID,{value:void 0}),t.query.setData(d,{roots:[r.projectId]}),f(t,null),r.folderPath==null?s(t,e.ACTIVE_WORKSPACE_ROOTS,[r.projectId]):l.dispatchMessage(`electron-set-active-workspace-root`,{root:r.folderPath}),r.projectId}async function v({existingLocalProjects:t,name:n,now:i,project:a,setGlobalSetting:o,updateWorkspaceRootLabel:s}){let c=C(a),u=n.trim();if(c.folderPath!=null){l.dispatchMessage(`electron-rename-workspace-root-option`,{root:c.folderPath,label:u}),s?.(c.folderPath,u);return}let d=t?.[c.projectId];d!=null&&await o(e.LOCAL_PROJECTS,r({localProjects:t??{},projectId:c.projectId,project:{...d,name:u||d.name,updatedAt:i}}))}async function y({clearWritableRoots:t,existingLocalProjects:n,pinnedProjectIds:i,project:a,projectOrder:o,setGlobalSetting:s,workspaceRootOptions:c}){let u=C(a),d=u.metadataProjectId==null?[]:[s(e.LOCAL_PROJECTS,r({localProjects:n??{},projectId:u.metadataProjectId,project:null})),t({legacyRoot:null,projectId:u.metadataProjectId})];await Promise.all([...d,s(e.PROJECT_ORDER,o?.filter(e=>e!==u.projectId)),s(e.PINNED_PROJECT_IDS,i?.filter(e=>e!==u.projectId))]),u.folderPath!=null&&l.dispatchMessage(`electron-update-workspace-root-options`,{roots:c.filter(e=>e!==u.folderPath)})}function b(e){return C(e).projectId}function x(e){return C(e).folderPath}function S(e){return C(e).projectId}function C(e){let t=e.projectId;if(e.isLocalProject===!0)return{folderPath:null,metadataProjectId:t,projectId:t};let n=e.path??t;return{folderPath:n,metadataProjectId:null,projectId:n}}function w(e){let t=new Set,n=[];for(let r of e){let e=o(r);t.has(e)||(t.add(e),n.push(r))}return n}async function T({projectId:r,prompt:a,validateProjectId:o=!1}){let[{value:s},{value:c},l]=await Promise.all([u(`get-global-state`,{params:{key:e.LOCAL_PROJECTS}}),u(`get-global-state`,{params:{key:e.PROJECT_WRITABLE_ROOTS}}),o?u(`workspace-root-options`,{params:{hostId:i}}):Promise.resolve(null)]),d=t(s),f=Object.hasOwn(d,r);if(l!=null&&!l.roots.includes(r)&&!f)throw Error(`Unknown projectId: ${r}\nSaved projectIds:\n${l.roots.join(`
`)}`);let m=n(c);if(!Object.hasOwn(m,r)&&!f)return null;let h=await p({projectId:r,projectWritableRoots:m,legacyRoot:f?null:r,prompt:a});return{cwd:h.cwd,projectlessOutputDirectory:h.generatedWorkspace?.outputDirectory??null,workspaceRoots:h.workspaceRoots,projectAssignment:{projectKind:`local`,projectId:r,...f?{}:{path:r},cwd:h.cwd,pendingCoreUpdate:!1}}}function E(e,t){return e.trim()||c(t[0]??``).trim()||m}export{w as n,h as r,T as t};
//# sourceMappingURL=local-projects-8Dp63JZk.js.map