import{o as e}from"./rolldown-runtime-BM3Ffeng.js";import{t}from"./ban-BTTjgmmA.js";import{t as n}from"./chart-column-C5WJPc57.js";import{n as r,t as i}from"./panel-right-open-BQRAJa1o.js";import{t as a}from"./square-Qg9lso1a.js";import{A as o,A_ as s,B as c,C as l,Cd as u,Cf as d,D as f,D_ as p,E as m,E_ as h,F as g,Fc as _,Ff as v,Fg as y,Fy as b,Gy as x,H as S,Hy as C,I as w,Jd as T,Jf as E,Kd as D,L as ee,Lc as te,Ly as O,M as ne,Mg as re,N as ie,Nd as k,Nf as A,O as ae,O_ as oe,Od as j,Of as M,P as se,Pf as N,Pp as ce,Ql as P,Rc as le,T as F,T_ as I,Tc as L,Ua as ue,Xd as de,Xp as R,Yd as fe,Zv as z,_f as pe,a as me,am as he,ap as ge,b as _e,dg as B,dh as ve,dr as V,dv as ye,et as be,fr as xe,hv as H,i as Se,i_ as Ce,j as we,jf as Te,jg as Ee,k as De,k_ as Oe,kl as ke,kp as Ae,lh as U,lo as je,m_ as W,mr as Me,mv as G,n as Ne,n_ as Pe,nh as Fe,np as Ie,of as Le,ph as K,pr as q,pv as Re,r_ as ze,rf as Be,rv as Ve,sn as He,uv as Ue,w as We,wh as Ge,x as Ke,yf as qe,z as Je}from"./index-DDwwBb9e.js";import{t as Ye}from"./WithPermissionGuard-wX0IC3VF.js";import{n as Xe,r as Ze,t as Qe}from"./PassRateIndicator-DFvX4_Bz.js";var $e=E(`crosshair`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`22`,x2:`18`,y1:`12`,y2:`12`,key:`l9bcsi`}],[`line`,{x1:`6`,x2:`2`,y1:`12`,y2:`12`,key:`13hhkx`}],[`line`,{x1:`12`,x2:`12`,y1:`6`,y2:`2`,key:`10w3f3`}],[`line`,{x1:`12`,x2:`12`,y1:`22`,y2:`18`,key:`15g9kq`}]]),et=E(`layout-grid`,[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]),tt=E(`loader`,[[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m16.2 7.8 2.9-2.9`,key:`r700ao`}],[`path`,{d:`M18 12h4`,key:`wj9ykh`}],[`path`,{d:`m16.2 16.2 2.9 2.9`,key:`1bxg5t`}],[`path`,{d:`M12 18v4`,key:`jadmvz`}],[`path`,{d:`m4.9 19.1 2.9-2.9`,key:`bwix9q`}],[`path`,{d:`M2 12h4`,key:`j09sii`}],[`path`,{d:`m4.9 4.9 2.9 2.9`,key:`giyufr`}]]),nt=E(`repeat-2`,[[`path`,{d:`m2 9 3-3 3 3`,key:`1ltn5i`}],[`path`,{d:`M13 18H7a2 2 0 0 1-2-2V6`,key:`1r6tfw`}],[`path`,{d:`m22 15-3 3-3-3`,key:`4rnwn2`}],[`path`,{d:`M11 6h6a2 2 0 0 1 2 2v10`,key:`2f72bc`}]]),J=e(x()),Y=C(),rt={none:`None`,scenario:`Scenario`,target:`Target`};function it({scenarioOptions:e,filters:t,onFiltersChange:n,groupBy:r,onGroupByChange:i,groupByOptions:a=[...l],viewMode:o,onViewModeChange:s}){return(0,Y.jsxs)(W,{gap:3,flexWrap:`wrap`,justifyContent:`space-between`,children:[(0,Y.jsxs)(W,{gap:3,flexWrap:`wrap`,children:[(0,Y.jsxs)(Ce,{size:`sm`,width:`auto`,minWidth:`150px`,children:[(0,Y.jsxs)(Pe,{value:t.scenarioId,onChange:e=>n({...t,scenarioId:e.target.value}),"aria-label":`Filter by scenario`,children:[(0,Y.jsx)(`option`,{value:``,children:`All Scenarios`}),e.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Y.jsx)(ze,{})]}),(0,Y.jsxs)(Ce,{size:`sm`,width:`auto`,minWidth:`120px`,children:[(0,Y.jsxs)(Pe,{value:t.passFailStatus,onChange:e=>n({...t,passFailStatus:e.target.value}),"aria-label":`Filter by pass/fail status`,children:[(0,Y.jsx)(`option`,{value:``,children:`All Statuses`}),(0,Y.jsx)(`option`,{value:`pass`,children:`Pass`}),(0,Y.jsx)(`option`,{value:`fail`,children:`Fail`}),(0,Y.jsx)(`option`,{value:`stalled`,children:`Stalled`})]}),(0,Y.jsx)(ze,{})]})]}),(0,Y.jsxs)(W,{gap:3,children:[s&&(0,Y.jsxs)(W,{gap:1,role:`group`,"aria-label":`View mode`,children:[(0,Y.jsx)(Ve,{"aria-label":`List view`,"aria-pressed":o===`list`,size:`xs`,variant:o===`list`?`solid`:`ghost`,onClick:()=>s(`list`),children:(0,Y.jsx)(Be,{size:14})}),(0,Y.jsx)(Ve,{"aria-label":`Grid view`,"aria-pressed":o===`grid`,size:`xs`,variant:o===`grid`?`solid`:`ghost`,onClick:()=>s(`grid`),children:(0,Y.jsx)(et,{size:14})})]}),i&&(0,Y.jsxs)(W,{gap:2,children:[(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,whiteSpace:`nowrap`,children:`Group by:`}),(0,Y.jsxs)(Ce,{size:`sm`,width:`auto`,minWidth:`120px`,children:[(0,Y.jsx)(Pe,{value:r??`none`,onChange:e=>i(e.target.value),"aria-label":`Group by`,children:a.map(e=>(0,Y.jsx)(`option`,{value:e,children:rt[e]},e))}),(0,Y.jsx)(ze,{})]})]})]})]})}var at=(0,J.createContext)(Date.now());function ot(){return(0,J.useContext)(at)}var st={pass:`
    radial-gradient(ellipse at 0% 100%, rgba(134, 239, 172, 0.55) 0%, transparent 50%),
    radial-gradient(ellipse at 100% 50%, rgba(72, 187, 120, 0.5) 0%, transparent 45%),
    radial-gradient(ellipse at 70% 0%, rgba(56, 161, 105, 0.55) 0%, transparent 50%),
    linear-gradient(160deg, rgba(56, 161, 105, 0.58) 0%, rgba(104, 211, 145, 0.52) 100%)
  `,cancelled:`
    radial-gradient(ellipse at 0% 100%, rgba(226, 232, 240, 0.55) 0%, transparent 50%),
    radial-gradient(ellipse at 100% 50%, rgba(160, 174, 192, 0.5) 0%, transparent 45%),
    radial-gradient(ellipse at 70% 0%, rgba(113, 128, 150, 0.55) 0%, transparent 50%),
    linear-gradient(160deg, rgba(113, 128, 150, 0.58) 0%, rgba(160, 174, 192, 0.52) 100%)
  `,fail:`
    radial-gradient(ellipse at 0% 100%, rgba(254, 178, 178, 0.55) 0%, transparent 50%),
    radial-gradient(ellipse at 100% 50%, rgba(245, 101, 101, 0.5) 0%, transparent 45%),
    radial-gradient(ellipse at 70% 0%, rgba(229, 62, 62, 0.55) 0%, transparent 50%),
    linear-gradient(160deg, rgba(229, 62, 62, 0.58) 0%, rgba(252, 129, 129, 0.52) 100%)
  `,stalled:`
    radial-gradient(ellipse at 0% 100%, rgba(251, 211, 141, 0.55) 0%, transparent 50%),
    radial-gradient(ellipse at 100% 50%, rgba(236, 201, 75, 0.5) 0%, transparent 45%),
    radial-gradient(ellipse at 70% 0%, rgba(214, 158, 46, 0.55) 0%, transparent 50%),
    linear-gradient(160deg, rgba(214, 158, 46, 0.58) 0%, rgba(236, 201, 75, 0.52) 100%)
  `},ct={pass:`
    radial-gradient(ellipse at 0% 100%, rgba(74, 222, 128, 0.55) 0%, transparent 55%),
    radial-gradient(ellipse at 100% 50%, rgba(34, 197, 94, 0.42) 0%, transparent 50%),
    linear-gradient(160deg, rgba(22, 163, 74, 0.48) 0%, rgba(74, 222, 128, 0.32) 100%)
  `,cancelled:`
    radial-gradient(ellipse at 0% 100%, rgba(161, 161, 170, 0.4) 0%, transparent 55%),
    radial-gradient(ellipse at 100% 50%, rgba(113, 113, 122, 0.3) 0%, transparent 50%),
    linear-gradient(160deg, rgba(82, 82, 91, 0.38) 0%, rgba(161, 161, 170, 0.28) 100%)
  `,fail:`
    radial-gradient(ellipse at 0% 100%, rgba(248, 113, 113, 0.55) 0%, transparent 55%),
    radial-gradient(ellipse at 100% 50%, rgba(239, 68, 68, 0.42) 0%, transparent 50%),
    linear-gradient(160deg, rgba(220, 38, 38, 0.48) 0%, rgba(248, 113, 113, 0.32) 100%)
  `,stalled:`
    radial-gradient(ellipse at 0% 100%, rgba(251, 191, 36, 0.55) 0%, transparent 55%),
    radial-gradient(ellipse at 100% 50%, rgba(245, 158, 11, 0.42) 0%, transparent 50%),
    linear-gradient(160deg, rgba(217, 119, 6, 0.48) 0%, rgba(251, 191, 36, 0.32) 100%)
  `},lt={[q.SUCCESS]:`pass`,[q.FAILED]:`fail`,[q.ERROR]:`fail`,[q.CANCELLED]:`cancelled`,[q.STALLED]:`stalled`,[q.IN_PROGRESS]:`cancelled`,[q.PENDING]:`cancelled`,[q.QUEUED]:`cancelled`,[q.RUNNING]:`cancelled`};function ut({status:e}){let t=V[e].isComplete,n=lt[e],r=ce(st[n],ct[n]);return t?(0,Y.jsx)(O,{position:`absolute`,top:0,left:0,right:0,bottom:0,background:r,zIndex:1,pointerEvents:`none`}):null}function dt({title:e,status:t}){return(0,Y.jsx)(O,{py:2,px:3,w:`100%`,position:`relative`,zIndex:2,children:(0,Y.jsx)(z,{fontSize:`xs`,fontWeight:`semibold`,color:t&&V[t].isComplete?`white`:`fg`,lineClamp:2,children:e})})}function ft(){return(0,Y.jsxs)(B,{p:4,gap:4,align:`stretch`,height:`100%`,css:{"@keyframes shimmer":{"0%":{opacity:.4},"50%":{opacity:.7},"100%":{opacity:.4}}},children:[(0,Y.jsx)(W,{justify:`flex-end`,children:(0,Y.jsx)(O,{bg:`bg.muted`,borderRadius:`lg`,h:`32px`,w:`65%`,css:{animation:`shimmer 1.5s ease-in-out infinite`}})}),(0,Y.jsxs)(B,{align:`flex-start`,gap:2,children:[(0,Y.jsx)(O,{bg:`bg.muted`,borderRadius:`lg`,h:`14px`,w:`90%`,css:{animation:`shimmer 1.5s ease-in-out 0.15s infinite`}}),(0,Y.jsx)(O,{bg:`bg.muted`,borderRadius:`lg`,h:`14px`,w:`75%`,css:{animation:`shimmer 1.5s ease-in-out 0.3s infinite`}}),(0,Y.jsx)(O,{bg:`bg.muted`,borderRadius:`lg`,h:`14px`,w:`60%`,css:{animation:`shimmer 1.5s ease-in-out 0.45s infinite`}})]}),(0,Y.jsx)(W,{justify:`flex-end`,children:(0,Y.jsx)(O,{bg:`bg.muted`,borderRadius:`lg`,h:`28px`,w:`50%`,css:{animation:`shimmer 1.5s ease-in-out 0.6s infinite`}})}),(0,Y.jsxs)(B,{align:`flex-start`,gap:2,children:[(0,Y.jsx)(O,{bg:`bg.muted`,borderRadius:`lg`,h:`14px`,w:`85%`,css:{animation:`shimmer 1.5s ease-in-out 0.75s infinite`}}),(0,Y.jsx)(O,{bg:`bg.muted`,borderRadius:`lg`,h:`14px`,w:`70%`,css:{animation:`shimmer 1.5s ease-in-out 0.9s infinite`}})]})]})}function pt({description:e}){return(0,Y.jsxs)(B,{height:`100%`,justify:`center`,align:`center`,gap:4,p:4,css:{"@keyframes ripple":{"0%":{transform:`scale(0.8)`,opacity:.4},"50%":{transform:`scale(1)`,opacity:.15},"100%":{transform:`scale(0.8)`,opacity:.4}}},children:[(0,Y.jsx)(O,{position:`relative`,w:`64px`,h:`64px`,children:[0,1,2].map(e=>(0,Y.jsx)(O,{position:`absolute`,inset:`${e*8}px`,borderRadius:`full`,border:`1px solid`,borderColor:`fg.muted`,css:{animation:`ripple 2.4s ease-in-out ${e*.4}s infinite`}},e))}),e&&(0,Y.jsx)(z,{fontSize:`xs`,color:`fg.muted`,textAlign:`center`,lineClamp:2,maxW:`90%`,children:e})]})}function mt({children:e}){return(0,Y.jsx)(ye,{p:0,height:`100%`,overflow:`hidden`,position:`relative`,w:`100%`,children:(0,Y.jsx)(O,{height:`100%`,width:`100%`,position:`relative`,children:e})})}function ht({status:e}){let t=V[e],n=xe[e],r=e===q.RUNNING||e===q.IN_PROGRESS,i=e===q.PENDING||e===q.QUEUED;return(0,Y.jsx)(O,{position:`absolute`,bottom:3,left:`50%`,transform:`translateX(-50%)`,zIndex:10,pointerEvents:`none`,children:(0,Y.jsxs)(W,{gap:1.5,px:3,py:1,borderRadius:`full`,bg:`color-mix(in srgb, var(--chakra-colors-${t.colorPalette}-subtle) 80%, transparent)`,boxShadow:`0 2px 8px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04)`,border:`1px solid`,borderColor:`color-mix(in srgb, var(--chakra-colors-${t.colorPalette}-muted) 50%, transparent)`,color:t.fgColor,children:[r||i?(0,Y.jsx)(H,{size:`xs`,color:t.fgColor}):(0,Y.jsx)(n,{size:12,color:`currentColor`}),(0,Y.jsx)(z,{fontSize:`xs`,fontWeight:`semibold`,textTransform:`capitalize`,lineHeight:`1`,children:t.label})]})})}function gt({title:e,description:t,status:n,isActive:r,isLoading:i,isAwaitingMessages:a,children:o}){let s=n?V[n].isComplete:!1,c=s&&!r;return(0,Y.jsxs)(Re,{height:`100%`,border:`1px solid rgba(255,255,255,0.12)`,borderRadius:`xl`,position:`relative`,bg:`bg.panel`,css:{overflow:`hidden !important`,contain:`content`,boxShadow:`sm`,"&:hover .simulation-card-content":{opacity:1},"& .simulation-chat-scroll":{scrollbarWidth:`none`},"&:hover .simulation-chat-scroll":{scrollbarWidth:`thin`},"& .simulation-chat-scroll::-webkit-scrollbar":{display:`none`},"&:hover .simulation-chat-scroll::-webkit-scrollbar":{display:`block`,width:`6px`}},children:[(0,Y.jsxs)(B,{height:`100%`,gap:0,children:[!i&&(0,Y.jsx)(dt,{title:e,status:n}),(0,Y.jsx)(O,{className:`simulation-card-content`,opacity:c?.45:1,transition:`opacity 0.3s ease`,height:`100%`,width:`100%`,overflow:`hidden`,children:i?(0,Y.jsx)(ft,{}):a?(0,Y.jsx)(pt,{description:t}):(0,Y.jsx)(mt,{children:o})})]}),s&&n&&(0,Y.jsx)(ut,{status:n}),n&&(0,Y.jsx)(ht,{status:n})]})}function _t(e){if(typeof e==`string`){try{let t=JSON.parse(e);if(Array.isArray(t))return vt(t)}catch{}return e}return Array.isArray(e)?vt(e):``}function vt(e){return e.filter(e=>typeof e==`object`&&!!e&&e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(` `)}function yt(){return(0,Y.jsx)(O,{display:`flex`,gap:`3px`,alignItems:`center`,height:`14px`,css:{"@keyframes pulse-dot":{"0%, 80%, 100%":{opacity:.3},"40%":{opacity:1}}},children:[0,1,2].map(e=>(0,Y.jsx)(O,{width:`5px`,height:`5px`,borderRadius:`full`,bg:`fg.muted`,animation:`pulse-dot 1.4s infinite`,style:{animationDelay:`${e*.2}s`}},e))})}function bt({messages:e,streamingMessages:t}){let n=new Set((e??[]).map(e=>e.id).filter(Boolean)),r=(t??[]).filter(e=>!n.has(e.messageId));return(!e||e.length===0)&&r.length===0?(0,Y.jsxs)(B,{align:`stretch`,gap:1.5,padding:3,height:`100%`,justifyContent:`flex-end`,css:{"@keyframes shimmer":{"0%":{opacity:.3},"50%":{opacity:.55},"100%":{opacity:.3}}},children:[(0,Y.jsx)(O,{alignSelf:`flex-end`,maxWidth:`65%`,children:(0,Y.jsx)(O,{bg:`bg.muted`,borderRadius:`lg`,h:`28px`,w:`100%`,css:{animation:`shimmer 2s ease-in-out infinite`}})}),(0,Y.jsxs)(B,{align:`flex-start`,gap:1,maxWidth:`80%`,children:[(0,Y.jsx)(O,{bg:`bg.subtle`,borderRadius:`lg`,h:`12px`,w:`100%`,css:{animation:`shimmer 2s ease-in-out 0.2s infinite`}}),(0,Y.jsx)(O,{bg:`bg.subtle`,borderRadius:`lg`,h:`12px`,w:`70%`,css:{animation:`shimmer 2s ease-in-out 0.4s infinite`}})]})]}):(0,Y.jsxs)(B,{align:`stretch`,gap:1.5,padding:3,height:`100%`,overflow:`hidden`,justifyContent:`flex-end`,children:[(e??[]).map((e,t)=>{let n=`tool_calls`in e&&e.tool_calls?e.tool_calls:`toolCalls`in e&&e.toolCalls?e.toolCalls:null;if(n)return n.map((n,r)=>(0,Y.jsxs)(W,{alignSelf:`flex-start`,gap:1,children:[(0,Y.jsx)(O,{color:`orange.fg`,children:(0,Y.jsx)(Ge,{size:10})}),(0,Y.jsx)(z,{fontSize:`2xs`,color:`orange.fg`,fontWeight:`medium`,lineClamp:1,children:n.function?.name??`tool`})]},`${e.id??t}-tc-${r}`));if(e.role===`tool`){let n=_t(e.content);return n?(0,Y.jsx)(O,{alignSelf:`flex-start`,maxWidth:`85%`,children:(0,Y.jsx)(O,{bg:`bg.subtle`,borderRadius:`lg`,paddingX:2.5,paddingY:1.5,fontSize:`xs`,color:`fg.muted`,lineClamp:2,children:n})},e.id??t):null}let r=_t(e.content);if(!r||r===`None`)return null;let i=e.role===`user`;return(0,Y.jsx)(O,{alignSelf:i?`flex-end`:`flex-start`,maxWidth:`85%`,children:(0,Y.jsx)(O,{bg:i?`gray.600`:`bg.subtle`,color:i?`white`:`fg`,borderRadius:`lg`,paddingX:2.5,paddingY:1.5,fontSize:`xs`,lineClamp:3,children:r})},e.id??t)}),r.map(e=>{let t=e.role===`user`;return(0,Y.jsx)(O,{alignSelf:t?`flex-end`:`flex-start`,maxWidth:`85%`,children:(0,Y.jsx)(O,{bg:t?`gray.600`:`bg.subtle`,color:t?`white`:`fg`,borderRadius:`lg`,paddingX:2.5,paddingY:1.5,fontSize:`xs`,lineClamp:3,children:e.content||(0,Y.jsx)(yt,{})})},e.messageId)})]})}function xt({onCancelJobSuccess:e,onCancelJobError:t,onCancelBatchSuccess:n,onCancelBatchError:r}={}){let i=U.scenarios.cancelJob.useMutation({onSuccess:n=>{n.cancelled?e?.():t?.({message:`Job could not be cancelled — it may have already completed`})},onError:e=>{t?.(e)}}),a=U.scenarios.cancelBatchRun.useMutation({onSuccess:()=>{n?.()},onError:e=>{r?.(e)}});return{cancelJob:(0,J.useCallback)(e=>{i.mutate(e)},[i]),cancelBatchRun:(0,J.useCallback)(e=>{a.mutate(e)},[a]),isCancellingJob:i.isPending,isCancellingBatch:a.isPending}}function St({scenarioRun:e,targetName:t,onClick:n,iteration:r,onCancel:i,isCancelling:o=!1}){let s=F({scenarioName:e.name??e.scenarioId,targetName:t,iteration:r});return(0,Y.jsxs)(O,{position:`relative`,children:[(0,Y.jsx)(O,{as:`button`,onClick:n,cursor:`pointer`,height:`200px`,textAlign:`left`,width:`full`,"aria-label":`View details for ${s}`,children:(0,Y.jsx)(gt,{title:s,status:e.status,children:(0,Y.jsx)(bt,{messages:e.messages})})}),i&&Me(e.status)&&(0,Y.jsxs)(W,{as:`span`,role:`button`,tabIndex:o?-1:0,gap:1,paddingX:2,paddingY:.5,borderRadius:`md`,border:`1px solid`,borderColor:`gray.300`,fontSize:`xs`,color:`fg.default`,bg:`white`,cursor:o?`default`:`pointer`,opacity:o?.6:1,_hover:o?void 0:{bg:`gray.100`,borderColor:`gray.400`},position:`absolute`,top:2,right:2,zIndex:1,onClick:e=>{e.stopPropagation(),o||i()},onKeyDown:e=>{!o&&(e.key===`Enter`||e.key===` `)&&(e.stopPropagation(),e.preventDefault(),i())},"aria-label":`Stop run`,"aria-disabled":o,"data-testid":`cancel-run-button`,children:[o?(0,Y.jsx)(H,{size:`xs`}):(0,Y.jsx)(a,{size:10}),(0,Y.jsx)(z,{fontSize:`xs`,children:`Stop`})]})]})}var Ct={[q.SUCCESS]:`Passed`,[q.FAILED]:`Failed`,[q.ERROR]:`Failed`,[q.CANCELLED]:`Cancelled`,[q.STALLED]:`Stalled`,[q.IN_PROGRESS]:`Running`,[q.PENDING]:`Pending`,[q.QUEUED]:`Queued`,[q.RUNNING]:`Running`},wt=new Set([q.SUCCESS,q.FAILED,q.ERROR]);function Tt({status:e,results:t}){let n=Ct[e];if(!wt.has(e)||!t)return n;let r=t.metCriteria.length,i=r+t.unmetCriteria.length;return i===0?n:`${n} (${r}/${i})`}var Et={[q.SUCCESS]:`green.500`,[q.FAILED]:`red.500`,[q.ERROR]:`red.500`,[q.STALLED]:`yellow.500`,[q.CANCELLED]:`gray.400`,[q.IN_PROGRESS]:`orange.400`,[q.PENDING]:`gray.400`,[q.QUEUED]:`blue.400`,[q.RUNNING]:`orange.400`};function Dt({scenarioRun:e}){let t=e.roleCosts??{},n=e.roleLatencies??{},r=Object.keys(n).filter(e=>n[e]&&n[e].length>0),i=Object.keys(t).filter(e=>t[e]&&t[e].length>0);return(0,Y.jsx)(B,{align:`stretch`,gap:0,fontSize:`12px`,minWidth:`180px`,color:`fg`,children:(0,Y.jsxs)(B,{align:`stretch`,gap:2,padding:2,children:[e.durationInMs>0&&(0,Y.jsxs)(W,{justify:`space-between`,children:[(0,Y.jsx)(z,{color:`fg.muted`,children:`Duration`}),(0,Y.jsx)(z,{fontWeight:`medium`,children:c(e.durationInMs)})]}),e.totalCost!=null&&(0,Y.jsxs)(W,{justify:`space-between`,children:[(0,Y.jsx)(z,{color:`fg.muted`,children:`Total Cost`}),(0,Y.jsx)(z,{fontWeight:`medium`,children:Je(e.totalCost)})]}),r.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(O,{borderTopWidth:`1px`,borderColor:`border.emphasized`,marginX:-2}),(0,Y.jsx)(z,{color:`fg`,fontWeight:`semibold`,children:`Latency`}),r.map(e=>{let t=n[e],r=t.reduce((e,t)=>e+t,0)/t.length;return(0,Y.jsxs)(W,{justify:`space-between`,paddingLeft:2,children:[(0,Y.jsx)(z,{color:`fg.muted`,children:e}),(0,Y.jsx)(z,{fontWeight:`medium`,children:c(r)})]},`lat-${e}`)})]}),i.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[r.length===0&&(0,Y.jsx)(O,{borderTopWidth:`1px`,borderColor:`border.emphasized`,marginX:-2}),(0,Y.jsx)(z,{color:`fg`,fontWeight:`semibold`,children:`Cost`}),i.map(e=>{let n=t[e].reduce((e,t)=>e+t,0);return(0,Y.jsxs)(W,{justify:`space-between`,paddingLeft:2,children:[(0,Y.jsx)(z,{color:`fg.muted`,children:e}),(0,Y.jsx)(z,{fontWeight:`medium`,children:Je(n)})]},`cost-${e}`)})]})]})})}function Ot({status:e}){return e===q.QUEUED||e===q.RUNNING?(0,Y.jsx)(H,{size:`xs`,"data-testid":`queued-spinner`}):(0,Y.jsx)(O,{width:`10px`,height:`10px`,borderRadius:`full`,bg:Et[e]??`gray.400`,flexShrink:0})}function kt({scenarioRun:e,targetName:t,onClick:n,iteration:r,onCancel:i,isCancelling:o=!1}){let s=F({scenarioName:e.name??e.scenarioId,targetName:t,iteration:r}),l=V[e.status],u=i&&Me(e.status),d=e.durationInMs>0||e.totalCost!=null;return(0,Y.jsx)(O,{position:`relative`,className:`group`,borderBottom:`1px solid`,_last:{border:`none`},borderColor:`border.subtle`,_hover:{borderColor:`transparent`},children:(0,Y.jsxs)(W,{as:`button`,width:`full`,paddingX:4,paddingY:2,gap:4,_hover:{bg:`bg.muted/80`},borderRadius:`lg`,cursor:`pointer`,onClick:n,tabIndex:0,"aria-label":`View details for ${s}`,children:[(0,Y.jsxs)(W,{children:[(0,Y.jsx)(Ot,{status:e.status}),(0,Y.jsx)(z,{fontSize:`xs`,fontWeight:`semibold`,color:l.fgColor,minWidth:`43px`,textAlign:`left`,whiteSpace:`nowrap`,children:Tt({status:e.status,results:e.results??void 0})})]}),(0,Y.jsx)(z,{fontSize:`sm`,textAlign:`left`,truncate:!0,children:s}),u&&(0,Y.jsxs)(W,{as:`span`,role:`button`,tabIndex:o?-1:0,gap:1,paddingX:2,paddingY:.5,borderRadius:`md`,border:`1px solid`,borderColor:`gray.300`,fontSize:`xs`,color:`fg.default`,cursor:o?`default`:`pointer`,opacity:o?.6:1,flexShrink:0,_hover:o?void 0:{bg:`gray.100`,borderColor:`gray.400`},onClick:e=>{e.stopPropagation(),o||i?.()},onKeyDown:e=>{!o&&(e.key===`Enter`||e.key===` `)&&(e.stopPropagation(),e.preventDefault(),i?.())},"aria-label":`Stop run`,"aria-disabled":o,"data-testid":`cancel-run-button`,children:[o?(0,Y.jsx)(H,{size:`xs`}):(0,Y.jsx)(a,{size:10}),(0,Y.jsx)(z,{fontSize:`xs`,children:`Stop`})]}),(0,Y.jsx)(O,{flex:1}),d&&(0,Y.jsx)(P,{content:(0,Y.jsx)(Dt,{scenarioRun:e}),contentProps:{padding:0},positioning:{placement:`bottom`},interactive:!0,children:(0,Y.jsxs)(W,{gap:2,flexShrink:0,color:`fg.subtle`,children:[e.durationInMs>0&&(0,Y.jsx)(z,{fontSize:`11px`,children:c(e.durationInMs)}),e.totalCost!=null&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(z,{color:`gray.300`,children:`⋅`}),(0,Y.jsx)(z,{fontSize:`xs`,children:Je(e.totalCost)})]})]})})]})})}var At=30,jt=200,X=16,Mt=16,Nt=jt+X,Pt=37,Ft=250,It=(0,J.memo)(function({scenarioRun:e,targetName:t,onScenarioRunClick:n,iteration:r,onCancelRun:i,isCancelling:a}){let o=(0,J.useCallback)(()=>n(e),[n,e]),s=(0,J.useCallback)(()=>i?.(e),[i,e]);return(0,Y.jsx)(St,{scenarioRun:e,targetName:t,onClick:o,iteration:r,onCancel:i?s:void 0,isCancelling:a})});function Lt(e){return e.scenarioRuns.length>At?(0,Y.jsx)(Bt,{...e}):(0,Y.jsx)(Rt,{...e})}function Rt({scenarioRuns:e,viewMode:t,resolveTargetName:n,onScenarioRunClick:r,iterationMap:i,onCancelRun:a,cancellingJobId:o}){return t===`grid`?(0,Y.jsx)(b,{templateColumns:`repeat(auto-fill, minmax(250px, 1fr))`,gap:4,padding:4,position:`relative`,zIndex:0,"data-testid":`scenario-grid`,children:e.map(e=>(0,Y.jsx)(It,{scenarioRun:e,targetName:n(e),onScenarioRunClick:r,iteration:i.get(e.scenarioRunId),onCancelRun:a,isCancelling:o===e.scenarioRunId},e.scenarioRunId))}):(0,Y.jsx)(B,{align:`stretch`,gap:0,"data-testid":`scenario-list`,children:e.map(e=>(0,Y.jsx)(kt,{scenarioRun:e,targetName:n(e),onClick:()=>r(e),iteration:i.get(e.scenarioRunId),onCancel:a?()=>a(e):void 0,isCancelling:o===e.scenarioRunId},e.scenarioRunId))})}function zt(e){let t=e.parentElement;for(;t;){let e=getComputedStyle(t);if(/(auto|scroll)/.test(e.overflow+e.overflowY))return t;t=t.parentElement}return document.documentElement}function Bt({scenarioRuns:e,viewMode:t,resolveTargetName:n,onScenarioRunClick:r,iterationMap:i,onCancelRun:a,cancellingJobId:o}){let s=(0,J.useRef)(null),[c,l]=(0,J.useState)(null),[u,d]=(0,J.useState)(1),f=t===`grid`;(0,J.useLayoutEffect)(()=>{s.current&&l(zt(s.current))},[]),(0,J.useLayoutEffect)(()=>{if(!s.current||!f)return;let e=s.current.clientWidth-Mt*2;d(Math.max(1,Math.floor((e+X)/(Ft+X))))},[f]),(0,J.useEffect)(()=>{if(!s.current||!f)return;let e=s.current,t=new ResizeObserver(()=>{let t=e.clientWidth-Mt*2;d(Math.max(1,Math.floor((t+X)/(Ft+X))))});return t.observe(e),()=>t.disconnect()},[f]);let p=0;if(s.current&&c){let e=s.current.getBoundingClientRect(),t=c.getBoundingClientRect();p=Math.round(e.top-t.top+c.scrollTop)}let m=f?Math.ceil(e.length/u):e.length,h=f?Nt:Pt,g=je({count:m,getScrollElement:(0,J.useCallback)(()=>c,[c]),estimateSize:(0,J.useCallback)(()=>h,[h]),overscan:5,scrollMargin:p,enabled:!!c}),_=g.getVirtualItems(),v=g.getTotalSize();return f?(0,Y.jsx)(`div`,{ref:s,style:{height:v+Mt*2,width:`100%`,position:`relative`,flexShrink:0},"data-testid":`scenario-grid`,children:_.map(t=>{let s=t.index*u,c=e.slice(s,s+u);return(0,Y.jsx)(`div`,{style:{position:`absolute`,top:Mt,left:Mt,right:Mt,height:jt,transform:`translateY(${t.start-g.options.scrollMargin}px)`,display:`grid`,gridTemplateColumns:`repeat(${u}, 1fr)`,gap:X},children:c.map(e=>(0,Y.jsx)(It,{scenarioRun:e,targetName:n(e),onScenarioRunClick:r,iteration:i.get(e.scenarioRunId),onCancelRun:a,isCancelling:o===e.scenarioRunId},e.scenarioRunId))},t.index)})}):(0,Y.jsx)(`div`,{ref:s,style:{height:v,width:`100%`,position:`relative`,flexShrink:0},"data-testid":`scenario-list`,children:_.map(t=>{let s=e[t.index];return s?(0,Y.jsx)(`div`,{style:{position:`absolute`,top:0,left:0,width:`100%`,height:t.size,transform:`translateY(${t.start-g.options.scrollMargin}px)`},children:(0,Y.jsx)(kt,{scenarioRun:s,targetName:n(s),onClick:()=>r(s),iteration:i.get(s.scenarioRunId),onCancel:a?()=>a(s):void 0,isCancelling:o===s.scenarioRunId})},s.scenarioRunId):null})})}function Vt(e){let t=[];return e.failedCount>0&&t.push(`${e.failedCount} failed`),e.stalledCount>0&&t.push(`${e.stalledCount} stalled`),e.cancelledCount>0&&t.push(`${e.cancelledCount} cancelled`),t.length>0?`(${t.join(`, `)})`:null}function Ht({summary:e}){let t=Vt(e);return(0,Y.jsx)(B,{align:`stretch`,gap:0,fontSize:`12px`,minWidth:`220px`,color:`fg`,children:(0,Y.jsxs)(B,{align:`stretch`,gap:2,padding:2,children:[(0,Y.jsxs)(W,{justify:`space-between`,children:[(0,Y.jsx)(z,{color:`fg.muted`,children:`Pass`}),(0,Y.jsxs)(W,{gap:1.5,children:[(0,Y.jsx)(Qe,{passRate:e.passRate}),(0,Y.jsx)(z,{fontWeight:`medium`,color:Xe(e.passRate),children:e.passRate===null?`-`:`${Math.round(e.passRate)}%`})]})]}),(0,Y.jsxs)(W,{justify:`space-between`,children:[(0,Y.jsx)(z,{color:`fg.muted`,children:`Completed`}),(0,Y.jsxs)(z,{fontWeight:`medium`,children:[e.completedCount,`/`,e.totalCount,t&&(0,Y.jsx)(z,{as:`span`,color:`red.300`,marginLeft:1,children:t})]})]}),e.agentLatencyStats?(0,Y.jsx)(P,{content:(0,Y.jsx)(ee,{stats:e.agentLatencyStats}),positioning:{placement:`right`},openDelay:100,interactive:!0,children:(0,Y.jsxs)(W,{justify:`space-between`,cursor:`pointer`,_hover:{bg:`bg.muted`},marginX:-2,paddingX:2,paddingY:.5,borderRadius:`md`,children:[(0,Y.jsx)(z,{color:`fg.muted`,children:`Avg Agent Latency`}),(0,Y.jsxs)(W,{gap:1,children:[(0,Y.jsx)(I,{as:he,color:`fg.muted`,boxSize:3}),(0,Y.jsx)(z,{fontWeight:`medium`,children:c(e.averageAgentLatencyMs)}),(0,Y.jsx)(I,{as:R,boxSize:3,color:`fg.subtle`})]})]})}):e.averageAgentLatencyMs===null?null:(0,Y.jsxs)(W,{justify:`space-between`,children:[(0,Y.jsx)(z,{color:`fg.muted`,children:`Avg Agent Latency`}),(0,Y.jsxs)(W,{gap:1,children:[(0,Y.jsx)(I,{as:he,color:`fg.muted`,boxSize:3}),(0,Y.jsx)(z,{fontWeight:`medium`,children:c(e.averageAgentLatencyMs)})]})]}),e.agentCostStats?(0,Y.jsx)(P,{content:(0,Y.jsx)(w,{stats:e.agentCostStats}),positioning:{placement:`right`},openDelay:100,interactive:!0,children:(0,Y.jsxs)(W,{justify:`space-between`,cursor:`pointer`,_hover:{bg:`bg.muted`},marginX:-2,paddingX:2,paddingY:.5,borderRadius:`md`,children:[(0,Y.jsx)(z,{color:`fg.muted`,children:`Avg Agent Cost`}),(0,Y.jsxs)(W,{gap:1,children:[(0,Y.jsx)(z,{fontWeight:`medium`,children:Je(e.averageAgentCost)}),(0,Y.jsx)(I,{as:R,boxSize:3,color:`fg.subtle`})]})]})}):null,e.totalDurationMs!==null&&(0,Y.jsxs)(W,{justify:`space-between`,children:[(0,Y.jsx)(z,{color:`fg.muted`,children:`Total Duration`}),(0,Y.jsx)(z,{fontWeight:`medium`,children:c(e.totalDurationMs)})]}),e.totalCost!==null&&(0,Y.jsxs)(W,{justify:`space-between`,children:[(0,Y.jsx)(z,{color:`fg.muted`,children:`Total Cost`}),(0,Y.jsx)(z,{fontWeight:`medium`,children:Je(e.totalCost)})]})]})})}function Ut({summary:e}){let{isOpen:t,handleMouseEnter:n,handleMouseLeave:r}=Ze(150),i=e.inProgressCount>0||e.queuedCount>0;return(0,Y.jsx)(P,{content:(0,Y.jsx)(Ht,{summary:e}),contentProps:{padding:0,onMouseEnter:n,onMouseLeave:r},positioning:{placement:`bottom`},open:t,interactive:!0,children:(0,Y.jsxs)(W,{gap:2,fontSize:`12px`,color:`fg.muted`,paddingX:2,paddingY:1,borderRadius:`lg`,border:`1px solid`,borderColor:`border`,cursor:`default`,_hover:{borderColor:`border.emphasized`,bg:`bg.muted`},"data-testid":`run-metrics-summary`,onMouseEnter:n,onMouseLeave:r,overflow:`hidden`,children:[i&&(0,Y.jsxs)(W,{gap:1,children:[(0,Y.jsx)(I,{as:Fe,boxSize:3,color:`blue.fg`}),(0,Y.jsxs)(z,{color:`blue.fg`,fontWeight:`medium`,children:[e.completedCount,`/`,e.totalCount]})]}),!i&&e.totalCount>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(z,{fontWeight:`600`,children:`Pass`}),(0,Y.jsxs)(W,{gap:1,children:[(0,Y.jsx)(Qe,{passRate:e.passRate}),(0,Y.jsx)(z,{color:Xe(e.passRate),fontWeight:`medium`,children:e.passRate===null?`-`:`${Math.round(e.passRate)}%`})]})]}),i&&e.completedCount>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(z,{fontWeight:`600`,children:`Pass`}),(0,Y.jsxs)(W,{gap:1,children:[(0,Y.jsx)(Qe,{passRate:e.passRate}),(0,Y.jsx)(z,{color:Xe(e.passRate),fontWeight:`medium`,children:e.passRate===null?`-`:`${Math.round(e.passRate)}%`})]})]}),e.totalDurationMs!==null&&(0,Y.jsxs)(W,{gap:1,children:[(0,Y.jsx)(I,{as:he,boxSize:3}),(0,Y.jsx)(z,{fontWeight:`medium`,children:c(e.totalDurationMs)})]}),e.totalCost!==null&&(0,Y.jsx)(z,{fontWeight:`medium`,children:Je(e.totalCost)})]})})}function Wt(e){return e.loading?(0,Y.jsx)(Gt,{suiteName:e.suiteName}):(0,Y.jsx)(Kt,{...e})}function Gt({suiteName:e}){return(0,Y.jsxs)(O,{children:[(0,Y.jsx)(O,{padding:2,paddingBottom:0,width:`full`,position:`sticky`,top:0,zIndex:20,children:(0,Y.jsxs)(W,{width:`full`,paddingX:4,paddingY:3,gap:3,flexWrap:`nowrap`,bg:`bg.subtle/50`,backdropFilter:`blur(4px)`,"data-testid":`run-row-header`,borderRadius:`lg`,boxShadow:`xs`,children:[(0,Y.jsx)(H,{size:`xs`,color:`fg.muted`,css:{flexShrink:0,height:`14px`,width:`14px`}}),e&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(z,{fontSize:`sm`,fontWeight:`medium`,color:`fg.default`,flexShrink:0,children:e}),(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,flexShrink:0,children:`·`})]}),(0,Y.jsx)(z,{fontSize:`xs`,color:`fg.subtle`,flexShrink:0,children:`Starting...`}),(0,Y.jsx)(O,{flex:1}),(0,Y.jsx)(O,{paddingY:1,paddingX:2,borderRadius:`lg`,border:`1px solid transparent`,children:(0,Y.jsx)(z,{fontSize:`12px`,visibility:`hidden`,children:`\xA0`})})]})}),(0,Y.jsx)(O,{padding:2})]})}function Kt({batchRun:e,summary:t,isExpanded:n,onToggle:r,resolveTargetName:i,onScenarioRunClick:o,expectedJobCount:s,suiteName:c,viewMode:l=`grid`,onCancelRun:u,onCancelAll:d,isCancellingBatch:f=!1,cancellingJobId:p,isHighlighted:m=!1}){let[h,g]=(0,J.useState)(!1),v=ot(),y=_(e.timestamp,v),b=(0,J.useMemo)(()=>ae({scenarioRuns:e.scenarioRuns}),[e.scenarioRuns]),x=(0,J.useMemo)(()=>e.scenarioRuns.filter(e=>Me(e.status)).length,[e.scenarioRuns]),S=x>0;return(0,Y.jsxs)(O,{"data-batch-id":e.batchRunId,css:m?{"@keyframes yellowFlash":{"0%":{backgroundColor:`rgba(234, 179, 8, 0.3)`},"100%":{backgroundColor:`transparent`}},animation:`yellowFlash 2s ease-out`}:void 0,children:[(0,Y.jsx)(O,{padding:2,paddingBottom:0,width:`full`,position:`sticky`,top:0,zIndex:20,children:(0,Y.jsxs)(W,{as:`button`,width:`full`,paddingX:4,paddingY:3,gap:3,flexWrap:`nowrap`,cursor:`pointer`,onClick:r,className:`group`,"aria-expanded":n,"aria-label":`Run from ${y??`unknown time`}`,bg:`bg.subtle/50`,backdropFilter:`blur(4px)`,"data-testid":`run-row-header`,borderRadius:`lg`,boxShadow:`xs`,children:[n?(0,Y.jsx)(N,{size:14,style:{flexShrink:0}}):(0,Y.jsx)(A,{size:14,style:{flexShrink:0}}),c&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(z,{fontSize:`sm`,fontWeight:`medium`,color:`fg.default`,flexShrink:0,children:c}),(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,flexShrink:0,children:`·`})]}),(0,Y.jsx)(z,{fontSize:`xs`,color:`fg.subtle`,flexShrink:0,children:y}),s!=null&&t.totalCount<s&&(0,Y.jsxs)(z,{fontSize:`xs`,color:`fg.muted`,flexShrink:0,children:[t.totalCount,` of `,s]}),d&&S&&(0,Y.jsxs)(W,{as:`span`,role:`button`,tabIndex:f?-1:0,gap:1,paddingX:2,paddingY:.5,borderRadius:`md`,border:`1px solid`,borderColor:`gray.300`,fontSize:`xs`,color:`fg.default`,cursor:f?`default`:`pointer`,flexShrink:0,opacity:f?.6:1,_hover:f?void 0:{bg:`gray.100`,borderColor:`gray.400`},onClick:e=>{e.stopPropagation(),f||g(!0)},onKeyDown:e=>{!f&&(e.key===`Enter`||e.key===` `)&&(e.stopPropagation(),e.preventDefault(),g(!0))},"aria-label":`Stop all remaining runs`,"aria-disabled":f,"data-testid":`cancel-all-button`,children:[f?(0,Y.jsx)(H,{size:`xs`}):(0,Y.jsx)(a,{size:10}),(0,Y.jsx)(z,{fontSize:`xs`,children:`Stop`})]}),(0,Y.jsx)(O,{flex:1}),(0,Y.jsx)(Ut,{summary:t})]})}),(0,Y.jsx)(O,{padding:2,children:n&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Lt,{scenarioRuns:e.scenarioRuns,viewMode:l,resolveTargetName:i,onScenarioRunClick:o,iterationMap:b,onCancelRun:u,cancellingJobId:p}),e.scenarioRuns.length===0&&(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,paddingX:4,paddingY:3,children:`No scenario runs in this batch.`})]})}),d&&(0,Y.jsx)(L.Root,{open:h,onOpenChange:({open:e})=>g(e),children:(0,Y.jsxs)(L.Content,{bg:`bg`,maxWidth:`sm`,children:[(0,Y.jsx)(L.Header,{children:(0,Y.jsx)(L.Title,{children:`Cancel remaining jobs?`})}),(0,Y.jsx)(L.Body,{children:(0,Y.jsxs)(z,{fontSize:`sm`,color:`fg.muted`,children:[`This will cancel `,x,` remaining`,` `,x===1?`job`:`jobs`,` in this batch run. This action cannot be undone.`]})}),(0,Y.jsxs)(L.Footer,{children:[(0,Y.jsx)(G,{variant:`outline`,onClick:()=>g(!1),children:`Keep running`}),(0,Y.jsxs)(G,{colorPalette:`red`,onClick:()=>{g(!1),d()},"data-testid":`confirm-cancel-all-button`,children:[`Cancel `,x,` `,x===1?`job`:`jobs`]})]})]})})]})}function qt({batch:e,resolveTargetName:t,onScenarioRunClick:n,viewMode:r,onCancelRun:i,cancellingJobId:a}){let o=(0,J.useMemo)(()=>m({batchRun:e}),[e]),s=(0,J.useMemo)(()=>ae({scenarioRuns:e.scenarioRuns}),[e.scenarioRuns]),c=ot();return(0,Y.jsxs)(B,{align:`stretch`,gap:0,children:[(0,Y.jsxs)(W,{paddingX:4,paddingY:2,gap:2,"data-testid":`batch-sub-header`,children:[(0,Y.jsx)(z,{fontSize:`xs`,color:`fg.subtle`,children:_(e.timestamp,c)}),(0,Y.jsx)(O,{flex:1}),(0,Y.jsx)(Jt,{summary:o})]}),(0,Y.jsx)(Lt,{scenarioRuns:e.scenarioRuns,viewMode:r,resolveTargetName:t,onScenarioRunClick:n,iterationMap:s,onCancelRun:i,cancellingJobId:a})]})}function Jt({summary:e}){let t=[];return e.passedCount>0&&t.push({count:e.passedCount,color:`green.500`,label:`passed`}),e.failedCount>0&&t.push({count:e.failedCount,color:`red.500`,label:`failed`}),e.stalledCount>0&&t.push({count:e.stalledCount,color:`yellow.500`,label:`stalled`}),e.cancelledCount>0&&t.push({count:e.cancelledCount,color:`fg.muted`,label:`cancelled`}),e.inProgressCount>0&&t.push({count:e.inProgressCount,color:`orange.500`,label:`running`}),e.queuedCount>0&&t.push({count:e.queuedCount,color:`blue.500`,label:`queued`}),t.length===0?null:(0,Y.jsx)(W,{gap:2,children:t.map(e=>(0,Y.jsxs)(W,{gap:1,children:[(0,Y.jsx)(O,{width:`6px`,height:`6px`,borderRadius:`full`,bg:e.color,flexShrink:0}),(0,Y.jsxs)(z,{fontSize:`xs`,color:`fg.subtle`,children:[e.count,` `,e.label]})]},e.label))})}function Yt({group:e,summary:t,isExpanded:n,onToggle:r,onScenarioRunClick:i,resolveTargetName:a,viewMode:s=`grid`,onCancelRun:c,cancellingJobId:l}){let u=e.scenarioRuns.length,d=(0,J.useMemo)(()=>o({runs:e.scenarioRuns}),[e.scenarioRuns]);return(0,Y.jsxs)(O,{children:[(0,Y.jsx)(O,{padding:2,paddingBottom:0,width:`full`,position:`sticky`,top:0,zIndex:20,children:(0,Y.jsxs)(W,{as:`button`,width:`full`,paddingX:4,paddingY:3,gap:3,flexWrap:`nowrap`,cursor:`pointer`,onClick:r,className:`group`,"aria-expanded":n,"aria-label":`${e.groupLabel} group`,bg:`bg.subtle/50`,backdropFilter:`blur(4px)`,"data-testid":`group-row-header`,borderRadius:`lg`,boxShadow:`xs`,children:[n?(0,Y.jsx)(N,{size:14,style:{flexShrink:0}}):(0,Y.jsx)(A,{size:14,style:{flexShrink:0}}),(0,Y.jsx)(z,{fontSize:`sm`,fontWeight:`medium`,color:`fg.default`,truncate:!0,minWidth:0,flexShrink:1,children:e.groupLabel}),(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,flexShrink:0,children:`·`}),(0,Y.jsxs)(z,{fontSize:`xs`,color:`fg.muted`,flexShrink:0,children:[u,` `,u===1?`run`:`runs`]}),(0,Y.jsx)(O,{flex:1}),(0,Y.jsx)(O,{flexShrink:0,children:(0,Y.jsx)(Ut,{summary:t})})]})}),(0,Y.jsx)(O,{padding:2,children:n&&(0,Y.jsxs)(Y.Fragment,{children:[d.map(e=>(0,Y.jsx)(qt,{batch:e,resolveTargetName:a,onScenarioRunClick:i,viewMode:s,onCancelRun:c,cancellingJobId:l},e.batchRunId)),e.scenarioRuns.length===0&&(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,paddingX:4,paddingY:3,children:`No scenario runs in this group.`})]})})]})}function Xt({scrollRef:e,fadeAfterPx:t=100}={}){let[n,r]=(0,J.useState)(+!e),i=(0,J.useRef)(null);return(0,J.useEffect)(()=>{if(!e)return;let n,a=!1,o=()=>{let s=e.current;if(!s){n=requestAnimationFrame(o);return}a=!0;let c=()=>{r(Math.min(s.scrollTop/t,1))};c(),s.addEventListener(`scroll`,c,{passive:!0}),i.current=()=>s.removeEventListener(`scroll`,c)};return n=requestAnimationFrame(o),()=>{a||cancelAnimationFrame(n),i.current?.(),i.current=null}},[e,t]),(0,Y.jsxs)(O,{width:`full`,flexShrink:0,position:`relative`,opacity:n,transition:`opacity 0.15s ease-out`,children:[(0,Y.jsx)(O,{width:`full`,height:`1px`,bg:`border.muted`}),(0,Y.jsx)(O,{width:`full`,height:`4px`,background:`linear-gradient(to bottom, var(--chakra-colors-border-muted), transparent)`,opacity:.4,position:`absolute`,zIndex:1})]})}function Zt({count:e,label:t,tooltip:n,icon:r,color:i,bg:a}){return(0,Y.jsx)(P,{content:n,children:(0,Y.jsxs)(W,{gap:`4px`,paddingX:`8px`,paddingY:`2px`,borderRadius:`md`,bg:a,children:[(0,Y.jsx)(r,{size:12,style:{color:`var(--chakra-colors-${i})`}}),(0,Y.jsxs)(z,{fontSize:`xs`,fontWeight:`semibold`,color:i,whiteSpace:`nowrap`,children:[e,` `,t]})]})})}function Qt({summary:e}){return(0,Y.jsxs)(W,{gap:1,"data-testid":`run-summary-counts`,children:[e.passedCount>0&&(0,Y.jsx)(Zt,{count:e.passedCount,label:`passed`,tooltip:`${e.passedCount} scenario${e.passedCount===1?``:`s`} passed all criteria`,icon:v,color:`green.fg`,bg:`green.subtle`}),e.failedCount>0&&(0,Y.jsx)(Zt,{count:e.failedCount,label:`failed`,tooltip:`${e.failedCount} scenario${e.failedCount===1?``:`s`} failed one or more criteria`,icon:u,color:`red.fg`,bg:`red.subtle`}),e.stalledCount>0&&(0,Y.jsx)(Zt,{count:e.stalledCount,label:`stalled`,tooltip:`${e.stalledCount} scenario${e.stalledCount===1?``:`s`} stalled (no response received)`,icon:j,color:`yellow.fg`,bg:`yellow.subtle`}),e.cancelledCount>0&&(0,Y.jsx)(Zt,{count:e.cancelledCount,label:`cancelled`,tooltip:`${e.cancelledCount} scenario${e.cancelledCount===1?``:`s`} were cancelled`,icon:t,color:`fg.muted`,bg:`bg.emphasized`}),e.inProgressCount>0&&(0,Y.jsx)(Zt,{count:e.inProgressCount,label:`running`,tooltip:`${e.inProgressCount} scenario${e.inProgressCount===1?``:`s`} currently executing`,icon:tt,color:`orange.fg`,bg:`orange.subtle`}),e.queuedCount>0&&(0,Y.jsx)(Zt,{count:e.queuedCount,label:`queued`,tooltip:`${e.queuedCount} scenario${e.queuedCount===1?``:`s`} waiting to execute`,icon:M,color:`blue.fg`,bg:`blue.subtle`})]})}function $t(e){return typeof e==`string`&&l.includes(e)}function en(e,t){let n=e[t];return Array.isArray(n)?n[0]??``:typeof n==`string`?n:``}function tn(){return ve((e,t)=>({groupBy:`none`,viewMode:`grid`,filters:{scenarioId:``,passFailStatus:``},setGroupBy:t=>{e({groupBy:t})},setViewMode:t=>{e({viewMode:t})},setFilter:(t,n)=>{e(e=>({filters:{...e.filters,[t]:n}}))},setFilters:t=>{e({filters:t})},syncToUrl:e=>{let{groupBy:n,filters:r}=t(),i={};for(let[t,n]of Object.entries(e.query))(typeof n==`string`||Array.isArray(n))&&(i[t]=n);n===`none`?delete i.groupBy:i.groupBy=n,r.scenarioId?i.scenarioId=r.scenarioId:delete i.scenarioId,r.passFailStatus?i.passFailStatus=r.passFailStatus:delete i.passFailStatus,e.push({query:i},void 0,{shallow:!0})},hydrateFromUrl:t=>{let n=en(t,`groupBy`);e({groupBy:$t(n)?n:`none`,filters:{scenarioId:en(t,`scenarioId`),passFailStatus:en(t,`passFailStatus`)}})}}))}var Z=tn();function nn(e){if(e.startsWith(`{`)&&e.endsWith(`}`))throw Error(`Queue name "${e}" is already wrapped in hash tags. Do not call makeQueueName twice.`);return`{${e}}`}nn(`simulations/scenarios/executions`);var rn={TIMEOUT_MS:900*1e3}.TIMEOUT_MS*2;function an({scenarioSetId:e,startDateMs:t}){let{project:n}=ge(),[r,i]=(0,J.useState)(void 0),[a,o]=(0,J.useState)([]),s=(0,J.useRef)(void 0);(0,J.useEffect)(()=>{i(void 0),o([])},[t]);let{data:c,isLoading:l,error:u,refetch:d}=U.scenarios.getSuiteRunData.useQuery({projectId:n?.id??``,scenarioSetId:e,limit:20,cursor:r,startDate:t},{enabled:!!n,refetchInterval:a.length<=1?3e4:void 0,trpc:{context:{skipBatch:!0}}});return(0,J.useEffect)(()=>{!c||!c.changed||(r===void 0?o([c]):r!==s.current&&o(e=>[...e,c]),s.current=r)},[c,r]),{allRuns:(0,J.useMemo)(()=>{let e=Date.now();return a.flatMap(e=>e.runs).map(t=>t.status===q.IN_PROGRESS&&e-t.timestamp>=rn?{...t,status:q.STALLED}:t)},[a]),allScenarioSetIds:(0,J.useMemo)(()=>{let e={};for(let t of a)Object.assign(e,t.scenarioSetIds);return e},[a]),hasMore:a.length>0?a[a.length-1]?.hasMore??!1:!1,loadMore:(0,J.useCallback)(()=>{let e=a[a.length-1];e?.nextCursor&&i(e.nextCursor)},[a]),isLoading:l&&a.length===0,error:u,refetch:d}}var on=`langwatch:run-history-expanded`,sn=new Set,Q=new Map;try{let e=typeof window<`u`?localStorage.getItem(on):null;if(e){let t=JSON.parse(e);for(let[e,n]of Object.entries(t))Q.set(e,new Set(n)),sn.add(e)}}catch{}function cn(){try{let e={};for(let[t,n]of Q)e[t]=[...n];localStorage.setItem(on,JSON.stringify(e))}catch{}}function ln(e,t){return`${e}::${t}`}function un({panelKey:e,groupBy:t,batchRuns:n,groups:r}){let i=ln(e,t),[a,o]=(0,J.useState)(()=>Q.get(i)??new Set),s=(0,J.useRef)(t),c=(0,J.useRef)(e);return(0,J.useEffect)(()=>{if(s.current!==t||c.current!==e){let n=ln(e,t),r=Q.get(n);r?o(r):(o(new Set),sn.delete(n)),s.current=t,c.current=e}},[t,e]),(0,J.useEffect)(()=>{let e=t===`none`?n:r;if(e.length===0)return;let a=new Set(e.map(e=>`batchRunId`in e?e.batchRunId:e.groupKey));sn.has(i)?o(e=>{let t=[...a].filter(t=>!e.has(t));if(t.length===0)return e;let n=new Set(e);for(let e of t)n.add(e);return Q.set(i,n),cn(),n}):(o(a),Q.set(i,a),sn.add(i),cn())},[t,n,r,i]),{expandedIds:a,toggleExpanded:(0,J.useCallback)(e=>{o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),Q.set(i,n),cn(),n})},[i])}}var dn=2e3,fn=100,pn=50;function mn({highlightBatchId:e}){let[t,n]=(0,J.useState)(null);return(0,J.useEffect)(()=>{if(!e){n(null);return}let t=0,r=!1,i=null,a=()=>{if(r)return;let o=document.querySelector(`[data-batch-id="${e}"]`);if(!o){t++,t<pn&&requestAnimationFrame(a);return}document.querySelectorAll(`[data-batch-id]`)[0]!==o&&o.scrollIntoView({behavior:`smooth`,block:`center`}),n(e),i=setTimeout(()=>{r||n(null)},dn)},o=setTimeout(a,fn);return()=>{r=!0,clearTimeout(o),i&&clearTimeout(i)}},[e]),{highlightedBatchId:t}}function hn({scenarioSetId:e,period:t,onStatsReady:n,expectedJobCount:r,suiteNameMap:i,pendingBatchRunId:a,highlightBatchId:s}){let{project:c}=ge(),l=Ae(),u=Z(e=>e.groupBy),d=Z(e=>e.viewMode),p=Z(e=>e.filters),h=Z(e=>e.setGroupBy),_=Z(e=>e.setViewMode),v=Z(e=>e.setFilters),y=Z(e=>e.syncToUrl),b=Z(e=>e.hydrateFromUrl),x=(0,J.useRef)(null),C=(0,J.useRef)(!1);(0,J.useEffect)(()=>{!C.current&&l.isReady&&(b(l.query),C.current=!0)},[l.isReady,l.query,b]);let w=(0,J.useRef)(u),T=(0,J.useRef)(p);(0,J.useEffect)(()=>{C.current&&(w.current!==u||T.current!==p)&&(w.current=u,T.current=p,y(l))},[u,p,y,l]);let{allRuns:E,allScenarioSetIds:D,hasMore:ee,loadMore:te,isLoading:re,error:k,refetch:A}=an({scenarioSetId:e,startDateMs:t.startDate.getTime()});Ke({projectId:c?.id??``,refetch:A,enabled:!!c?.id,debounceMs:500,filter:e?{scenarioSetId:e}:void 0});let{data:ae}=U.scenarios.getAll.useQuery({projectId:c?.id??``},{enabled:!!c}),oe=_e(),j=(0,J.useCallback)(e=>{let t=e.metadata?.langwatch?.targetReferenceId;return t?oe.get(t)??t:null},[oe]),M=(0,J.useMemo)(()=>ae?ae.map(e=>({id:e.id,name:e.name})):[],[ae]),[se,N]=(0,J.useState)(null),{cancelJob:ce,cancelBatchRun:P,isCancellingBatch:le}=xt({onCancelJobSuccess:()=>{N(null),A(),K.create({title:`Cancellation requested`,type:`info`})},onCancelJobError:e=>{N(null),A(),K.create({title:`Failed to cancel job`,description:e.message,type:`error`})},onCancelBatchSuccess:()=>{A(),K.create({title:`Jobs cancelled`,type:`success`})},onCancelBatchError:e=>{K.create({title:`Failed to cancel jobs`,description:e.message,type:`error`})}}),F=(0,J.useMemo)(()=>{if(E.length===0)return[];let e=E;return p.scenarioId&&(e=e.filter(e=>e.scenarioId===p.scenarioId)),p.passFailStatus===`pass`?e=e.filter(e=>e.status===q.SUCCESS):p.passFailStatus===`fail`?e=e.filter(e=>e.status===q.ERROR||e.status===q.FAILED):p.passFailStatus===`stalled`&&(e=e.filter(e=>e.status===q.STALLED)),e},[E,p]),I=(0,J.useMemo)(()=>o({runs:F,scenarioSetIds:D}),[F,D]),L=(0,J.useMemo)(()=>u===`none`?[]:u===`scenario`?we({runs:F}):ne({runs:F,targetNameMap:oe}),[u,F,oe]),{expandedIds:ue,toggleExpanded:de}=un({panelKey:e??`all-runs`,groupBy:u,batchRuns:I,groups:L}),R=(0,J.useMemo)(()=>De({runs:F}),[F]),fe=u===`none`?I[0]?.timestamp??null:L[0]?.timestamp??null;(0,J.useEffect)(()=>{if(!n)return;let e=R.passedCount+R.failedCount,t=e>0?R.passedCount/e*100:0;n({runCount:R.runCount,passRate:t,lastActivityTimestamp:fe})},[R,fe,n]);let{highlightedBatchId:pe}=mn({highlightBatchId:s}),me=e=>!!e&&(S(e)||g(e)),he=(0,J.useCallback)(e=>t=>{c?.id&&(N(t.scenarioRunId),ce({projectId:c.id,scenarioSetId:e,batchRunId:t.batchRunId,scenarioRunId:t.scenarioRunId,scenarioId:t.scenarioId}))},[c?.id,ce]),ve=(0,J.useCallback)((e,t)=>{c?.id&&P({projectId:c.id,scenarioSetId:t,batchRunId:e})},[c?.id,P]),{openDrawer:V}=Ne(),ye=(0,J.useCallback)(e=>{V(`scenarioRunDetail`,{urlParams:{scenarioRunId:e.scenarioRunId}})},[V]),be=(0,J.useCallback)(e=>{v(e)},[v]),xe=(0,J.useMemo)(()=>a?!I.some(e=>e.batchRunId===a):!1,[a,I]);if(k)return(0,Y.jsx)(O,{padding:6,children:(0,Y.jsxs)(z,{color:`red.fg`,children:[`Error loading runs: `,k.message]})});if(re)return(0,Y.jsx)(O,{padding:6,display:`flex`,justifyContent:`center`,children:(0,Y.jsx)(H,{size:`lg`,"data-testid":`loading-spinner`})});let Se=!!e,Ce=u===`none`?I.length:L.length,Te=!!(p.scenarioId||p.passFailStatus);return(0,Y.jsxs)(B,{align:`stretch`,gap:0,height:`100%`,children:[!Se&&(0,Y.jsxs)(O,{paddingX:6,paddingY:4,children:[(0,Y.jsx)(z,{fontSize:`xl`,fontWeight:`semibold`,children:`All Runs`}),(0,Y.jsxs)(W,{gap:2,"data-testid":`all-runs-header-totals`,children:[(0,Y.jsxs)(z,{fontSize:`sm`,color:`fg.muted`,children:[u===`none`?`${I.length} ${I.length===1?`execution`:`executions`} · `:`${L.length} ${L.length===1?`group`:`groups`} · `,R.runCount,` `,R.runCount===1?`run`:`runs`]}),(0,Y.jsx)(Qt,{summary:{passedCount:R.passedCount,failedCount:R.failedCount,stalledCount:0,cancelledCount:0,completedCount:R.passedCount+R.failedCount,inProgressCount:R.pendingCount,queuedCount:0,passRate:0,totalCount:R.runCount,totalCost:null,averageAgentLatencyMs:null,totalDurationMs:null,agentLatencyStats:null,agentCostStats:null,averageAgentCost:null}})]})]}),(0,Y.jsx)(O,{paddingX:6,paddingY:4,bg:`bg`,_after:{content:`""`,position:`absolute`,bottom:`-5px`,left:0,right:0,height:`5px`,borderTop:`1px solid var(--chakra-colors-border-muted)`,background:`linear-gradient(to bottom, color-mix(in srgb, var(--chakra-colors-border-muted) 40%, transparent), transparent)`,pointerEvents:`none`},children:(0,Y.jsx)(it,{scenarioOptions:M,filters:p,onFiltersChange:be,groupBy:u,onGroupByChange:h,viewMode:d,onViewModeChange:_})}),(0,Y.jsx)(Xt,{scrollRef:x}),Ce===0&&!xe?(0,Y.jsx)(O,{paddingX:6,paddingY:8,textAlign:`center`,children:(0,Y.jsx)(z,{color:`fg.muted`,children:Te?`No runs match the selected filters.`:Se?`Run this suite to see results here.`:`No runs yet. Execute a suite to see results here.`})}):(0,Y.jsxs)(B,{ref:x,align:`stretch`,gap:0,flex:1,minH:0,overflow:`auto`,children:[xe&&(0,Y.jsx)(Wt,{loading:!0}),u===`none`?I.map(t=>(0,Y.jsx)(Wt,{batchRun:t,summary:m({batchRun:t}),isExpanded:ue.has(t.batchRunId),onToggle:()=>de(t.batchRunId),resolveTargetName:j,onScenarioRunClick:ye,expectedJobCount:r,suiteName:i?ie({scenarioSetId:t.scenarioSetId,suiteNameMap:i})??void 0:void 0,viewMode:d,onCancelRun:me(t.scenarioSetId??e)?he(t.scenarioSetId??e??``):void 0,onCancelAll:me(t.scenarioSetId??e)?()=>ve(t.batchRunId,t.scenarioSetId??e??``):void 0,isCancellingBatch:le,cancellingJobId:se,isHighlighted:pe===t.batchRunId},t.batchRunId)):L.map(t=>(0,Y.jsx)(Yt,{group:t,summary:f({group:t}),isExpanded:ue.has(t.groupKey),onToggle:()=>de(t.groupKey),onScenarioRunClick:ye,resolveTargetName:j,viewMode:d,onCancelRun:me(e)?he(e??``):void 0,cancellingJobId:se},t.groupKey)),ee&&(0,Y.jsx)(O,{paddingX:6,paddingY:6,display:`flex`,justifyContent:`center`,children:(0,Y.jsx)(G,{variant:`outline`,onClick:te,children:`Load More...`})})]})]})}function gn({open:e,onClose:t,onConfirm:n,suiteName:r,isLoading:i=!1}){return(0,Y.jsx)(L.Root,{open:e,onOpenChange:t,placement:`center`,children:(0,Y.jsxs)(L.Content,{bg:`bg`,maxWidth:`500px`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(L.CloseTrigger,{}),(0,Y.jsx)(L.Header,{children:(0,Y.jsx)(L.Title,{fontSize:`md`,fontWeight:`500`,children:`Archive run plan?`})}),(0,Y.jsx)(L.Body,{children:(0,Y.jsxs)(B,{align:`stretch`,gap:4,children:[(0,Y.jsx)(z,{children:(0,Y.jsx)(z,{as:`span`,fontWeight:`semibold`,children:r})}),(0,Y.jsx)(z,{color:`fg.muted`,fontSize:`sm`,children:`Archived run plans will no longer appear in the sidebar. Test runs are preserved.`})]})}),(0,Y.jsxs)(L.Footer,{children:[(0,Y.jsx)(G,{variant:`outline`,mr:3,onClick:e=>{e.stopPropagation(),t()},disabled:i,children:`Cancel`}),(0,Y.jsx)(G,{colorPalette:`orange`,onClick:e=>{e.stopPropagation(),n()},disabled:i,children:i?(0,Y.jsx)(H,{size:`sm`}):`Archive`})]})]})})}function _n({x:e,y:t,onEdit:n,onDuplicate:r,onArchive:i,onClose:a}){let o=(0,J.useRef)(null);return(0,J.useEffect)(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&a()};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),(0,Y.jsx)(O,{ref:o,position:`fixed`,left:`${e}px`,top:`${t}px`,bg:`bg.surface`,border:`1px solid`,borderColor:`border`,borderRadius:`md`,shadow:`lg`,zIndex:1e3,py:1,minWidth:`140px`,children:(0,Y.jsxs)(B,{align:`stretch`,gap:0,children:[(0,Y.jsx)(vn,{label:`Edit`,onClick:()=>{n(),a()}}),(0,Y.jsx)(vn,{label:`Duplicate`,onClick:()=>{r(),a()}}),(0,Y.jsx)(vn,{label:`Archive`,onClick:()=>{i(),a()},color:`orange.fg`})]})})}function vn({label:e,onClick:t,color:n}){return(0,Y.jsx)(O,{as:`button`,width:`full`,textAlign:`left`,paddingX:3,paddingY:1.5,cursor:`pointer`,_hover:{bg:`bg.subtle`},onClick:t,children:(0,Y.jsx)(z,{fontSize:`sm`,color:n,children:e})})}function yn({suite:e,onEdit:t,onRun:r,isRunning:i=!1,pendingBatchRunId:a,period:o,highlightBatchId:s}){let c=ot(),l=(()=>{try{return me(e.targets)}catch{return[]}})(),u=e.scenarioIds.length*l.length*e.repeatCount,[d,f]=(0,J.useState)(null);return(0,Y.jsxs)(B,{align:`stretch`,gap:0,height:`100%`,children:[(0,Y.jsx)(O,{paddingX:6,paddingY:4,children:(0,Y.jsxs)(W,{justify:`space-between`,align:`start`,children:[(0,Y.jsxs)(B,{align:`start`,gap:1,children:[(0,Y.jsx)(z,{fontSize:`xl`,fontWeight:`bold`,children:e.name}),e.description&&(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,children:e.description})]}),(0,Y.jsxs)(W,{gap:2,children:[(0,Y.jsxs)(G,{size:`sm`,variant:`outline`,onClick:t,children:[(0,Y.jsx)(de,{size:14}),`Edit`]}),(0,Y.jsxs)(G,{size:`sm`,colorPalette:`blue`,onClick:r,disabled:i,loading:i,children:[(0,Y.jsx)(fe,{size:14}),`Run`]})]})]})}),(0,Y.jsx)(O,{paddingX:6,paddingBottom:2,children:(0,Y.jsxs)(W,{gap:2,flexWrap:`wrap`,alignItems:`center`,children:[(0,Y.jsx)($,{icon:(0,Y.jsx)(qe,{size:14}),value:e.scenarioIds.length,label:`scenarios`,colorScheme:`gray`}),(0,Y.jsx)($,{icon:(0,Y.jsx)(k,{size:14}),value:l.length,label:`targets`,colorScheme:`purple`}),(0,Y.jsx)($,{icon:(0,Y.jsx)(nt,{size:14}),value:`${e.repeatCount}x`,label:`trials`,colorScheme:`gray`}),d&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(y,{orientation:`vertical`,height:`24px`,borderColor:`border`}),(0,Y.jsx)($,{icon:(0,Y.jsx)(Le,{size:14}),value:u,label:`executions`,colorScheme:`gray`}),(0,Y.jsx)($,{icon:(0,Y.jsx)(n,{size:14}),value:d.runCount,label:`runs`,colorScheme:`gray`}),(0,Y.jsx)(xn,{passRate:d.passRate}),d.lastActivityTimestamp&&(0,Y.jsx)($,{icon:(0,Y.jsx)(M,{size:14}),value:_(d.lastActivityTimestamp,c),label:``,colorScheme:`gray`})]}),!d&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(y,{orientation:`vertical`,height:`24px`,borderColor:`border`}),(0,Y.jsx)($,{icon:(0,Y.jsx)(Le,{size:14}),value:u,label:`executions`,colorScheme:`gray`})]})]})}),(0,Y.jsx)(hn,{scenarioSetId:se(e.id),onStatsReady:f,period:o,pendingBatchRunId:a,highlightBatchId:s})]})}var bn={gray:{bg:`bg.muted`,color:`fg.muted`},purple:{bg:`bg.muted`,color:`purple.fg`},blue:{bg:`bg.muted`,color:`blue.fg`},orange:{bg:`bg.muted`,color:`orange.fg`}};function $({icon:e,value:t,label:n,colorScheme:r=`gray`}){let i=bn[r]??bn.gray;return(0,Y.jsxs)(W,{gap:1.5,paddingX:3,paddingY:1.5,borderRadius:`full`,bg:i.bg,children:[(0,Y.jsx)(O,{color:i.color,children:e}),(0,Y.jsx)(z,{fontSize:`sm`,fontWeight:`semibold`,children:t}),n&&(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,children:n})]})}function xn({passRate:e}){return(0,Y.jsxs)(W,{gap:1.5,paddingX:3,paddingY:1.5,borderRadius:`full`,border:`1px solid`,borderColor:`border`,bg:`bg`,children:[(0,Y.jsx)(Te,{size:14}),(0,Y.jsxs)(z,{fontSize:`sm`,fontWeight:`semibold`,children:[Math.round(e),`%`]}),(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,children:`pass`})]})}function Sn({onNewSuite:e}){return(0,Y.jsx)(Ue,{flex:1,height:`100%`,children:(0,Y.jsx)(Oe,{children:(0,Y.jsxs)(h,{children:[(0,Y.jsx)(oe,{children:(0,Y.jsx)(pe,{size:32})}),(0,Y.jsx)(s,{children:`No run plan selected`}),(0,Y.jsx)(p,{children:`Select a run plan from the sidebar or create a new one`}),(0,Y.jsxs)(G,{colorPalette:`blue`,onClick:e,children:[(0,Y.jsx)(T,{size:16}),` New Run Plan`]})]})})})}var Cn=We({viewContext:`external`});function wn({scenarioSetId:e,period:t,highlightBatchId:n}){let{project:r}=ge(),{openDrawer:i}=Ne(),{highlightedBatchId:a}=mn({highlightBatchId:n}),s=(0,J.useRef)(null),c=Z(e=>e.groupBy),l=Z(e=>e.viewMode),u=Z(e=>e.filters),d=Z(e=>e.setGroupBy),p=Z(e=>e.setViewMode),h=Z(e=>e.setFilters),g=Cn.includes(c)?c:`none`,{data:_,isLoading:v,error:y}=U.scenarios.getSuiteRunData.useQuery({projectId:r?.id??``,scenarioSetId:e,limit:100,startDate:t.startDate.getTime(),endDate:t.endDate.getTime()},{enabled:!!r,refetchInterval:5e3,trpc:{context:{skipBatch:!0}}}),b=_&&`runs`in _?_.runs:void 0,{data:x}=U.scenarios.getAll.useQuery({projectId:r?.id??``},{enabled:!!r}),S=(0,J.useMemo)(()=>{if(!x||!b)return[];let e=new Set(b.map(e=>e.scenarioId));return x.filter(t=>e.has(t.id)).map(e=>({id:e.id,name:e.name}))},[x,b]);(0,J.useEffect)(()=>{!u.scenarioId||S.length===0||new Set(S.map(e=>e.id)).has(u.scenarioId)||h({...u,scenarioId:``})},[u,S,h]);let C=(0,J.useMemo)(()=>{if(!b)return[];let e=b;return u.scenarioId&&(e=e.filter(e=>e.scenarioId===u.scenarioId)),u.passFailStatus===`pass`?e=e.filter(e=>e.status===q.SUCCESS):u.passFailStatus===`fail`?e=e.filter(e=>e.status===q.ERROR||e.status===q.FAILED):u.passFailStatus===`stalled`&&(e=e.filter(e=>e.status===q.STALLED)),e},[b,u.scenarioId,u.passFailStatus]),w=(0,J.useMemo)(()=>o({runs:C}),[C]),T=(0,J.useMemo)(()=>g===`none`?[]:we({runs:C}),[g,C]),{expandedIds:E,toggleExpanded:D}=un({panelKey:`external:${e}`,groupBy:g,batchRuns:w,groups:T}),ee=(0,J.useCallback)(e=>{i(`scenarioRunDetail`,{urlParams:{scenarioRunId:e.scenarioRunId}})},[i]),te=(0,J.useCallback)(()=>null,[]),ne=(0,J.useCallback)(e=>{h(e)},[h]),re=g===`none`?w.length>0:T.length>0,ie=!!(u.scenarioId||u.passFailStatus);return(0,Y.jsxs)(B,{align:`stretch`,gap:0,height:`100%`,children:[(0,Y.jsx)(W,{paddingX:6,paddingY:4,justify:`space-between`,children:(0,Y.jsxs)(B,{align:`start`,gap:0,children:[(0,Y.jsx)(z,{fontSize:`xs`,fontWeight:`bold`,color:`fg.muted`,letterSpacing:`wider`,children:`EXTERNAL SET`}),(0,Y.jsx)(z,{fontSize:`lg`,fontWeight:`semibold`,children:e})]})}),!v&&!y&&b&&b.length>0&&(0,Y.jsx)(O,{paddingX:6,paddingY:4,bg:`bg`,flexShrink:0,_after:{content:`""`,position:`absolute`,bottom:`-5px`,left:0,right:0,height:`5px`,borderTop:`1px solid var(--chakra-colors-border-muted)`,background:`linear-gradient(to bottom, color-mix(in srgb, var(--chakra-colors-border-muted) 40%, transparent), transparent)`,pointerEvents:`none`},children:(0,Y.jsx)(it,{scenarioOptions:S,filters:u,onFiltersChange:ne,groupBy:g,onGroupByChange:d,groupByOptions:Cn,viewMode:l,onViewModeChange:p})}),(0,Y.jsx)(Xt,{scrollRef:s}),(0,Y.jsxs)(B,{ref:s,align:`stretch`,gap:0,flex:1,overflow:`auto`,children:[v&&(0,Y.jsxs)(B,{paddingY:8,children:[(0,Y.jsx)(H,{}),(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,children:`Loading run data...`})]}),y&&(0,Y.jsxs)(B,{paddingY:8,children:[(0,Y.jsx)(z,{color:`red.500`,children:`Error loading run data`}),(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,children:y.message})]}),!v&&!y&&b&&b.length>0&&(0,Y.jsx)(Y.Fragment,{children:!re&&ie?(0,Y.jsx)(O,{paddingX:6,paddingY:8,textAlign:`center`,children:(0,Y.jsx)(z,{color:`fg.muted`,children:`No runs match the selected filters.`})}):(0,Y.jsx)(Y.Fragment,{children:g===`none`?w.map(e=>(0,Y.jsx)(Wt,{batchRun:e,summary:m({batchRun:e}),isExpanded:E.has(e.batchRunId),onToggle:()=>D(e.batchRunId),resolveTargetName:te,onScenarioRunClick:ee,viewMode:l,isHighlighted:a===e.batchRunId},e.batchRunId)):T.map(e=>(0,Y.jsx)(Yt,{group:e,summary:f({group:e}),isExpanded:E.has(e.groupKey),onToggle:()=>D(e.groupKey),onScenarioRunClick:ee,resolveTargetName:te,viewMode:l},e.groupKey))})}),!v&&!y&&(!b||b.length===0)&&(0,Y.jsx)(B,{paddingY:8,children:(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,children:`No run data found for this set.`})})]})]})}var Tn=`all-runs`,En=`external:`;function Dn(e){return e.startsWith(En)}function On(e){return e.slice(9)}function kn(e){return`${En}${e}`}function An(){let e=Ae(),{selectedSuiteSlug:t,highlightBatchId:n}=jn({isReady:e.isReady,path:e.query.path??Mn(e.asPath)}),r=e.query.project;return{selectedSuiteSlug:t,navigateToSuite:(0,J.useCallback)(t=>{if(!r)return;let n={};typeof e.query.startDate==`string`&&(n.startDate=e.query.startDate),typeof e.query.endDate==`string`&&(n.endDate=e.query.endDate);let i;i=t===`all-runs`?[]:Dn(t)?[On(t)]:[`run-plans`,t];let a=i.length>0?`/${r}/simulations/${i.join(`/`)}`:`/${r}/simulations`,o=Object.entries(n).map(([e,t])=>`${e}=${encodeURIComponent(t)}`).join(`&`),s=o?`${a}?${o}`:a;e.push({pathname:`/[project]/simulations/[[...path]]`,query:{project:r,...i.length>0?{path:i}:{},...n}},s,{shallow:!0})},[e,r]),highlightBatchId:n}}function jn({isReady:e,path:t}){if(!e)return{selectedSuiteSlug:null,highlightBatchId:null};let n=(Array.isArray(t)?t:t?[t]:[]).filter(e=>e&&!e.startsWith(`?`)&&!e.includes(`=`));return n.length===0?{selectedSuiteSlug:Tn,highlightBatchId:null}:n[0]===`run-plans`&&n.length>=2?{selectedSuiteSlug:n[1],highlightBatchId:n[2]??null}:{selectedSuiteSlug:kn(n[0]),highlightBatchId:n[1]??null}}function Mn(e){let t=(e.split(`?`)[0]?.split(`#`)[0]??``).match(/\/simulations\/(.+?)\/?$/);if(t?.[1])return t[1].split(`/`).filter(Boolean)}var Nn=`suite-sidebar-collapsed`,Pn=6;function Fn({projectSlug:e,suites:t,selectedSuiteSlug:n,runSummaries:a,externalSets:o=[],onSelectSuite:s,onRunSuite:c,onContextMenu:l,isLoading:u=!1}){let[d,f]=(0,J.useState)(``),[p,m]=(0,J.useState)(()=>{try{return localStorage.getItem(Nn)===`true`}catch{return!1}}),h=()=>{let e=!p;m(e);try{localStorage.setItem(Nn,String(e))}catch{}},g=(0,J.useMemo)(()=>{if(!d.trim())return t;let e=d.toLowerCase();return t.filter(t=>t.name.toLowerCase().includes(e))},[t,d]),_=(0,J.useMemo)(()=>[...d.trim()?o.filter(e=>e.scenarioSetId.toLowerCase().includes(d.toLowerCase())):o].sort((e,t)=>t.lastRunTimestamp-e.lastRunTimestamp),[o,d]),v=g.length===0&&_.length===0;return(0,Y.jsxs)(B,{width:p?`auto`:`280px`,minWidth:p?`auto`:`280px`,height:`100%`,align:`stretch`,gap:0,children:[!p&&(0,Y.jsx)(O,{paddingX:3,paddingBottom:2,children:(0,Y.jsx)(Se,{size:`sm`,borderRadius:`full`,placeholder:`Search...`,value:d,onChange:e=>f(e.target.value)})}),(0,Y.jsx)(O,{paddingX:p?6:2,paddingBottom:2,children:p?(0,Y.jsx)(P,{content:`All Runs`,positioning:{placement:`right`},children:(0,Y.jsx)(Ve,{"aria-label":`All Runs`,size:`sm`,width:`full`,variant:n===`all-runs`?`solid`:`ghost`,onClick:()=>s(Tn),children:(0,Y.jsx)(Be,{size:16})})}):(0,Y.jsx)(In,{icon:(0,Y.jsx)(Be,{size:14}),label:`All Runs`,href:`/${e}/simulations`,isSelected:n===Tn,onClick:()=>s(Tn)})}),(0,Y.jsx)(Xt,{}),(0,Y.jsxs)(B,{flex:1,overflow:`auto`,paddingX:p?6:2,paddingTop:2,paddingBottom:2,gap:+!p,align:`stretch`,children:[u&&!p&&Array.from({length:Pn}).map((e,t)=>(0,Y.jsx)(re,{"data-testid":`suite-sidebar-skeleton`,height:`60px`,width:`100%`,borderRadius:`md`,marginBottom:1},t)),!u&&!p&&v&&t.length===0&&o.length===0&&(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,paddingX:2,paddingY:4,textAlign:`center`,children:`No run plans yet`}),!u&&!p&&v&&(t.length>0||o.length>0)&&(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,paddingX:2,paddingY:4,textAlign:`center`,children:`No matching run plans`}),!u&&g.map(t=>p?(0,Y.jsx)(P,{content:t.name,positioning:{placement:`right`},children:(0,Y.jsx)(Ve,{"aria-label":t.name,size:`sm`,width:`full`,variant:t.slug===n?`solid`:`ghost`,onClick:()=>s(t.slug),children:(0,Y.jsx)(Ue,{width:`22px`,height:`22px`,borderRadius:`full`,bg:t.slug===n?`transparent`:`bg.emphasized`,fontSize:`xs`,fontWeight:`bold`,children:t.name.charAt(0).toUpperCase()})})},t.id):(0,Y.jsx)(zn,{suite:t,projectSlug:e,isSelected:t.slug===n,runSummary:a?.get(t.id),onSelect:()=>s(t.slug),onRun:()=>c(t.id),onContextMenu:e=>l(e,t.id)},t.id)),!u&&_.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[!p&&(0,Y.jsx)(z,{"data-testid":`external-sets-header`,fontSize:`xs`,fontWeight:`bold`,color:`fg.muted`,letterSpacing:`wider`,paddingX:2,paddingTop:3,paddingBottom:1,children:`EXTERNAL SETS`}),p&&(0,Y.jsx)(O,{paddingY:.5,children:(0,Y.jsx)(Xt,{})}),_.map(t=>p?(0,Y.jsx)(P,{content:t.scenarioSetId,positioning:{placement:`right`},children:(0,Y.jsx)(Ve,{"aria-label":t.scenarioSetId,size:`sm`,width:`full`,variant:n===kn(t.scenarioSetId)?`solid`:`ghost`,onClick:()=>s(kn(t.scenarioSetId)),children:(0,Y.jsx)(Ue,{width:`22px`,height:`22px`,borderRadius:`full`,bg:n===kn(t.scenarioSetId)?`transparent`:`bg.emphasized`,fontSize:`xs`,fontWeight:`bold`,children:t.scenarioSetId.charAt(0).toUpperCase()})})},t.scenarioSetId):(0,Y.jsx)(Bn,{externalSet:t,projectSlug:e,isSelected:n===kn(t.scenarioSetId),onSelect:()=>s(kn(t.scenarioSetId))},t.scenarioSetId))]})]}),(0,Y.jsx)(Xt,{}),(0,Y.jsx)(W,{paddingX:p?6:3,paddingY:1.5,justify:`flex-start`,children:(0,Y.jsx)(Ve,{"aria-label":p?`Expand sidebar`:`Collapse sidebar`,size:`sm`,variant:`outline`,width:p?`full`:void 0,onClick:h,children:p?(0,Y.jsx)(r,{size:16}):(0,Y.jsx)(i,{size:16})})})]})}function In({icon:e,label:t,href:n,isSelected:r=!1,onClick:i}){return(0,Y.jsx)(W,{asChild:!0,width:`full`,paddingX:2,paddingY:1.5,borderRadius:`md`,cursor:`pointer`,bg:r?`bg.emphasized`:`transparent`,_hover:{bg:r?`bg.emphasized`:`bg.subtle`},onClick:e=>{e.metaKey||e.ctrlKey||e.button===1||(e.preventDefault(),i())},gap:2,textDecoration:`none`,color:`inherit`,children:(0,Y.jsxs)(`a`,{href:n??`#`,children:[e,(0,Y.jsx)(z,{fontSize:`sm`,children:t})]})})}function Ln({passedCount:e,failedCount:t,totalCount:n}){let r=n>0?e/n*100:null;return(0,Y.jsxs)(W,{gap:1,color:`fg.muted`,children:[(0,Y.jsx)(Qe,{passRate:r,size:`8px`}),(0,Y.jsx)(z,{fontSize:`xs`,color:Xe(r),fontWeight:`medium`,children:r===null?`-`:`${Math.round(r)}%`}),(0,Y.jsx)(z,{fontSize:`xs`,color:`gray.400`,children:`·`}),(0,Y.jsxs)(z,{fontSize:`xs`,color:`fg.subtle`,children:[e,` passed`]})]})}function Rn({isSelected:e,href:t,onClick:n,onContextMenu:r,className:i,"data-testid":a,children:o}){return(0,Y.jsx)(W,{asChild:!0,className:i,"data-testid":a,"data-selected":e||void 0,paddingX:3,position:`relative`,paddingY:3,borderRadius:`md`,cursor:`pointer`,bg:e?`bg.subtle`:`transparent`,border:e?`1px solid border.emphasized`:`none`,_hover:{bg:e?`bg.emphasized`:`bg.subtle`},onContextMenu:r,onClick:e=>{e.metaKey||e.ctrlKey||e.button===1||(e.preventDefault(),n())},justify:`space-between`,width:`full`,textDecoration:`none`,color:`inherit`,children:(0,Y.jsx)(`a`,{href:t??`#`,children:o})})}function zn({suite:e,projectSlug:t,isSelected:n,runSummary:r,onSelect:i,onRun:a,onContextMenu:o}){let s=ot();return(0,Y.jsx)(Rn,{className:`group`,"data-testid":`suite-list-item`,href:`/${t}/simulations/run-plans/${e.slug}`,isSelected:n,onClick:i,onContextMenu:o,children:(0,Y.jsxs)(B,{align:`start`,gap:0,flex:1,overflow:`hidden`,textAlign:`left`,children:[(0,Y.jsxs)(W,{gap:1.5,width:`full`,children:[(0,Y.jsx)(z,{fontSize:`13px`,fontWeight:`medium`,lineClamp:1,children:e.name||`<empty>`}),(0,Y.jsx)(Ee,{}),r?.lastRunTimestamp&&(0,Y.jsx)(z,{fontSize:`11px`,color:`fg.subtle`,flexShrink:0,whiteSpace:`nowrap`,children:_(r.lastRunTimestamp,s)}),(0,Y.jsxs)(W,{gap:0,flexShrink:0,children:[(0,Y.jsxs)(O,{as:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),a()},paddingX:1,paddingY:.5,borderRadius:`sm`,_hover:{bg:`bg.muted`},cursor:`pointer`,display:`flex`,alignItems:`center`,gap:1,flexShrink:0,children:[(0,Y.jsx)(fe,{size:12}),(0,Y.jsx)(z,{fontSize:`xs`,children:`Run`})]}),(0,Y.jsx)(O,{as:`button`,"aria-label":`Run plan options`,"data-testid":`suite-menu-button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),o(e)},paddingX:1,paddingY:.5,borderRadius:`sm`,_hover:{bg:`bg.muted`},display:`flex`,alignItems:`center`,opacity:0,_groupHover:{opacity:1},transition:`opacity 150ms`,cursor:`pointer`,children:(0,Y.jsx)(d,{size:14})})]})]}),r&&(0,Y.jsx)(Ln,{passedCount:r.passedCount,failedCount:r.failedCount,totalCount:r.totalCount})]})})}function Bn({externalSet:e,projectSlug:t,isSelected:n,onSelect:r}){let i=ot();return(0,Y.jsx)(Rn,{"data-testid":`external-set-list-item`,href:`/${t}/simulations/${e.scenarioSetId}`,isSelected:n,onClick:r,children:(0,Y.jsxs)(B,{align:`start`,gap:0,flex:1,overflow:`hidden`,textAlign:`left`,children:[(0,Y.jsxs)(W,{gap:1.5,width:`full`,children:[(0,Y.jsx)(z,{fontSize:`13px`,fontWeight:`medium`,lineClamp:1,children:e.scenarioSetId||`<empty>`}),(0,Y.jsx)(Ee,{}),e.lastRunTimestamp&&(0,Y.jsx)(z,{fontSize:`11px`,color:`fg.subtle`,flexShrink:0,whiteSpace:`nowrap`,children:_(e.lastRunTimestamp,i)})]}),(0,Y.jsx)(Ln,{passedCount:e.passedCount,failedCount:e.failedCount,totalCount:e.totalCount})]})})}function Vn(e={}){let{project:t}=ge(),{openDrawer:n}=Ne(),r=U.useContext(),i=(0,J.useRef)(e);i.current=e;let[a,o]=(0,J.useState)(null),[s,c]=(0,J.useState)(null),l=U.suites.run.useMutation({onSuccess:(e,t)=>{if(r.scenarios.getSuiteRunData.invalidate(),o(null),(e.skippedArchived?.scenarios?.length??0)+(e.skippedArchived?.targets?.length??0)>0){let r=[];e.skippedArchived.scenarios.length>0&&r.push(`${e.skippedArchived.scenarios.length} archived scenario${e.skippedArchived.scenarios.length>1?`s`:``}`),e.skippedArchived.targets.length>0&&r.push(`${e.skippedArchived.targets.length} archived target${e.skippedArchived.targets.length>1?`s`:``}`),K.create({title:`Run plan scheduled (${e.jobCount} jobs)`,description:`${r.join(` and `)} skipped.`,type:`warning`,meta:{closable:!0},action:{label:`Edit Run Plan`,onClick:()=>{n(`suiteEditor`,{urlParams:{suiteId:t.id}})}}})}else K.create({title:`Run plan scheduled (${e.jobCount} jobs)`,type:`success`,meta:{closable:!0}});i.current.onRunScheduled?.(t.id,t.batchRunId??e.batchRunId)},onError:(e,t)=>{o(null),c(null);let r=e.data?.code===`BAD_REQUEST`&&(e.message.includes(`All scenarios`)||e.message.includes(`All targets`));K.create({title:r?`Cannot start run plan`:`Run plan failed to start`,description:e.message,type:`error`,meta:{closable:!0},...r?{action:{label:`Edit Run Plan`,onClick:()=>{n(`suiteEditor`,{urlParams:{suiteId:t.id}})}}}:{}})}}),u=(0,J.useCallback)(e=>{!t||l.isPending||o(e)},[t,l.isPending]),d=(0,J.useCallback)(()=>{if(!t||!a||l.isPending)return;let e=be(ke.SCENARIO_BATCH).toString();c(e),l.mutate({projectId:t.id,id:a.id,idempotencyKey:crypto.randomUUID(),batchRunId:e})},[t,a,l]),f=(0,J.useCallback)(()=>{l.isPending||o(null)},[l.isPending]),{data:p}=U.scenarios.getAll.useQuery({projectId:t?.id??``},{enabled:!!t&&!!a}),m=(0,J.useMemo)(()=>{if(!a||!p)return a?.scenarioIds.length??0;let e=new Set(p.map(e=>e.id));return a.scenarioIds.filter(t=>e.has(t)).length},[a,p]),h=(0,J.useMemo)(()=>a?me(a.targets).length:0,[a]);return{requestRun:u,confirmRun:d,cancelRun:f,isPending:l.isPending,pendingBatchRunId:s,dialogProps:{open:!!a,onClose:f,onConfirm:d,suiteName:a?.name??``,scenarioCount:m,targetCount:h,repeatCount:a?.repeatCount??1,isLoading:l.isPending}}}function Hn({open:e,onClose:t,onConfirm:n,suiteName:r,scenarioCount:i,targetCount:a,repeatCount:o=1,isLoading:s=!1}){let c=i*a*o;return(0,Y.jsx)(L.Root,{open:e,onOpenChange:()=>{s||t()},placement:`center`,children:(0,Y.jsxs)(L.Content,{bg:`bg`,maxWidth:`500px`,onClick:e=>e.stopPropagation(),children:[!s&&(0,Y.jsx)(L.CloseTrigger,{}),(0,Y.jsx)(L.Header,{children:(0,Y.jsx)(L.Title,{children:r})}),(0,Y.jsx)(L.Body,{children:(0,Y.jsxs)(B,{align:`stretch`,gap:4,children:[(0,Y.jsxs)(z,{fontWeight:`semibold`,children:[` `,`Run `,c,` `,c===1?`simulation`:`simulations`,`?`]}),(0,Y.jsxs)(W,{gap:6,children:[(0,Y.jsxs)(B,{gap:0,align:`start`,children:[(0,Y.jsxs)(W,{gap:1.5,align:`center`,children:[(0,Y.jsx)(qe,{size:14,color:`var(--chakra-colors-fg-muted)`}),(0,Y.jsx)(z,{fontSize:`lg`,fontWeight:`semibold`,children:i})]}),(0,Y.jsx)(z,{color:`fg.muted`,fontSize:`sm`,children:i===1?`scenario`:`scenarios`})]}),(0,Y.jsxs)(B,{gap:0,align:`start`,children:[(0,Y.jsxs)(W,{gap:1.5,align:`center`,children:[(0,Y.jsx)($e,{size:14,color:`var(--chakra-colors-fg-muted)`}),(0,Y.jsx)(z,{fontSize:`lg`,fontWeight:`semibold`,children:a})]}),(0,Y.jsx)(z,{color:`fg.muted`,fontSize:`sm`,children:a===1?`target`:`targets`})]}),o>1&&(0,Y.jsxs)(B,{gap:0,align:`start`,children:[(0,Y.jsxs)(W,{gap:1.5,align:`center`,children:[(0,Y.jsx)(D,{size:14,color:`var(--chakra-colors-fg-muted)`}),(0,Y.jsxs)(z,{fontSize:`lg`,fontWeight:`semibold`,children:[o,`x`]})]}),(0,Y.jsx)(z,{color:`fg.muted`,fontSize:`sm`,children:`repeats`})]})]})]})}),(0,Y.jsxs)(L.Footer,{children:[(0,Y.jsx)(G,{variant:`outline`,onClick:e=>{e.stopPropagation(),t()},disabled:s,children:`Cancel`}),(0,Y.jsx)(G,{colorPalette:`blue`,onClick:e=>{e.stopPropagation(),n()},disabled:s,children:s?(0,Y.jsx)(H,{size:`sm`}):`Run ${c} ${c===1?`Job`:`Jobs`}`})]})]})})}var Un=6e4;function Wn({intervalMs:e=Un,children:t}){let[n,r]=(0,J.useState)(()=>Date.now());return(0,J.useEffect)(()=>{let t=setInterval(()=>r(Date.now()),e);return()=>clearInterval(t)},[e]),(0,Y.jsx)(at,{value:n,children:t})}function Gn(){let{project:e}=ge(),{openDrawer:t,setFlowCallbacks:n}=Ne(),r=U.useContext(),{selectedSuiteSlug:i,navigateToSuite:a,highlightBatchId:o}=An(),s=Ae();(0,J.useEffect)(()=>{if(!s.isReady)return;let e=s.query.openRun;if(typeof e==`string`&&e){t(`scenarioRunDetail`,{urlParams:{scenarioRunId:e}});let{openRun:n,...r}=s.query;s.replace({pathname:s.pathname,query:r},void 0,{shallow:!0})}},[s.isReady]);let[c,l]=(0,J.useState)(null);(0,J.useEffect)(()=>{if(!s.isReady)return;let e=s.query.pendingBatch;if(typeof e==`string`&&e){l(e);let{pendingBatch:t,...n}=s.query;s.replace({pathname:s.pathname,query:n},void 0,{shallow:!0})}},[s.isReady]);let{period:u,mode:d,setPeriod:f,setRelativePeriod:p}=le(30),[m,h]=(0,J.useState)(null),[g,_]=(0,J.useState)(null),{data:v,isLoading:y,error:b}=U.suites.getAll.useQuery({projectId:e?.id??``},{enabled:!!e}),{data:x,isLoading:S}=U.scenarios.getExternalSetSummaries.useQuery({projectId:e?.id??``,startDate:u.startDate.getTime(),endDate:u.endDate.getTime()},{enabled:!!e,refetchInterval:15e3}),{data:C}=U.suites.getSummaries.useQuery({projectId:e?.id??``,startDate:u.startDate.getTime(),endDate:u.endDate.getTime()},{enabled:!!e,refetchInterval:3e4});Ke({projectId:e?.id??``,refetch:()=>{r.suites.getSummaries.invalidate(),r.scenarios.getExternalSetSummaries.invalidate()},enabled:!!e?.id,debounceMs:500});let w=(0,J.useMemo)(()=>{if(C)return new Map(Object.entries(C))},[C]),E=(0,J.useMemo)(()=>{let e=new Map;if(v)for(let t of v)e.set(t.id,t.name);return e},[v]),D=(0,J.useMemo)(()=>!i||i===`all-runs`||Dn(i)?null:v?.find(e=>e.slug===i)??null,[i,v]),ee=(0,J.useMemo)(()=>!i||!Dn(i)?null:On(i),[i]);(0,J.useEffect)(()=>{if(!i||i===`all-runs`)return;let e=null;if(Dn(i)&&x){let t=On(i);e=x.find(e=>e.scenarioSetId===t)?.lastRunTimestamp??null}else D&&w&&(e=w.get(D.id)?.lastRunTimestamp??null);if(e&&e<u.startDate.getTime()){let t=Math.ceil((Date.now()-e)/864e5);f(Ie(new Date,t<=30?30:t<=90?90:365),new Date)}},[i]);let ne=g?v?.find(e=>e.id===g):null,re=U.suites.archive.useMutation({onSuccess:()=>{r.suites.getAll.invalidate();let e=v?.find(e=>e.id===g);e&&e.slug===i&&a(Tn),_(null),K.create({title:`Run plan archived`,type:`success`,meta:{closable:!0}})},onError:e=>{K.create({title:`Failed to archive run plan`,description:e.message,type:`error`,meta:{closable:!0}})}}),ie=U.suites.duplicate.useMutation({onSuccess:e=>{r.suites.getAll.invalidate(),a(e.slug),K.create({title:`Run plan duplicated`,type:`success`,meta:{closable:!0}})},onError:e=>{K.create({title:`Failed to duplicate run plan`,description:e.message,type:`error`,meta:{closable:!0}})}}),{requestRun:k,isPending:A,pendingBatchRunId:ae,dialogProps:oe}=Vn({onRunScheduled:e=>{r.suites.getSummaries.invalidate();let t=v?.find(t=>t.id===e);t&&i!==t.slug&&a(t.slug)}}),j=(0,J.useCallback)(e=>{a(e.slug)},[a]),M=(0,J.useCallback)(e=>{a(e.slug),k(e)},[a,k]),se=(0,J.useCallback)(()=>{n(`suiteEditor`,{onSaved:j,onRunRequested:M}),t(`suiteEditor`)},[t,n,j,M]),N=(0,J.useCallback)(e=>{n(`suiteEditor`,{onSaved:j,onRunRequested:M}),t(`suiteEditor`,{urlParams:{suiteId:e}})},[t,n,j,M]),ce=(0,J.useCallback)(e=>{let t=v?.find(t=>t.id===e);t&&k(t)},[v,k]),P=(0,J.useCallback)(t=>{e&&ie.mutate({projectId:e.id,id:t})},[e,ie]),F=(0,J.useCallback)(t=>{e&&_(t)},[e]),I=(0,J.useCallback)(()=>{!e||!g||re.mutate({projectId:e.id,id:g})},[e,g,re]),L=(0,J.useCallback)((e,t)=>{e.preventDefault(),h({x:e.clientX,y:e.clientY,suiteId:t})},[]);return(0,Y.jsx)(Wn,{children:(0,Y.jsxs)(He,{children:[(0,Y.jsxs)(B,{width:`full`,height:`full`,gap:0,children:[(0,Y.jsx)(ue.Header,{withBorder:!1,children:(0,Y.jsxs)(W,{justify:`space-between`,align:`center`,w:`full`,children:[(0,Y.jsx)(ue.Heading,{children:`Simulations`}),(0,Y.jsxs)(W,{children:[(0,Y.jsx)(te,{period:u,mode:d,setPeriod:f,setRelativePeriod:p}),(0,Y.jsxs)(ue.HeaderButton,{onClick:se,children:[(0,Y.jsx)(T,{size:16}),` New Run Plan`]})]})]})}),(0,Y.jsxs)(W,{flex:1,width:`full`,gap:0,overflow:`hidden`,minHeight:0,children:[(0,Y.jsx)(Fn,{projectSlug:e?.slug??``,suites:v??[],selectedSuiteSlug:i,runSummaries:w,externalSets:x??[],onSelectSuite:a,onRunSuite:ce,onContextMenu:L,isLoading:y||S}),(0,Y.jsx)(O,{flex:1,height:`full`,minWidth:0,paddingBottom:3,paddingRight:4,children:(0,Y.jsx)(O,{height:`full`,width:`full`,borderRadius:`lg`,boxShadow:`0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1), 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1)`,border:`1px solid`,borderColor:`border.muted`,background:`bg.panel`,overflow:`auto`,children:(0,Y.jsx)(Kn,{error:b??null,selectedSuiteSlug:i,selectedSuite:D,selectedExternalSetId:ee,isLoading:y,onNewSuite:se,onEditSuite:N,onRunSuite:ce,isRunning:A,pendingBatchRunId:ae??c,period:u,suiteNameMap:E,highlightBatchId:o})})})]})]}),m&&(0,Y.jsx)(_n,{x:m.x,y:m.y,onEdit:()=>N(m.suiteId),onDuplicate:()=>P(m.suiteId),onArchive:()=>F(m.suiteId),onClose:()=>h(null)}),(0,Y.jsx)(gn,{open:!!g,onClose:()=>_(null),onConfirm:I,suiteName:ne?.name??``,isLoading:re.isPending}),(0,Y.jsx)(Hn,{...oe})]})})}function Kn({error:e,selectedSuiteSlug:t,selectedSuite:n,selectedExternalSetId:r,isLoading:i,onNewSuite:a,onEditSuite:o,onRunSuite:s,isRunning:c,pendingBatchRunId:l,period:u,suiteNameMap:d,highlightBatchId:f}){return e?(0,Y.jsxs)(B,{gap:4,align:`center`,py:8,children:[(0,Y.jsx)(z,{color:`red.500`,children:`Error loading simulations`}),(0,Y.jsx)(z,{fontSize:`sm`,color:`fg.muted`,children:e.message})]}):t===null?null:r?(0,Y.jsx)(wn,{scenarioSetId:r,period:u,highlightBatchId:f}):t===`all-runs`?(0,Y.jsx)(hn,{period:u,suiteNameMap:d,pendingBatchRunId:l,highlightBatchId:f}):n?(0,Y.jsx)(yn,{suite:n,onEdit:()=>o(n.id),onRun:()=>s(n.id),isRunning:c,pendingBatchRunId:l,period:u,highlightBatchId:f}):i?null:(0,Y.jsx)(Sn,{onNewSuite:a})}function qn(){let e=Ae(),t=Array.isArray(e.query.path)?e.query.path:[],n=e.query.project;return(0,J.useEffect)(()=>{if(!(!e.isReady||!n)){if(t[0]===`suites`){let t=e.query.suite,r=e.query.externalSet;typeof t==`string`&&t?e.replace(`/${n}/simulations/run-plans/${t}`):typeof r==`string`&&r?e.replace(`/${n}/simulations/${r}`):e.replace(`/${n}/simulations`);return}if(t.length===3&&t[0]!==`run-plans`){let[r,i,a]=t;e.replace(`/${n}/simulations/${r}/${i}?openRun=${a}`)}}},[e.isReady]),t[0]===`suites`||t.length===3&&t[0]!==`run-plans`?null:(0,Y.jsx)(Gn,{})}var Jn=Ye(`scenarios:view`,{layoutComponent:He})(qn);export{Jn as default};
//# sourceMappingURL=__...path__-DpBkNF3v.js.map