import{c as C,d as f,p as L,A as Q,g as y,t as U,e as w,f as O,r as i,h as V,i as z,k as H,m as J,s as K}from"./index-DTC0Ed21.js";import{g as N}from"./tasks-ClycqzjK.js";const Z=({projectId:a,sprintId:n,performerIds:o,search:c,flatList:s})=>{var S;const[p]=C(c,800),E=f(t=>t.devSlice.skeletons.tasks),h=f(t=>t.usersCache.currentUser.Id),u=f(t=>t.archiveSlice),{data:d}=L.useFetchProjectsQuery({States:y(u),ReturnDataType:Q.ProjectReturnDataType.Projects}),e=U((d==null?void 0:d.Projects)||[]),{attributeIds:P,attributes:T,isLoading:I}=w(),j=T.filter(t=>P.includes(t.Id)).map(t=>t.AttributeId),{data:k=[],error:B,isError:A,isSuccess:M,isLoading:D,isFetching:b,originalArgs:l,currentData:v,refetch:F}=O.useGetTasksQuery({projectIds:a?[a]:null,sprintId:n||null,performerIds:o,like:p==null?void 0:p.trim(),fields:j,states:y(u)},{skip:I}),r=i.useMemo(()=>V({tasks:k,archiveState:u,sprintEntities:e.sprintEntities,projectEntities:e.folderEntities,currentUserId:h}),[u,h,k,e.folderEntities,e.sprintEntities]),g=i.useMemo(()=>W(r),[r]),m=i.useMemo(()=>s?r.map(t=>({...t,flatList:s}))??[]:g,[r,s,g]),G=i.useMemo(()=>N(z(m,"Order"),"SprintId"),[m]),R=i.useMemo(()=>{const q=H(J(r,"SprintId")).map(x=>e.sprintEntities[x]).filter(Boolean);return K(q,["ProjectId","Id"])},[r,e.sprintEntities]);return{data:m,groupedBySprint:G,sprints:R,isSuccess:M,isLoading:I||D||!v||E,error:B,refetch:F,isError:A,isFetching:b,isSearching:!!((S=l==null?void 0:l.like)!=null&&S.length)}};function W(a){const n=new Map,o=[],c=a.map(s=>({...s,SubTasks:[]}));return c.forEach(s=>n.set(s.Id,s)),c.forEach(s=>{s.ParentId!==null&&n.has(s.ParentId)?n.get(s.ParentId).SubTasks.push(s):o.push(s)}),o}export{Z as u};
