import{d as D,C as B,r as j,b as I,H as L}from"./jwt-decode.esm-BPi7UGps.js";import{a as V}from"./router-fx_h9Pdf.js";import{i as k,M as E}from"./member-DdtKaQMZ.js";import{O as R}from"./organization-DoURzs4y.js";import{a as x,P as H}from"./project-CgoqD6rU.js";import"./tables-D28I09yf.js";import{F as N,u as d}from"./cascaderStore-DdthiAZ-.js";import{a as Q}from"./ant-design-BHrjmV_f.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]="fbfa2558-2bf8-4752-87ea-be460e6435cf",e._sentryDebugIdIdentifier="sentry-dbid-fbfa2558-2bf8-4752-87ea-be460e6435cf")}catch{}})();const X=D("projectsView",()=>{const e=B(null),l=j(""),i=j(new Map);let p=0,n=null;const u={member:new E,project:new x,folder:new N},b=async r=>{if(n?.orgId===r)return n.promise;n={orgId:r,promise:(async()=>{if(!V.getAuthor()?.claims.email)throw new Error("User not authenticated");const a=++p,s=u.project.list(r),[t,f,F,O,_]=await Promise.all([s,R.get(r),u.member.list(r),u.folder.list(r),u.member.me(r).catch(()=>null)]);if(p!==a)return;const A=t.map(c=>H.fromDTO(c)),v=new Map;for(const c of t)c.lastBuild&&v.set(c.id,c.lastBuild);i.value=v,e.value={projects:A.sort((c,m)=>c.name.localeCompare(m.name)),organization:f,members:F,folders:O.sort((c,m)=>c.name.localeCompare(m.name)),currentMember:_},C(r)})()};try{await n.promise}finally{n?.orgId===r&&(n=null)}},h=r=>e.value?.projects.filter(o=>o.folderId===r&&(!l.value.trim()||o.name.toLowerCase().includes(l.value.toLowerCase())))??[],w=async(r,o)=>{if(!e.value)return;const a=e.value.projects.find(t=>t.id===r);if(!a||a.folderId===o)return;const s=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&&d().invalidateCache("projects",t)}catch(t){e.value&&(e.value={...e.value,projects:s}),console.error("Failed to move project",t)}},y=async r=>{const o=e.value?.projects.find(t=>t.id===r);if(!o||!e.value||!await Q(L.translate("i18n_projectsview_delete_project_confirm",null,o.name)))return!1;const s=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&&d().invalidateCache("projects",t),!0}catch(t){return e.value&&(e.value={...e.value,projects:s}),console.error("Failed to delete project",t),!1}},P=r=>{e.value&&(e.value={...e.value,members:e.value.members.filter(o=>o.id!==r)})},M=(r,o)=>{if(!e.value)return;const a=s=>s.authorId===r?{...s,role:o}:s;e.value={...e.value,members:e.value.members.map(a),currentMember:e.value.currentMember?a(e.value.currentMember):null}},g=I(()=>k(e.value?.currentMember??null)),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=d();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:l,fetchState:b,getFolderProjects:h,moveProject:w,removeProjectOptimistic:y,removeMemberFromState:P,updateMemberRoleInState:M,updateFolderNameInState:S,isAdmin:g,getProjectLastBuild:r=>i.value.get(r)??null}});export{X as u};
//# sourceMappingURL=projectsStore-BeACNtQ0.js.map
