import{d as D,s as k,r as p,b as E,l as I}from"./jwt-decode.esm-CZajAnkk.js";import{a as L,C as V}from"./router-C8CCuUKN.js";import{i as R,M as x}from"./member-D3C_DPKf.js";import{O as G}from"./organization-CkvaBeNd.js";import{P as N,a as Q}from"./project-DTFW8XGL.js";import"./tables-BosOXgsx.js";import{F as T,u as v}from"./cascaderStore-BpKZSTEF.js";import{a as U}from"./ant-design-CiKENTgs.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},c=new Error().stack;c&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[c]="0982fa43-aaf2-47ef-a3d4-5f7618c67433",e._sentryDebugIdIdentifier="sentry-dbid-0982fa43-aaf2-47ef-a3d4-5f7618c67433")}catch{}})();const Z=D("projectsView",()=>{const e=k(null),c=p(null),i=p(""),j=p(new Map);let f=0,n=null;const u={member:new x,project:new N,folder:new T},P=async r=>{if(n?.orgId===r)return n.promise;n={orgId:r,promise:(async()=>{if(!L.getAuthor()?.claims.email)throw new Error("User not authenticated");c.value=null;const s=++f,l=u.project.list(r);let t,d,h,b,w;try{[t,d,h,b,w]=await Promise.all([l,G.get(r),u.member.list(r),u.folder.list(r),u.member.me(r).catch(()=>null)])}catch(a){if(a instanceof V&&a.allowedMethods){f===s&&(c.value={allowedMethods:a.allowedMethods},e.value=null);return}throw a}if(f!==s)return;const B=t.map(a=>Q.fromDTO(a)),y=new Map;for(const a of t)a.lastBuild&&y.set(a.id,a.lastBuild);j.value=y,e.value={projects:B.sort((a,m)=>a.name.localeCompare(m.name)),organization:d,members:h,folders:b.sort((a,m)=>a.name.localeCompare(m.name)),currentMember:w},_(r)})()};try{await n.promise}finally{n?.orgId===r&&(n=null)}},M=r=>e.value?.projects.filter(o=>o.folderId===r&&(!i.value.trim()||o.name.toLowerCase().includes(i.value.toLowerCase())))??[],g=async(r,o)=>{if(!e.value)return;const s=e.value.projects.find(t=>t.id===r);if(!s||s.folderId===o)return;const l=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:o}):t)};try{await u.project.update(r,{folderId:o});const t=e.value?.organization?.id;t&&v().invalidateCache("projects",t)}catch(t){e.value&&(e.value={...e.value,projects:l}),console.error("Failed to move project",t)}},S=async r=>{const o=e.value?.projects.find(t=>t.id===r);if(!o||!e.value||!await U(I.translate("i18n_projectsview_delete_project_confirm",null,o.name)))return!1;const l=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&&v().invalidateCache("projects",t),!0}catch(t){return e.value&&(e.value={...e.value,projects:l}),console.error("Failed to delete project",t),!1}},C=r=>{e.value&&(e.value={...e.value,members:e.value.members.filter(o=>o.id!==r)})},F=(r,o)=>{if(!e.value)return;const s=l=>l.authorId===r?{...l,role:o}:l;e.value={...e.value,members:e.value.members.map(s),currentMember:e.value.currentMember?s(e.value.currentMember):null}},A=E(()=>R(e.value?.currentMember??null)),O=(r,o)=>{e.value&&(e.value={...e.value,folders:e.value.folders.map(s=>s.id===r?{...s,name:o}:s)})},_=r=>{if(!e.value)return;const o=v();o.cache.folders[r]||(o.cache.folders[r]=e.value.folders),o.cache.projects[r]||(o.cache.projects[r]=e.value.projects)};return{fetchedState:e,loginBlocked:c,searchQuery:i,fetchState:P,getFolderProjects:M,moveProject:g,removeProjectOptimistic:S,removeMemberFromState:C,updateMemberRoleInState:F,updateFolderNameInState:O,isAdmin:A,getProjectLastBuild:r=>j.value.get(r)??null}});export{Z as u};
//# sourceMappingURL=projectsStore-BjPuofVb.js.map
