import{d as L,E as V,r as m,b as M,K as k}from"./jwt-decode.esm-TBTnMpAQ.js";import{a as R,b as x}from"./router-D3FyrFLh.js";import{i as G,M as K}from"./member-DcSvDUMh.js";import{O as N}from"./organization-c9JpfAmx.js";import{a as Q,P as T}from"./project-C7rccdjE.js";import"./tables-BnZZliwP.js";import{F as U,u as p}from"./cascaderStore-07xe8M_8.js";import{a as $}from"./ant-design-CTCTsPCY.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},l=new Error().stack;l&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[l]="c1359932-715e-4afa-8ce9-cd37859bafc5",e._sentryDebugIdIdentifier="sentry-dbid-c1359932-715e-4afa-8ce9-cd37859bafc5")}catch{}})();const ee=L("projectsView",()=>{const e=V(null),l=m(""),d=m(new Map),v=m(new Map);let j=0,n=null;const u={member:new K,project:new Q,folder:new U},g=async r=>{if(n?.orgId===r)return n.promise;n={orgId:r,promise:(async()=>{if(!R.getAuthor()?.claims.email)throw new Error("User not authenticated");const s=++j,c=u.project.list(r);let t,i,h,b,w;try{[t,i,h,b,w]=await Promise.all([c,N.get(r),u.member.list(r),u.folder.list(r),u.member.me(r).catch(()=>null)])}catch(o){if(o instanceof x&&o.allowedMethods)return;throw o}if(j!==s)return;const I=t.map(o=>T.fromDTO(o)),y=new Map,P=new Map;for(const o of t)o.lastBuild&&y.set(o.id,o.lastBuild),P.set(o.id,o.isShutdown??!1);d.value=y,v.value=P,e.value={projects:I.sort((o,f)=>o.name.localeCompare(f.name)),organization:i,members:h,folders:b.sort((o,f)=>o.name.localeCompare(f.name)),currentMember:w},E(r)})()};try{await n.promise}finally{n?.orgId===r&&(n=null)}},S=r=>e.value?.projects.filter(a=>a.folderId===r&&(!l.value.trim()||a.name.toLowerCase().includes(l.value.toLowerCase())))??[],C=async(r,a)=>{if(!e.value)return;const s=e.value.projects.find(t=>t.id===r);if(!s||s.folderId===a)return;const c=e.value.projects;e.value={...e.value,projects:e.value.projects.map(t=>t.id===r?Object.assign(Object.create(Object.getPrototypeOf(t)),t,{folderId:a}):t)};try{await u.project.update(r,{folderId:a});const t=e.value?.organization?.id;t&&p().invalidateCache("projects",t)}catch(t){e.value&&(e.value={...e.value,projects:c}),console.error("Failed to move project",t)}},F=async r=>{const a=e.value?.projects.find(t=>t.id===r);if(!a||!e.value||!await $(k.translate("i18n_projectsview_delete_project_confirm",null,a.name)))return!1;const c=e.value.projects;e.value={...e.value,projects:e.value.projects.filter(t=>t.id!==r)};try{await u.project.delete(r);const t=e.value?.organization?.id;return t&&p().invalidateCache("projects",t),!0}catch(t){return e.value&&(e.value={...e.value,projects:c}),console.error("Failed to delete project",t),!1}},A=r=>{e.value&&(e.value={...e.value,members:e.value.members.filter(a=>a.id!==r)})},O=(r,a)=>{if(!e.value)return;const s=c=>c.authorId===r?{...c,role:a}:c;e.value={...e.value,members:e.value.members.map(s),currentMember:e.value.currentMember?s(e.value.currentMember):null}},_=M(()=>G(e.value?.currentMember??null)),D=M(()=>e.value?.organization.featureFlags??{}),B=(r,a)=>{e.value&&(e.value={...e.value,folders:e.value.folders.map(s=>s.id===r?{...s,name:a}:s)})},E=r=>{if(!e.value)return;const a=p();a.cache.folders[r]||(a.cache.folders[r]=e.value.folders),a.cache.projects[r]||(a.cache.projects[r]=e.value.projects)};return{fetchedState:e,searchQuery:l,fetchState:g,getFolderProjects:S,moveProject:C,removeProjectOptimistic:F,removeMemberFromState:A,updateMemberRoleInState:O,updateFolderNameInState:B,isAdmin:_,featureFlags:D,getProjectLastBuild:r=>d.value.get(r)??null,getProjectIsShutdown:r=>v.value.get(r)??!1}});export{ee as u};
//# sourceMappingURL=projectsStore-BmrGbwqP.js.map
