const U=new Set(["Passed","Failed"]);function K(e){const t=new Map,a=new Map;for(const s of e){const n=h(s);if(!n)continue;const r=a.get(n);r?r.push(s):a.set(n,[s])}for(const s of a.values()){const n=[...s].sort(E);for(let r=0;r<n.length;r+=1){const c=n[r],o=T(c,n);o&&t.set(c.id,o)}}return t}function T(e,t){const a=t.filter(o=>o.id!==e.id).filter(o=>h(o)===h(e)).filter(o=>B(o,e)).filter(o=>U.has(o.status)).sort(E);if(a.length===0)return null;const s=l(e.workflowProfileId),n=l(e.environmentName),r=l(e.branchName),c=a.find(o=>u(s,l(o.workflowProfileId))&&u(n,l(o.environmentName))&&(!r||u(r,l(o.branchName))));if(c)return d(e,c,r?"same-branch":s?"same-profile":n?"same-environment":"same-check-type");if(s){const o=a.find(f=>u(s,l(f.workflowProfileId))&&u(n,l(f.environmentName)));if(o)return d(e,o,"same-profile")}if(n){const o=a.find(f=>u(n,l(f.environmentName)));if(o)return d(e,o,"same-environment")}return d(e,a[0],"same-check-type")}function L(e){switch(e){case"same-branch":return"previous same branch";case"same-profile":return"previous same profile";case"same-environment":return"previous same environment";default:return"previous same check type"}}function _(e){const t=[];e.statusChanged&&t.push(`status ${e.baseline.status} -> ${e.baseline.status==="Passed"&&e.hasRegression?"Failed":e.baseline.status==="Failed"&&e.hasImprovement?"Passed":"changed"}`);const a=x(e.testDelta.failed,"failed");a&&t.push(a);const s=A(e.coverageDelta.linesPct,"lines");s&&t.push(s);const n=z(e.durationDeltaMs);n&&t.push(`duration ${n}`);const r=x(e.artifactCountDelta,"artifacts");return r&&t.push(r),t.length>0?t.join(" | "):"No material change"}function x(e,t){return e==null||e===0?null:`${e>0?"+":""}${e} ${t}`}function A(e,t){if(e==null||Math.abs(e)<.01)return null;const a=`${e>0?"+":""}${e.toFixed(Math.abs(e)%1<.01?0:2)}%`;return t?`${t} ${a}`:a}function z(e){if(e==null||Math.abs(e)<1)return null;const t=Math.abs(e),a=t<1e3?`${Math.round(t)} ms`:t>=6e4?`${(t/6e4).toFixed(t%6e4===0?0:2)} min`:`${(t/1e3).toFixed(t%1e3===0?0:2)} s`;return`${e>0?"+":"-"}${a}`}function d(e,t,a){var f,g,S,v,y,D,C,P,$,k,M,N,w,I,F,b;const s=i((f=e.testSummary)==null?void 0:f.failed,(g=t.testSummary)==null?void 0:g.failed),n=i(m((S=e.coverageSummary)==null?void 0:S.lines),m((v=t.coverageSummary)==null?void 0:v.lines)),r=i(m((y=e.coverageSummary)==null?void 0:y.statements),m((D=t.coverageSummary)==null?void 0:D.statements)),c=t.status==="Passed"&&e.status==="Failed"||s!=null&&s>0||n!=null&&n<0||r!=null&&r<0,o=t.status==="Failed"&&e.status==="Passed"||s!=null&&s<0||n!=null&&n>0||r!=null&&r>0;return{baseline:t,scope:a,statusChanged:e.status!==t.status,hasRegression:c,hasImprovement:o,durationDeltaMs:i(e.durationMs,t.durationMs),artifactCountDelta:e.artifacts.length-t.artifacts.length,testDelta:{passed:i((C=e.testSummary)==null?void 0:C.passed,(P=t.testSummary)==null?void 0:P.passed),failed:s,skipped:i(($=e.testSummary)==null?void 0:$.skipped,(k=t.testSummary)==null?void 0:k.skipped),total:i((M=e.testSummary)==null?void 0:M.total,(N=t.testSummary)==null?void 0:N.total)},coverageDelta:{linesPct:n,branchesPct:i(m((w=e.coverageSummary)==null?void 0:w.branches),m((I=t.coverageSummary)==null?void 0:I.branches)),functionsPct:i(m((F=e.coverageSummary)==null?void 0:F.functions),m((b=t.coverageSummary)==null?void 0:b.functions)),statementsPct:r}}}function m(e){return(e==null?void 0:e.percentage)??null}function i(e,t){return e==null||t==null?null:Math.round((e-t)*100)/100}function h(e){return e.vesselId?`${e.vesselId}::${e.type}`:null}function E(e,t){const a=p(t.createdUtc)-p(e.createdUtc);return a!==0?a:t.id.localeCompare(e.id)}function B(e,t){const a=p(e.createdUtc),s=p(t.createdUtc);return a!==s?a<s:e.id.localeCompare(t.id)<0}function p(e){const t=Date.parse(e||"");return Number.isFinite(t)?t:0}function l(e){return(e||"").trim()}function u(e,t){return e===t}export{_ as a,K as b,z as c,x as d,A as e,L as f,T as g};
