import{aj as p,ak as P,N as E,al as $,v as D,am as U,af as k,an as ee,ao as re,ap as te,w as se,u as N,aq as ne,ar as q,r as y,as as oe,y as ie,at as ae}from"./index-n-59FgrC.js";import{g as de}from"./useTaskTypesData-CgG6u01U.js";const ce={[P.IPriority.Highest]:1,[P.IPriority.High]:2,[P.IPriority.Medium]:3,[P.IPriority.Low]:4,[P.IPriority.Lowest]:5},ue={[E.IStatusType.BeExecuted]:10,[E.IStatusType.Active]:20,[E.IStatusType.Done]:30,[E.IStatusType.Closed]:40},fe=(t,o)=>(ue[t]??Number.MAX_SAFE_INTEGER)*1e5+o,h=t=>p(t,"Order","asc"),Ie=(t,o,a,u,s,g,l)=>{if(!o||!a)return h(t);const f=a??"asc";switch(o){case"type":return u?p(t,[e=>{const r=u.find(d=>d.Id===e.TypeId);return(r==null?void 0:r.Order)??0},"Order"],[f,"asc"]):h(t);case"priority":return p(t,[e=>ce[e.Priority]??1/0,"Order"],[f,"asc"]);case"status":return g?p(t,[e=>{const r=g.find(d=>d.Id===e.Status);return r?fe(r.Type,r.Order):1/0},"Order"],[f,"asc"]):h(t);case"performer":return s?p(t,[e=>{let r=[];return e.Performers&&e.Performers.length>0?r=e.Performers:e.PerformerId!==null&&e.PerformerId!==void 0&&(r=[e.PerformerId]),r.length},e=>{if(!l)return!1;let r=[];return e.Performers&&e.Performers.length>0?r=e.Performers:e.PerformerId!==null&&e.PerformerId!==void 0&&(r=[e.PerformerId]),r.includes(l)},e=>{var I;let r=[];if(e.Performers&&e.Performers.length>0?r=e.Performers:e.PerformerId!==null&&e.PerformerId!==void 0&&(r=[e.PerformerId]),r.length===0)return"";const d=r.map(i=>s.find(c=>c.Id===i)).filter(i=>i!==void 0);return d.length===0?"":((I=p(d,[i=>l?i.Id===l:!1,"Name"],["desc","asc"])[0])==null?void 0:I.Name.toLowerCase())??""},"Order"],[f,"desc",f,"asc"]):h(t);default:return h(t)}},Pe=({projectId:t,sprintId:o,performerIds:a,search:u,flatList:s,typeIds:g,statusIds:l,priorities:f,authorIds:e})=>{var G;const[r]=$(u,800),d=D(n=>n.devSlice.skeletons.tasks),O=D(n=>n.usersCache.currentUser.Id),I=D(n=>n.archiveSlice),{data:i}=U(),c=k((i==null?void 0:i.Projects)||[]),{attributeIds:x,attributes:H,isLoading:F}=ee(),Q=H.filter(n=>x.includes(n.Id)).map(n=>n.AttributeId),{data:b=[],error:R,isError:_,isSuccess:K,isLoading:V,isFetching:w,originalArgs:v,currentData:X,refetch:z}=re.useGetTasksQuery({projectIds:t?[t]:null,sprintId:o||null,performerIds:a,like:r==null?void 0:r.trim(),fields:Q,states:te(),typeIds:g,statusIds:l,priorities:f,authorIds:e},{skip:F}),B=se(o),{project:A}=N(t),J=(B==null?void 0:B.rootProjectId)??(A==null?void 0:A.rootProjectId),{project:L}=N(J),W=L==null?void 0:L.Settings.EnabledFeatures.includes("Labels"),{data:S}=ne.useGetByTaskQuery(q(b,"Id"),{skip:!W||w}),m=y.useMemo(()=>oe({tasks:b.map(n=>{var T;return{...n,LabelIds:((T=S==null?void 0:S.find(j=>j.TaskId===n.Id))==null?void 0:T.LabelIds.map(String))||[]}}),archiveState:I,sprintEntities:c.sprintEntities,projectEntities:c.folderEntities,currentUserId:O}),[S,I,O,b,c.folderEntities,c.sprintEntities]),C=y.useMemo(()=>pe(m),[m]),M=y.useMemo(()=>s?m.map(n=>({...n,flatList:s}))??[]:C,[m,s,C]),Y=y.useMemo(()=>de(p(M,"Order"),"SprintId"),[M]),Z=y.useMemo(()=>{const T=ie(q(m,"SprintId")).map(j=>c.sprintEntities[j]).filter(Boolean);return ae(T,["ProjectId","Id"])},[m,c.sprintEntities]);return{data:M,groupedBySprint:Y,sprints:Z,isSuccess:K,isLoading:F||V||!X||d,error:R,refetch:z,isError:_,isFetching:w,isSearching:!!((G=v==null?void 0:v.like)!=null&&G.length)}};function pe(t){const o=new Map,a=[],u=t.map(s=>({...s,SubTasks:[]}));return u.forEach(s=>o.set(s.Id,s)),u.forEach(s=>{s.ParentId!==null&&o.has(s.ParentId)?o.get(s.ParentId).SubTasks.push(s):a.push(s)}),a}export{ce as p,Ie as s,Pe as u};
