import{r as o,t as v,d as y,C as S,c as h,ag as O,ah as B,M as D,j as s,p as T,a3 as k,n as H,a2 as L}from"./index-B-YXshIJ.js";import{u as Q}from"./useGraphArgs-DTUG6avZ.js";import{S as z}from"./ScatterLineGraph-BapPE0y_.js";import{a as F}from"./query-hooks-C0Pc4MKj.js";import{C as J}from"./check-DaW7r622.js";import"./Filters-DsROmhj9.js";import"./MultiSelectDropdown-B42s6W_W.js";import"./react-select.esm-OagQDocY.js";import"./extends-vRGLuScH.js";import"./index-Brfj1MB8.js";const _=({type:M,workItemConfig:p,lineColor:w})=>{var f,b,j,N;const C=Q(),[n,u]=o.useState([]),[x,I]=o.useState(),{collectionName:G}=F(),l=v.workItems.getWorkItemTimeSpent.useQuery({type:M,...C,workItemType:p.name[0]}),c=v.workItems.getWorkItemTooltip.useQuery({collectionName:G,id:x},{enabled:!!x}),d=o.useMemo(()=>{var e;return(e=l.data)==null?void 0:e.map(t=>({...t,timeSpent:t.stateChanges.reduce((a,r,i)=>(i===0||a.push({state:t.stateChanges[i-1].state,time:r.date.getTime()-t.stateChanges[i-1].date.getTime()}),a),[])}))},[l.data]),g=o.useMemo(()=>{const e=d==null?void 0:d.reduce((t,a)=>(a.timeSpent.forEach(r=>{const i=t.get(r.state)||{time:0,count:0};t.set(r.state,{time:i.time+r.time,count:i.count+1})}),t),new Map);return e&&[...e.entries()].map(([t,a])=>({state:t,...a}))},[d]),E=o.useMemo(()=>{var e,t;return y(S(((e=l.data)==null?void 0:e.map(h("cycleTime")))||[]),((t=l.data)==null?void 0:t.length)||0)},[l.data]),m=o.useMemo(()=>{var t;const e=(t=l.data)==null?void 0:t.reduce((a,r)=>{const i=a.get(r.groupName)||{time:0,count:0};return a.set(r.groupName,{time:i.time+r.cycleTime,count:i.count+1}),a},new Map);return e&&[...e.entries()].map(([a,r])=>({groupName:a,...r}))},[l.data]);o.useEffect(()=>{u((m==null?void 0:m.map(h("groupName")))||[])},[m]);const P=o.useCallback(e=>{n.includes(e)?u(O(t=>t!==e)):u(B(e))},[n]),A=o.useMemo(()=>Object.fromEntries((g||[]).map(e=>[e.state,(d||[]).filter(t=>n.includes(t.groupName)).map(t=>({...t,stateTime:S(t.timeSpent.filter(a=>a.state===e.state).map(h("time")))}))]).filter(D)),[n,g,d]);return s.jsxs("div",{className:"p-6 grid grid-flow-row gap-4",children:[s.jsx("div",{children:s.jsxs("div",{className:"text-lg font-bold",children:[E.map(T).getOr("-")," ",s.jsxs("span",{className:"text-base font-normal text-theme-helptext inline-block pl-1",children:[(f=l.data)==null?void 0:f.length," items"]})]})}),s.jsx("div",{children:s.jsx("ul",{className:"grid grid-cols-4 gap-2 items-stretch",children:m==null?void 0:m.map(e=>s.jsx("li",{children:s.jsxs("button",{onClick:()=>P(e.groupName),className:k("flex flex-col w-full h-full","border border-l-2 border-theme-seperator rounded-lg p-2","text-sm text-left transition-all duration-200 group",n.includes(e.groupName)?"bg-theme-page-content":"bg-theme-col-header"),style:{borderLeftColor:w(e.groupName),boxShadow:n.includes(e.groupName)?"rgba(30, 41, 59, 0.05) 0px 4px 3px":void 0},children:[s.jsxs("div",{className:"grid grid-flow-col justify-between w-full",children:[s.jsx("div",{children:e.groupName||"Unclassified"}),s.jsx("div",{children:s.jsx(J,{size:20,className:k("text-theme-highlight transition-opacity",!n.includes(e.groupName)&&"opacity-0")})})]}),s.jsxs("div",{className:"font-medium flex items-end",children:[s.jsx("span",{children:y(e.time,e.count).map(T).getOr("-")}),s.jsxs("span",{className:"inline-block text-theme-helptext ml-2",children:["(",H(e.count),")"]})]})]})},e.groupName))})}),s.jsxs("div",{className:"overflow-x-auto mt-6",children:[s.jsx(z,{graphData:[{label:p.name[1],data:A,yAxisPoint:e=>e.stateTime,tooltip:e=>String(e.id)}],height:400,linkForItem:e=>e.url,pointTooltipId:"bubble-graph-tooltip",onPointHover:e=>I(e.id)}),s.jsx(L,{id:"bubble-graph-tooltip",children:s.jsxs("div",{className:"w-96",children:[s.jsxs("div",{className:"font-medium mb-2",children:[s.jsx("img",{src:p.icon,className:"w-4 h-4 mr-2 inline-block",alt:"Icon for ".concat(p.name[1])}),(b=c.data)==null?void 0:b.title]}),s.jsxs("div",{children:["Priority:"," ",c.data?(j=c.data.priority)!=null?j:"No priority":"..."]}),((N=c.data)==null?void 0:N.severity)&&s.jsxs("div",{children:["Severity: ",c.data.severity]})]})})]})]})};export{_ as default};
