import{d as F,s as I,r as j,l as D}from"./jwt-decode.esm-CuqABuF0.js";import{a as A}from"./router-C-Pd0gHD.js";import{M as B}from"./member-CO0IVq7z.js";import{O}from"./organization-CFugdneJ.js";import{P as E,a as L}from"./project-D3XwUmzI.js";import"./tables-BHu5fUrG.js";import{F as V}from"./folder-Bovb-6rt.js";import{a as k}from"./ant-design-BW5BPqF1.js";import{u as f}from"./cascaderStore-CChdaozc.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]="0e060689-75e3-4c90-a147-4c373eda1a30",e._sentryDebugIdIdentifier="sentry-dbid-0e060689-75e3-4c90-a147-4c373eda1a30")}catch{}})();const J=F("projectsView",()=>{const e=I(null),c=j(""),i=j(new Map);let m=0;const l={member:new B,project:new E,folder:new V},w=async r=>{const t=A.getAuthor()?.claims.email;if(!t)throw new Error("User not authenticated");const a=++m,n=l.project.list(r),[o,d,p,C]=await Promise.all([n,O.get(r),l.member.list(r),l.folder.list(r)]);if(m!==a)return;const M=p.find(s=>s.email===t)??null,_=o.map(s=>L.fromDTO(s)),v=new Map;for(const s of o)s.lastBuild&&v.set(s.id,s.lastBuild);i.value=v,e.value={projects:_.sort((s,u)=>s.name.localeCompare(u.name)),organization:d,members:p,folders:C.sort((s,u)=>s.name.localeCompare(u.name)),currentMember:M},g(r)},h=r=>e.value?.projects.filter(t=>t.folderId===r&&(!c.value.trim()||t.name.toLowerCase().includes(c.value.toLowerCase())))??[],P=async(r,t)=>{const a=e.value?.projects.find(o=>o.id===r);if(!a||a.folderId===t)return;const n=a.folderId;a.folderId=t;try{await l.project.update(r,{folderId:t});const o=e.value?.organization?.id;o&&f().invalidateCache("projects",o)}catch(o){a.folderId=n,console.error("Failed to move project",o)}},b=async r=>{const t=e.value?.projects.find(o=>o.id===r);if(!t||!e.value||!await k(D.translate("i18n_projectsview_delete_project_confirm",null,t.name)))return!1;const n=[...e.value.projects];e.value.projects=e.value.projects.filter(o=>o.id!==r);try{await l.project.delete(r);const o=e.value?.organization?.id;return o&&f().invalidateCache("projects",o),!0}catch(o){return e.value&&(e.value.projects=n),console.error("Failed to delete project",o),!1}},y=r=>{e.value&&(e.value={...e.value,members:e.value.members.filter(t=>t.id!==r)})},S=(r,t)=>{e.value&&(e.value={...e.value,folders:e.value.folders.map(a=>a.id===r?{...a,name:t}:a)})},g=r=>{if(!e.value)return;const t=f();t.cache.folders[r]||(t.cache.folders[r]=e.value.folders),t.cache.projects[r]||(t.cache.projects[r]=e.value.projects)};return{fetchedState:e,searchQuery:c,fetchState:w,getFolderProjects:h,moveProject:P,removeProjectOptimistic:b,removeMemberFromState:y,updateFolderNameInState:S,getProjectLastBuild:r=>i.value.get(r)??null}});export{J as u};
//# sourceMappingURL=projectsStore-H8ncVaPA.js.map
