import{ae as h,D as C,r as w,ab as y}from"./index-B-YXshIJ.js";import{c as D,t as W,w as T,a as $,b as S,d as O}from"./work-item-utils-BC5ckKim.js";const p="Not classified",j=(()=>{const n=y(["#9A6324","#e6194B","#3cb44b","#ffe119","#000075","#f58231","#911eb4","#42d4f4","#bfef45","#fabed4","#a9a9a9"]);return({witId:t,groupName:e})=>n(t+e)})(),P=(n,t)=>{const e=new Date(n);return e.setDate(e.getDate()-t),e.setHours(0,0,0,0),e},v=n=>t=>t.start?n.workCenters.reduce((e,l,o)=>{const r=t.workCenters.find(a=>a.label===l.label);return r&&(e.push({label:"Waiting for ".concat(l.label),start:o===0?new Date(t.start):C(e).end,end:new Date(r.start),isWorkCenter:!1},{label:"In ".concat(l.label),start:new Date(r.start),end:r.end?new Date(r.end):void 0,isWorkCenter:!0}),o===n.workCenters.length-1&&r.end&&e.push({label:"After ".concat(l.label),start:new Date(r.end),end:t.end?new Date(t.end):void 0,isWorkCenter:!1})),e},[]).slice(1):[],A=(n,t)=>{const{overview:e,lastUpdated:l,ignoreForWIP:o,environments:r}=n,a=s=>e.times[s.id],d=s=>e.groups[s],f=s=>e.types[s],u=s=>f(s).name[0].toLowerCase().includes("bug"),m=P(l,t),g=O(a,o);return{queryPeriodDays:t,allWorkItems:Object.values(e.byId),lastUpdated:new Date(l),ignoreForWIP:o,workItemType:f,workItemTimes:a,workItemGroup:d,cycleTime:D(a),isBug:u,totalCycleTime:W(a),workCenterTime:T(a),totalWorkCenterTime:$(a),isWIPInTimeRange:g,isWIP:g(h),timeSpent:s=>v(f(s.typeId))(a(s)),environments:r,sortByEnvironment:(s=>{const i=s==null?void 0:s.map(b=>b.toLowerCase());return(b,c)=>i?i.indexOf(b.toLowerCase())-i.indexOf(c.toLowerCase()):0})(r),isWorkItemClosed:s=>{const i=a(s);return!i.end||!i.start?!1:new Date(i.end)>m},wasWorkItemOpenedInLastThreeMonths:S(f,a)(s=>s>m),organizeByWorkItemType:(s,i)=>s.reduce((b,c)=>{b[c.typeId]=b[c.typeId]||{};const I=c.groupId?d(c.groupId):null,k=I?I.name:p;return b[c.typeId][k]=b[c.typeId][k]||[],i(c)&&b[c.typeId][k].push(c),b},{}),groupLabel:({witId:s,groupName:i})=>f(s).name[1]+(i===p?"":" - ".concat(i)),workItemRelations:s=>{var i;return((i=e.relations)==null?void 0:i[s.id])||[]}}},E=(n,t,e,l)=>Object.entries(n).map(([o,r])=>({label:t(o).name[1],value:e(Object.values(r).flat(),o),unit:l})),R=(n,{workItemType:t,sortByEnvironment:e},l,o,r=j)=>Object.entries(n).reduce((a,[d,f])=>(Object.entries(f).sort(([u],[m])=>e(u,m)).forEach(([u,m])=>{const g=t(d),s=u===p?g.name[1]:u;a.push({label:s,value:l(m,d,u),iconUrl:g.icon,key:d+u,color:r({witId:d,groupName:u}),isChecked:o==null?void 0:o(d+u)})}),a),[]),U=n=>{const[t,e]=w.useState(Object.entries(n).reduce((r,[a,d])=>(Object.keys(d).forEach(f=>{r[a+f]=!0}),r),{}));return[r=>{e(a=>({...a,[r]:!a[r]}))},r=>t[r]]},F=(n,t)=>{const[e,l]=Object.entries(t).find(([a])=>n.startsWith(a)),[o,r]=Object.entries(l).find(([a])=>n===e+a);return[e,o,r]},x=(n,t="and")=>{if(n.length===0)return"";if(n.length===1)return n[0];const e=[...n],l=e.pop();return"".concat("".concat(e.join(", ")," ").concat(t)," ").concat(l)},G=n=>n.length===1?"'".concat(n[0],"'"):"".concat(x(n.map(t=>"'".concat(t,"'")),"or"),", whichever is earlier"),H=({workItemTimes:n},t)=>e=>{const l=n(e);if(l.end)return{state:"Done",since:new Date(l.end)};const o=C(l.workCenters);if(!o)return{state:"Before ".concat(t.workCenters.length?t.workCenters[0].label:"start"),since:new Date(l.start||e.created.on)};if(o.end){const r=t.workCenters.findIndex(a=>a.label===o.label);return r===t.workCenters.length-1?{state:"After ".concat(o.label),since:new Date(o.end)}:{state:"Waiting for ".concat(t.workCenters[r+1].label),since:new Date(o.end)}}return{state:"In ".concat(o.label),since:new Date(o.start)}};export{E as a,F as b,x as c,A as d,R as g,j as l,p as n,G as s,v as t,U as u,H as w};
