import{d as k,A as E,r as f,b as L,J as V}from"./jwt-decode.esm-rEBc1yJt.js";import{a as R,b as x}from"./router-BaFu-do7.js";import{i as G,M as J}from"./member-qsE1qwIO.js";import{O as N}from"./organization-DI9u_TkV.js";import{a as Q,P as T}from"./project-D1d7g0j_.js";import"./tables-DdYqLMX_.js";import{F as U,u as v}from"./cascaderStore-Dimdeu3o.js";import{a as $}from"./ant-design-oMJ_KisO.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]="eb8a6165-b7dd-4898-bcb5-499adf90777a",e._sentryDebugIdIdentifier="sentry-dbid-eb8a6165-b7dd-4898-bcb5-499adf90777a")}catch{}})();const ee=k("projectsView",()=>{const e=E(null),c=f(null),i=f(""),j=f(new Map),b=f(new Map);let m=0,n=null;const u={member:new J,project:new Q,folder:new U},g=async t=>{if(n?.orgId===t)return n.promise;n={orgId:t,promise:(async()=>{if(!R.getAuthor()?.claims.email)throw new Error("User not authenticated");c.value=null;const s=++m,l=u.project.list(t);let r,d,h,w,y;try{[r,d,h,w,y]=await Promise.all([l,N.get(t),u.member.list(t),u.folder.list(t),u.member.me(t).catch(()=>null)])}catch(a){if(a instanceof x&&a.allowedMethods){m===s&&(c.value={allowedMethods:a.allowedMethods},e.value=null);return}throw a}if(m!==s)return;const I=r.map(a=>T.fromDTO(a)),M=new Map,P=new Map;for(const a of r)a.lastBuild&&M.set(a.id,a.lastBuild),P.set(a.id,a.isShutdown??!1);j.value=M,b.value=P,e.value={projects:I.sort((a,p)=>a.name.localeCompare(p.name)),organization:d,members:h,folders:w.sort((a,p)=>a.name.localeCompare(p.name)),currentMember:y},D(t)})()};try{await n.promise}finally{n?.orgId===t&&(n=null)}},S=t=>e.value?.projects.filter(o=>o.folderId===t&&(!i.value.trim()||o.name.toLowerCase().includes(i.value.toLowerCase())))??[],C=async(t,o)=>{if(!e.value)return;const s=e.value.projects.find(r=>r.id===t);if(!s||s.folderId===o)return;const l=e.value.projects;e.value={...e.value,projects:e.value.projects.map(r=>r.id===t?Object.assign(Object.create(Object.getPrototypeOf(r)),r,{folderId:o}):r)};try{await u.project.update(t,{folderId:o});const r=e.value?.organization?.id;r&&v().invalidateCache("projects",r)}catch(r){e.value&&(e.value={...e.value,projects:l}),console.error("Failed to move project",r)}},A=async t=>{const o=e.value?.projects.find(r=>r.id===t);if(!o||!e.value||!await $(V.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(r=>r.id!==t)};try{await u.project.delete(t);const r=e.value?.organization?.id;return r&&v().invalidateCache("projects",r),!0}catch(r){return e.value&&(e.value={...e.value,projects:l}),console.error("Failed to delete project",r),!1}},F=t=>{e.value&&(e.value={...e.value,members:e.value.members.filter(o=>o.id!==t)})},O=(t,o)=>{if(!e.value)return;const s=l=>l.authorId===t?{...l,role:o}:l;e.value={...e.value,members:e.value.members.map(s),currentMember:e.value.currentMember?s(e.value.currentMember):null}},_=L(()=>G(e.value?.currentMember??null)),B=(t,o)=>{e.value&&(e.value={...e.value,folders:e.value.folders.map(s=>s.id===t?{...s,name:o}:s)})},D=t=>{if(!e.value)return;const o=v();o.cache.folders[t]||(o.cache.folders[t]=e.value.folders),o.cache.projects[t]||(o.cache.projects[t]=e.value.projects)};return{fetchedState:e,loginBlocked:c,searchQuery:i,fetchState:g,getFolderProjects:S,moveProject:C,removeProjectOptimistic:A,removeMemberFromState:F,updateMemberRoleInState:O,updateFolderNameInState:B,isAdmin:_,getProjectLastBuild:t=>j.value.get(t)??null,getProjectIsShutdown:t=>b.value.get(t)??!1}});export{ee as u};
//# sourceMappingURL=projectsStore-CB4dfD6J.js.map
