import{d as D,s as A,r as b,l as B}from"./jwt-decode.esm-BYfS37aG.js";import{a as E}from"./router-D53qV9Zg.js";import{M as L}from"./member-dJywfr1G.js";import{O as V}from"./organization-BI2IWMw4.js";import{P as k,a as I}from"./project-C7QI6pXl.js";import"./tables-nYEEmE6H.js";import{F as U,u as m}from"./cascaderStore-DVmoq__x.js";import{a as x}from"./ant-design-2HB1Oiwt.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]="b3703f52-1eef-42ae-9bec-4292dc60bf32",e._sentryDebugIdIdentifier="sentry-dbid-b3703f52-1eef-42ae-9bec-4292dc60bf32")}catch{}})();const K=D("projectsView",()=>{const e=A(null),c=b(""),f=b(new Map);let p=0,l=null;const n={member:new L,project:new k,folder:new U},h=async r=>{if(l?.orgId===r)return l.promise;l={orgId:r,promise:(async()=>{const a=E.getAuthor()?.claims.email;if(!a)throw new Error("User not authenticated");const i=++p,t=n.project.list(r),[u,M,v,F]=await Promise.all([t,V.get(r),n.member.list(r),n.folder.list(r)]);if(p!==i)return;const O=v.find(s=>s.email===a)??null,_=u.map(s=>I.fromDTO(s)),j=new Map;for(const s of u)s.lastBuild&&j.set(s.id,s.lastBuild);f.value=j,e.value={projects:_.sort((s,d)=>s.name.localeCompare(d.name)),organization:M,members:v,folders:F.sort((s,d)=>s.name.localeCompare(d.name)),currentMember:O},C(r)})()};try{await l.promise}finally{l?.orgId===r&&(l=null)}},w=r=>e.value?.projects.filter(o=>o.folderId===r&&(!c.value.trim()||o.name.toLowerCase().includes(c.value.toLowerCase())))??[],y=async(r,o)=>{if(!e.value)return;const a=e.value.projects.find(t=>t.id===r);if(!a||a.folderId===o)return;const i=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 n.project.update(r,{folderId:o});const t=e.value?.organization?.id;t&&m().invalidateCache("projects",t)}catch(t){e.value&&(e.value={...e.value,projects:i}),console.error("Failed to move project",t)}},P=async r=>{const o=e.value?.projects.find(t=>t.id===r);if(!o||!e.value||!await x(B.translate("i18n_projectsview_delete_project_confirm",null,o.name)))return!1;const i=e.value.projects;e.value={...e.value,projects:e.value.projects.filter(t=>t.id!==r)};try{await n.project.delete(r);const t=e.value?.organization?.id;return t&&m().invalidateCache("projects",t),!0}catch(t){return e.value&&(e.value={...e.value,projects:i}),console.error("Failed to delete project",t),!1}},g=r=>{e.value&&(e.value={...e.value,members:e.value.members.filter(o=>o.id!==r)})},S=(r,o)=>{e.value&&(e.value={...e.value,folders:e.value.folders.map(a=>a.id===r?{...a,name:o}:a)})},C=r=>{if(!e.value)return;const o=m();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,searchQuery:c,fetchState:h,getFolderProjects:w,moveProject:y,removeProjectOptimistic:P,removeMemberFromState:g,updateFolderNameInState:S,getProjectLastBuild:r=>f.value.get(r)??null}});export{K as u};
//# sourceMappingURL=projectsStore-CONhLlmu.js.map
