@testver/testver 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/LICENSE +88 -69
  2. package/README.md +6 -2
  3. package/bin/testver.js +9 -1
  4. package/dist/index.js +52650 -35771
  5. package/package.json +179 -178
  6. package/src/ui/static/agents/antigravity.svg +76 -0
  7. package/src/ui/static/agents/codex.svg +3 -0
  8. package/src/ui/static/agents/gemini.svg +1 -0
  9. package/src/ui/static/agents/opencode.svg +4 -0
  10. package/src/ui/static/agents/vscode.svg +17 -0
  11. package/src/ui/static/assets/AIPanel-RWO8Cd9w.js +32 -0
  12. package/src/ui/static/assets/AIRecordPanel-DnreS585.js +40 -0
  13. package/src/ui/static/assets/AIStreamUI-C1gHJtlF.js +9 -0
  14. package/src/ui/static/assets/{AITestGenPage-D3t2gPAA.js → AITestGenPage-C8bWUelu.js} +5 -5
  15. package/src/ui/static/assets/APITestingPage-DwL67hqL.js +19 -0
  16. package/src/ui/static/assets/AboutPage-CynLB95E.js +1 -0
  17. package/src/ui/static/assets/AccessTokensTab-BdevOmpE.js +1 -0
  18. package/src/ui/static/assets/AdvancedPage-BeM7aB8b.js +3 -0
  19. package/src/ui/static/assets/{AnalyticsPage-64mYNK2v.js → AnalyticsPage-C5ddYfRk.js} +1 -1
  20. package/src/ui/static/assets/AuditLogPage-DYcUdJoj.js +1 -0
  21. package/src/ui/static/assets/ChangesSummary-BjNMwGIZ.js +3 -0
  22. package/src/ui/static/assets/{CodeMapPage-B1ezmnlE.js → CodeMapPage-BQOEtv-R.js} +3 -3
  23. package/src/ui/static/assets/{ConfirmDialog-t7mpeeSN.js → ConfirmDialog-D_N9188T.js} +1 -1
  24. package/src/ui/static/assets/{CoveragePage-YMmCbiBk.js → CoveragePage-8bDSphY1.js} +2 -2
  25. package/src/ui/static/assets/{CronBuilder-Nk-K-_8I.js → CronBuilder-C7_JADb7.js} +1 -1
  26. package/src/ui/static/assets/{Dashboard-BDVxO2V4.js → Dashboard-B22yRPyV.js} +1 -1
  27. package/src/ui/static/assets/{DefectsPage-l8yGeCyR.js → DefectsPage-Arv4Ac-b.js} +72 -72
  28. package/src/ui/static/assets/{EmptyState-D1T3JWUr.js → EmptyState-BShNSbLf.js} +1 -1
  29. package/src/ui/static/assets/{ExportButton-Dt5RhL-h.js → ExportButton-xrS_AnfS.js} +1 -1
  30. package/src/ui/static/assets/{FileViewer-CrKgh_cB.js → FileViewer-Bcr9T1jW.js} +18 -18
  31. package/src/ui/static/assets/{GitPage-_4nCEzkJ.js → GitPage-DXL2Sv40.js} +12 -12
  32. package/src/ui/static/assets/{ImportExportPage-BcR7IQi9.js → ImportExportPage-BcjzRd7T.js} +36 -36
  33. package/src/ui/static/assets/{JiraPushDialog-C2sP4_4h.js → JiraPushDialog-DNYU9Ce0.js} +1 -1
  34. package/src/ui/static/assets/{KpiTile-inmeEsy3.js → KpiTile-BKlWqjgN.js} +1 -1
  35. package/src/ui/static/assets/{LiveExecutionView-D5BRe9jq.js → LiveExecutionView-1LlyEDEe.js} +1 -1
  36. package/src/ui/static/assets/{ManagePage-B8iG6Q0B.js → ManagePage-SvRQ6L19.js} +1 -1
  37. package/src/ui/static/assets/{MediaModal-C5n6sHYi.js → MediaModal-Dyy_iHl9.js} +1 -1
  38. package/src/ui/static/assets/MobileRunPicker-Cf5rm469.js +1 -0
  39. package/src/ui/static/assets/MobileRunTarget-C4M4YJJh.js +6 -0
  40. package/src/ui/static/assets/{ModuleExplorer-VGcmK167.js → ModuleExplorer-BKVbxFZK.js} +1 -1
  41. package/src/ui/static/assets/{OutputPage-B_1nPPxE.js → OutputPage-Bi-28tJi.js} +1 -1
  42. package/src/ui/static/assets/PipelinesPanel-BtO3iSJ4.js +1 -0
  43. package/src/ui/static/assets/{ProfilePage-y7tJNNFd.js → ProfilePage-BgZ4VDC-.js} +1 -1
  44. package/src/ui/static/assets/{ProjectExplorer-DbfGhRq0.js → ProjectExplorer-BVGbmVP7.js} +1 -1
  45. package/src/ui/static/assets/{RemoteFileStrip-WuRKtx_h.js → RemoteFileStrip-dzPInzgb.js} +1 -1
  46. package/src/ui/static/assets/{ReportCard-G52Q6-2i.js → ReportCard-LOf1PXlb.js} +2 -2
  47. package/src/ui/static/assets/{ReportFullView-Bt8UFP2J.js → ReportFullView-Ce4OI8lf.js} +1 -1
  48. package/src/ui/static/assets/{ReportsPage-DMtDi73Q.js → ReportsPage-DFxCQ8cY.js} +48 -48
  49. package/src/ui/static/assets/{ResultsPage-BI9jpK2N.js → ResultsPage-DD-uj8gk.js} +115 -115
  50. package/src/ui/static/assets/{RunState-ifC4zi6M.js → RunState-DDwFB4tA.js} +1 -1
  51. package/src/ui/static/assets/{RunTargets-C7vpCbck.js → RunTargets-CkIpY3v3.js} +1 -1
  52. package/src/ui/static/assets/ScriptMappingPage-DQQoR6sR.js +1 -0
  53. package/src/ui/static/assets/{SearchableDevicePicker-BYxYJNWl.js → SearchableDevicePicker-CenIxD7b.js} +1 -1
  54. package/src/ui/static/assets/{SettingsPage-DSISg7r7.js → SettingsPage-DAV_0y0m.js} +83 -83
  55. package/src/ui/static/assets/{SharedReportView-BOqKGJmR.js → SharedReportView-CqSLFKT1.js} +1 -1
  56. package/src/ui/static/assets/{SourcesPage-CgqtYGBi.js → SourcesPage-BvqC9oKw.js} +14 -14
  57. package/src/ui/static/assets/TestExplorerPage-Bdnll77k.js +7 -0
  58. package/src/ui/static/assets/{TestManagementPage-wqYTKP7W.js → TestManagementPage-CCNE688A.js} +10 -10
  59. package/src/ui/static/assets/{TestPlansPage-DOKX9p6z.js → TestPlansPage-T6D25i6-.js} +5 -5
  60. package/src/ui/static/assets/{TestverCreditsDetail-cSW0SpNx.js → TestverCreditsDetail-BKpt4oLW.js} +1 -1
  61. package/src/ui/static/assets/{TestverCreditsRing-DpMzl3h7.js → TestverCreditsRing-CoDk5eAS.js} +1 -1
  62. package/src/ui/static/assets/TestverMcpPage-Dte0qSXp.js +34 -0
  63. package/src/ui/static/assets/{UncommittedDiffViewer-BxS0zi-p.js → UncommittedDiffViewer-BNroxCoo.js} +2 -2
  64. package/src/ui/static/assets/{UserManagementPage-B5d0uDU_.js → UserManagementPage-BU4MuDJZ.js} +10 -10
  65. package/src/ui/static/assets/{WorkflowsPage-Bk0DFnFS.js → WorkflowsPage-BP5k7AqE.js} +83 -83
  66. package/src/ui/static/assets/clipboard-BIEd7Ccc.js +1 -0
  67. package/src/ui/static/assets/{hiddenLlmProviders-CdhhNa5G.js → hiddenLlmProviders-BPORgy-e.js} +1 -1
  68. package/src/ui/static/assets/index-BlA8ntjb.js +47 -0
  69. package/src/ui/static/assets/index-Co4_SlGD.css +1 -0
  70. package/src/ui/static/assets/{index-DpQhqcHv.js → index-DLmlY2Ol.js} +1 -1
  71. package/src/ui/static/assets/{reportMeta-AKcU_qwq.js → reportMeta-B9ZRW6ts.js} +1 -1
  72. package/src/ui/static/assets/runSelected-BoPm1sz-.js +1 -0
  73. package/src/ui/static/assets/{useChartTheme-BFz2QcND.js → useChartTheme-CTIe6M63.js} +1 -1
  74. package/src/ui/static/assets/{useDebouncedValue-BsHptIvX.js → useDebouncedValue-C9odz7b2.js} +1 -1
  75. package/src/ui/static/assets/{useFeatureFlags-DNkIctil.js → useFeatureFlags-B4Otsv-N.js} +1 -1
  76. package/src/ui/static/assets/{useJiraConnector-D5ysBBvz.js → useJiraConnector--JZhbYrT.js} +1 -1
  77. package/src/ui/static/assets/{useOwnership-U0AfKBRo.js → useOwnership-BhPOiYzy.js} +1 -1
  78. package/src/ui/static/assets/useSuites-GN_K2mHc.js +1 -0
  79. package/src/ui/static/assets/{useTabParam-ChbOedP1.js → useTabParam-CyYAP90W.js} +1 -1
  80. package/src/ui/static/assets/{useTestExplorer-DT8frjCK.js → useTestExplorer-BGhkGHKy.js} +1 -1
  81. package/src/ui/static/assets/{useTestLifecycle-OcwQaB1s.js → useTestLifecycle-DX5ES6x8.js} +1 -1
  82. package/src/ui/static/assets/{useTestManagement-Xm4Bcx3u.js → useTestManagement-ommXjx0q.js} +2 -2
  83. package/src/ui/static/assets/useTestResults-DWjvm8gm.js +1 -0
  84. package/src/ui/static/assets/{vendor-charts-DWFQlmCz.js → vendor-charts-By5uZ93z.js} +1 -1
  85. package/src/ui/static/assets/{vendor-flow-YGpC9U9I.js → vendor-flow-B61ZV-pm.js} +1 -1
  86. package/src/ui/static/assets/{vendor-icons-BKPiFyYV.js → vendor-icons-Cm92aSc5.js} +1426 -1421
  87. package/src/ui/static/assets/vendor-query-DkZSMtfn.js +1 -0
  88. package/src/ui/static/assets/{vendor-quill-W-RoQfb6.js → vendor-quill-xJF2Jvjc.js} +1 -1
  89. package/src/ui/static/assets/{vendor-react-CTbHBddL.js → vendor-react-DOVfxdUy.js} +1 -1
  90. package/src/ui/static/index.html +479 -479
  91. package/src/ui/static/assets/AIPanel-B_R-CbrF.js +0 -32
  92. package/src/ui/static/assets/AIRecordPanel-BRQWIU5h.js +0 -40
  93. package/src/ui/static/assets/AIStreamUI-C3D989_6.js +0 -9
  94. package/src/ui/static/assets/APITestingPage-Cmwkiiys.js +0 -19
  95. package/src/ui/static/assets/AboutPage-CjEqKB-q.js +0 -1
  96. package/src/ui/static/assets/AdvancedPage-4kAcpE8Y.js +0 -3
  97. package/src/ui/static/assets/AuditLogPage-BQjOzQje.js +0 -1
  98. package/src/ui/static/assets/ChangesSummary-CY_Vb27i.js +0 -2
  99. package/src/ui/static/assets/DiffViewer-BIU09a_i.js +0 -2
  100. package/src/ui/static/assets/MobileRunPicker-0h-N2c6d.js +0 -1
  101. package/src/ui/static/assets/MobileRunTarget-Bo_xekig.js +0 -6
  102. package/src/ui/static/assets/PipelinesPanel-PmmPu8pj.js +0 -1
  103. package/src/ui/static/assets/ScriptMappingPage-7vHuvhQw.js +0 -1
  104. package/src/ui/static/assets/TestExplorerPage-gYLhCD4d.js +0 -7
  105. package/src/ui/static/assets/index-BYVxKLrT.js +0 -47
  106. package/src/ui/static/assets/index-C2KJt7SI.css +0 -1
  107. package/src/ui/static/assets/runSelected-WlgnZcSF.js +0 -1
  108. package/src/ui/static/assets/useSuites-DyfN9HVv.js +0 -1
  109. package/src/ui/static/assets/useTestResults-D5EwGIX9.js +0 -1
  110. package/src/ui/static/assets/vendor-query-BrzmPFT3.js +0 -1
@@ -0,0 +1,3 @@
1
+ import{r as l,j as e,u as at,n as wt}from"./vendor-react-DOVfxdUy.js";import{u as kt}from"./useTabParam-CyYAP90W.js";import{u as pe,a as Ct}from"./vendor-query-DkZSMtfn.js";import{s as St,k as rt,l as Rt,m as Pt,n as zt,o as Tt,p as Et,q as It,t as $t,v as De,w as At,b as nt,c as Dt,d as Lt,x as lt,y as ot,z as it,R as Ft,A as Mt,C as qt,D as Bt,E as Vt,F as Kt,G as _t,H as Ht,I as Ot,J as We,K as Gt,M as Ut}from"./index-BlA8ntjb.js";import{p as Wt,s as Qt}from"./ansiToHtml-DYRzYQV1.js";import{aw as Xt,v as ct,aq as le,C as se,a1 as me,b2 as Jt,b3 as Yt,ao as Zt,$ as es,au as ne,X as Le,b4 as ts,S as Ee,p as ss,c as dt,z as as,w as rs,b5 as ue,ah as Qe,b6 as ns,b7 as ls,b8 as Ie,a3 as xe,b9 as Xe,ba as $e,K as Ae,G as os,a4 as ke,bb as Je,bc as is}from"./vendor-icons-Cm92aSc5.js";import{M as mt,R as cs}from"./MobileRunTarget-C4M4YJJh.js";import{L as ds}from"./LiveExecutionView-1LlyEDEe.js";import{R as ms}from"./RunState-DDwFB4tA.js";import{h as us}from"./aiHandoff-vhtR29Fh.js";import{e as xs,b as Ne}from"./runSelected-BoPm1sz-.js";import{C as ps}from"./ConfirmDialog-D_N9188T.js";import{s as fs}from"./visibleInterval-BKsLfJZ3.js";import{f as Ye}from"./formatDate-T65-Y6Mi.js";import{C as hs,i as bs}from"./CronBuilder-C7_JADb7.js";import"./SearchableDevicePicker-CenIxD7b.js";const we=5e3;function gs(o){const[t,i]=l.useState(null),[r,u]=l.useState([]),[m,c]=l.useState(null),[f,h]=l.useState(null),p=l.useRef([]),b=l.useRef(null),g=l.useCallback(()=>{const d=b.current;(d==null?void 0:d.raf)!=null&&cancelAnimationFrame(d.raf),(d==null?void 0:d.timer)!=null&&clearTimeout(d.timer),b.current=null;const k=p.current;k.length!==0&&(p.current=[],u(B=>{const F=B.concat(k);return F.length>we?F.slice(F.length-we):F}))},[]),N=l.useCallback(()=>{b.current||(b.current=typeof document<"u"&&document.hidden?{timer:setTimeout(g,100)}:{raf:requestAnimationFrame(g)})},[g]),z=l.useCallback(()=>{const d=b.current;(d==null?void 0:d.raf)!=null&&cancelAnimationFrame(d.raf),(d==null?void 0:d.timer)!=null&&clearTimeout(d.timer),b.current=null,p.current=[],u([])},[]);l.useEffect(()=>()=>{const d=b.current;(d==null?void 0:d.raf)!=null&&cancelAnimationFrame(d.raf),(d==null?void 0:d.timer)!=null&&clearTimeout(d.timer)},[]),l.useEffect(()=>{const d=()=>{document.hidden||g()};return document.addEventListener("visibilitychange",d),()=>document.removeEventListener("visibilitychange",d)},[g]),l.useEffect(()=>o(d=>{d.type==="output"&&d.runId===(t==null?void 0:t.runId)&&(h(null),p.current.push({stream:d.stream,data:d.data}),p.current.length>we&&(p.current=p.current.slice(p.current.length-we)),N()),d.type==="run-waiting-input"&&d.runId===(t==null?void 0:t.runId)&&h(d.prompt),d.type==="complete"&&t&&d.runId===t.runId&&(g(),c({runId:t.runId,command:t.command,startTime:"",status:d.exitCode===0?"completed":"failed",exitCode:d.exitCode,duration:d.duration}),i(null),h(null))}),[o,t,g,N]);const I=l.useCallback(async d=>{z(),c(null);const k=await St(d);return i({runId:k.runId,command:k.command}),k},[z]),L=l.useCallback(async()=>{t&&(await rt(t.runId),i(null),h(null))},[t]),x=l.useCallback(async(d,k=!1)=>{t&&(h(null),await Rt(t.runId,k?{eof:!0}:{data:d}))},[t]),y=l.useCallback((d,k)=>{z(),c(null),i({runId:d,command:k})},[z]);return{activeRun:t,output:r,runResult:m,run:I,cancel:L,attachToRun:y,waitingPrompt:f,sendInput:x}}function ys(){return pe({queryKey:["runHistory"],queryFn:Pt,refetchInterval:5e3})}function js(o,t){const[i,r]=l.useState({current:0,total:0,currentTestName:"",passed:0,failed:0,tests:[],elapsedMs:0,summary:null}),u=l.useRef(null),m=l.useRef(null),c=l.useCallback(()=>{u.current=null,m.current&&(clearInterval(m.current),m.current=null),r({current:0,total:0,currentTestName:"",passed:0,failed:0,tests:[],elapsedMs:0,summary:null})},[]);return l.useEffect(()=>(t?(r({current:0,total:0,currentTestName:"",passed:0,failed:0,tests:[],elapsedMs:0,summary:null}),u.current=Date.now(),m.current=setInterval(()=>{u.current&&r(f=>({...f,elapsedMs:Date.now()-u.current}))},500)):!t&&u.current&&m.current&&(clearInterval(m.current),m.current=null),()=>{m.current&&(clearInterval(m.current),m.current=null)}),[t]),l.useEffect(()=>{if(t)return o(f=>{const h=f.runId;if(!(h&&h!==t)&&(f.type==="test-progress"&&r(p=>({...p,current:f.current,total:f.total||p.total,currentTestName:f.testName})),f.type==="test-passed"&&r(p=>({...p,passed:p.passed+1,tests:[...p.tests,{name:f.testName,status:"passed",duration:f.duration}]})),f.type==="test-failed"&&r(p=>({...p,failed:p.failed+1,tests:[...p.tests,{name:f.testName,status:"failed",duration:f.duration}]})),f.type==="test-results")){const p=f.summary;r(b=>({...b,summary:{runId:t,...p}}))}})},[o,t]),{...i,reset:c}}function vs(o){const t=[];let i="",r="stdout";for(const u of o){if(u.stream!==r&&i){const m=i.split(`
2
+ `);for(const c of m)c&&t.push({stream:r,data:c});i=""}r=u.stream,i+=u.data}if(i){const u=i.split(`
3
+ `);for(const m of u)m&&t.push({stream:r,data:m})}return t}function Ns({output:o}){const t=l.useRef(null);l.useEffect(()=>{t.current&&(t.current.scrollTop=t.current.scrollHeight)},[o]);const i=l.useMemo(()=>vs(o),[o]);return e.jsxs("div",{ref:t,className:"flex-1 overflow-auto bg-black/40 rounded-lg p-4 font-mono text-xs leading-5",children:[i.length===0&&e.jsx("span",{className:"text-gray-600",children:"Waiting for output..."}),i.map((r,u)=>e.jsx(ws,{data:r.data,stream:r.stream},u))]})}const ws=l.memo(function({data:t,stream:i}){var m,c,f;const r=l.useMemo(()=>Wt(t),[t]),u=i==="stderr"?"text-red-400":i==="stdin"?"text-cyan-300":"text-gray-200";return i==="stdin"?e.jsxs("div",{className:u,children:[e.jsx("span",{className:"text-cyan-500/70 select-none",children:"› "}),t==="^D"?"^D (end of input)":t]}):r.length<=1&&!((m=r[0])!=null&&m.style.color)&&!((c=r[0])!=null&&c.style.bold)&&!((f=r[0])!=null&&f.style.dim)?e.jsx("div",{className:u,children:t}):e.jsx("div",{className:u,children:r.map((h,p)=>{const b=Qt(h.style);return Object.keys(b).length>0?e.jsx("span",{style:b,children:h.text},p):e.jsx("span",{children:h.text},p)})})});function ks(){const{data:o,isLoading:t}=ys(),i=(o==null?void 0:o.history)??[];return t?e.jsx("div",{className:"text-xs text-gray-500 p-3",children:"Loading history..."}):i.length===0?e.jsx("div",{className:"text-xs text-gray-500 p-4 text-center",children:"No previous runs"}):e.jsx("div",{className:"space-y-1.5 max-h-72 overflow-y-auto",children:i.map(r=>e.jsx(Cs,{run:r},r.runId))})}function Cs({run:o}){const t={completed:e.jsx(se,{size:14,className:"text-emerald-400"}),failed:e.jsx(le,{size:14,className:"text-red-400"}),running:e.jsx(ct,{size:14,className:"text-amber-400 animate-pulse"}),cancelled:e.jsx(Xt,{size:14,className:"text-gray-400"})};return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-surface-2 border border-white/5 text-xs",children:[t[o.status],e.jsx("span",{className:"font-mono text-gray-300 flex-1 truncate",children:o.command}),o.duration!=null&&e.jsxs("span",{className:"text-gray-500",children:[(o.duration/1e3).toFixed(1),"s"]}),o.startTime&&e.jsx("span",{className:"text-gray-600 text-[10px]",children:new Date(o.startTime).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})}function Ss({current:o,passed:t,failed:i,currentTestName:r,tests:u,elapsedMs:m}){const c=t+i,f=Math.round(m/1e3);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex-1 bg-surface-2 rounded-full h-2 overflow-hidden",children:e.jsx("div",{className:"h-full flex",children:c>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bg-emerald-500 transition-all",style:{width:`${t/Math.max(c,1)*100}%`}}),e.jsx("div",{className:"bg-red-500 transition-all",style:{width:`${i/Math.max(c,1)*100}%`}})]})})}),e.jsxs("span",{className:"text-xs text-gray-500 flex-shrink-0",children:[f,"s"]})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[e.jsxs("span",{className:"text-gray-400",children:["Test #",o]}),e.jsxs("span",{className:"text-emerald-400 flex items-center gap-1",children:[e.jsx(se,{size:12})," ",t]}),e.jsxs("span",{className:"text-red-400 flex items-center gap-1",children:[e.jsx(le,{size:12})," ",i]}),r&&e.jsxs("span",{className:"text-gray-500 flex items-center gap-1 truncate",children:[e.jsx(me,{size:12,className:"animate-spin"}),e.jsx("span",{className:"truncate",children:r})]})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto space-y-0.5",children:u.slice(-30).map((h,p)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs py-0.5 animate-slide-in",children:[h.status==="passed"?e.jsx(se,{size:12,className:"text-emerald-400 flex-shrink-0"}):e.jsx(le,{size:12,className:"text-red-400 flex-shrink-0"}),e.jsx("span",{className:`truncate ${h.status==="passed"?"text-gray-400":"text-red-300"}`,children:h.name})]},p))})]})}function Rs({runId:o,summary:t,onRerunFailed:i}){const r=at(),u=t.passRate>=90?"text-emerald-400":t.passRate>=70?"text-amber-400":"text-red-400",m=t.passRate>=90?"bg-emerald-500/10":t.passRate>=70?"bg-amber-500/10":"bg-red-500/10",c=t.failed===0,f=()=>r(`/results?runId=${encodeURIComponent(o)}`);return e.jsxs("div",{className:`rounded-xl border border-white/5 px-4 py-2.5 ${m} flex items-center gap-x-4 gap-y-2 flex-wrap`,children:[e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[c?e.jsx(se,{size:16,className:"text-emerald-400"}):e.jsx(le,{size:16,className:"text-red-400"}),e.jsx("span",{className:"text-sm font-semibold text-gray-200",children:"Run Complete"}),e.jsxs("span",{className:"text-xs text-gray-500",children:["· ",(t.duration/1e3).toFixed(1),"s"]})]}),e.jsx("span",{className:"w-px h-5 bg-white/10 hidden sm:block"}),e.jsxs("div",{className:"flex items-center gap-3.5 text-sm tabular-nums",children:[e.jsxs("span",{className:"text-gray-300",children:[e.jsx("span",{className:"font-bold text-gray-100",children:t.total})," ",e.jsx("span",{className:"text-gray-500 text-xs",children:"total"})]}),e.jsxs("span",{className:"flex items-center gap-1 text-emerald-400",title:"Passed",children:[e.jsx(se,{size:13})," ",t.passed]}),e.jsxs("span",{className:`flex items-center gap-1 ${t.failed>0?"text-red-400":"text-gray-500"}`,title:"Failed",children:[e.jsx(le,{size:13})," ",t.failed]}),e.jsxs("span",{className:"flex items-center gap-1 text-gray-500",title:"Skipped",children:[e.jsx(Jt,{size:13})," ",t.skipped]}),e.jsxs("span",{className:`font-bold ${u}`,children:[t.passRate,"%",e.jsx("span",{className:"text-gray-500 text-xs font-normal ml-1",children:"pass"})]})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2 flex-shrink-0",children:[t.failed>0&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:f,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-purple-500/15 text-purple-300 text-xs font-medium hover:bg-purple-500/25 transition-colors",children:[e.jsx(Yt,{size:12})," Analyze"]}),i&&e.jsxs("button",{onClick:i,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-surface-2 text-gray-300 text-xs font-medium hover:bg-surface-3 transition-colors",children:[e.jsx(Zt,{size:12})," Re-run Failed"]})]}),e.jsxs("button",{onClick:f,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-surface-2 text-gray-300 text-xs font-medium hover:bg-surface-3 transition-colors",children:[e.jsx(es,{size:12})," View Details"]})]})]})}function Ps({open:o,analysis:t,providerLabel:i,onAiFix:r,onSkipAndRun:u,onCancel:m}){return o?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60",onClick:m}),e.jsxs("div",{className:"relative bg-surface-1 rounded-xl border border-white/10 p-0 w-[760px] max-w-[92vw] max-h-[85vh] animate-fade-in flex flex-col",children:[e.jsx("div",{className:"px-6 pt-5 pb-4 border-b border-white/5",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center flex-shrink-0 bg-amber-500/15",children:e.jsx(ne,{size:20,className:"text-amber-400"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-base font-semibold text-gray-100",children:["Not connected to ",i," yet"]}),e.jsx("p",{className:"text-sm text-gray-400 mt-0.5",children:"This project's driver setup doesn't honor Testver's cloud settings — the run would silently execute on a local browser."})]})]}),e.jsx("button",{onClick:m,className:"text-gray-500 hover:text-gray-300 p-1",children:e.jsx(Le,{size:18})})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-4",children:[e.jsxs("div",{className:"bg-surface-2 rounded-lg p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-gray-400 uppercase tracking-wide",children:[e.jsx(ts,{size:14}),"Detection Summary"]}),e.jsxs("div",{className:"grid grid-cols-[140px_1fr] gap-x-4 gap-y-1.5 text-sm",children:[e.jsx("div",{className:"text-gray-500",children:"Framework:"}),e.jsx("div",{className:"text-gray-200",children:t.framework||"Unknown"}),e.jsx("div",{className:"text-gray-500",children:"Language:"}),e.jsx("div",{className:"text-gray-200",children:t.language||"Unknown"}),e.jsx("div",{className:"text-gray-500",children:"Driver file (guess):"}),e.jsx("div",{className:"text-gray-200 font-mono text-xs break-all",children:t.hookFile||"Not located"})]}),e.jsx("p",{className:"text-[11px] text-gray-500 pt-1",children:"The driver file is a best-guess from a code scan — the AI Assistant verifies it (and looks for other driver-creation sites) before touching anything."})]}),e.jsxs("div",{className:"bg-brand-500/10 border border-brand-500/20 rounded-lg p-4 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-brand-300",children:[e.jsx(Ee,{size:15}),"Fix with AI Assistant"]}),e.jsxs("p",{className:"text-sm text-gray-300",children:["The AI Assistant makes the smallest change that connects this framework to ",i,", runs one test to verify, and confirms real cloud execution from the run's ground-truth verdict — self-correcting if verification fails, and undoing everything if it can't succeed."]}),e.jsx("p",{className:"text-xs text-gray-500",children:"You'll see every edit and the verification run in the AI Assistance screen. Requires an AI provider (Settings → LLM). Verification runs use a small amount of cloud minutes."})]}),e.jsxs("div",{className:"bg-surface-2 rounded-lg p-3 flex items-start gap-2",children:[e.jsx(ss,{size:14,className:"text-gray-500 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-xs text-gray-500",children:'"Run anyway" injects the cloud environment variables and runs as-is — if your code already reads them this works, otherwise the run lands locally and its result will carry a "executed locally" warning.'})]})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-white/5 flex justify-end gap-2",children:[e.jsx("button",{onClick:m,className:"px-4 py-2 text-sm rounded-lg bg-surface-2 hover:bg-surface-3 text-gray-300",children:"Cancel"}),e.jsx("button",{onClick:u,className:"px-4 py-2 text-sm rounded-lg bg-surface-2 hover:bg-surface-3 text-gray-300 border border-white/5",children:"Run Anyway"}),e.jsxs("button",{onClick:r,className:"flex items-center gap-1.5 px-4 py-2 text-sm rounded-lg bg-brand-600 hover:bg-brand-500 text-white font-medium",children:[e.jsx(Ee,{size:14}),"Fix with AI Assistant"]})]})]})]}):null}const zs="testver-runner-recent",Ze="testver-runner-recent",Ts=10;try{localStorage.getItem(Ze)!==null&&localStorage.removeItem(Ze)}catch{}function Es(o){return`${zs}:${o||"unknown"}`}function et(o){try{const t=localStorage.getItem(o),i=t?JSON.parse(t):[];return Array.isArray(i)?i.filter(r=>typeof r=="string"):[]}catch{return[]}}function ut(){const o=Ct(),{data:t}=pe({queryKey:["runner-commands"],queryFn:zt,staleTime:3e4}),i=(t==null?void 0:t.commands)||[],{data:r}=Tt(),u=Es(r==null?void 0:r.rootPath),m=l.useCallback(async(b,g)=>{const N=await Et(b,g);o.setQueryData(["runner-commands"],N)},[o]),c=l.useCallback(async(b,g)=>{const N=await It(b,g);o.setQueryData(["runner-commands"],N)},[o]),f=l.useCallback(async b=>{const g=await $t(b);o.setQueryData(["runner-commands"],g)},[o]),h=l.useCallback(b=>{const g=b.trim();if(!g)return;const N=[g,...et(u).filter(z=>z!==g)].slice(0,Ts);try{localStorage.setItem(u,JSON.stringify(N))}catch{}},[u]);return{saved:[...i].sort((b,g)=>(g.pinned?1:0)-(b.pinned?1:0)||b.label.localeCompare(g.label)),add:m,update:c,remove:f,pushRecent:h,recent:et(u)}}function Is({saved:o,recent:t,disabled:i,onPick:r,onRun:u,onSave:m,onUpdate:c,onDelete:f}){var ee,U,w;const[h,p]=l.useState(!1),[b,g]=l.useState(""),[N,z]=l.useState(!1),[I,L]=l.useState(""),[x,y]=l.useState(""),[d,k]=l.useState(null),[B,F]=l.useState(""),[M,T]=l.useState(""),[A,V]=l.useState(null),K=l.useRef(null);l.useEffect(()=>{if(!h)return;const n=P=>{A||K.current&&!K.current.contains(P.target)&&p(!1)};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[h,A]);const{data:D}=pe({queryKey:["run-commands-config"],queryFn:De,staleTime:1e4}),ae=(((U=(ee=D==null?void 0:D.configured)==null?void 0:ee.fullRun)==null?void 0:U.trim())||((w=D==null?void 0:D.autoDetected)==null?void 0:w.fullRun)||"").trim(),W=ae?[{label:"Run All",command:ae}]:[],$=b.trim().toLowerCase(),a=(n,P)=>!$||n.toLowerCase().includes($)||P.toLowerCase().includes($),v=o.filter(n=>a(n.label,n.command)),E=W.filter(n=>a(n.label,n.command)),Q=t.filter(n=>a(n,n)),O=n=>{r(n),p(!1)},X=n=>{u(n),p(!1)},_=()=>{z(!1),L(""),y("")},fe=()=>{const n=I.trim(),P=x.trim();n&&P&&(m(n,P),_())},J=n=>{k(n.id),F(n.label),T(n.command)},oe=n=>{B.trim()&&M.trim()&&(c(n,{label:B.trim(),command:M.trim()}),k(null))};return e.jsxs("div",{className:"relative flex-shrink-0",ref:K,children:[e.jsxs("button",{type:"button",onClick:()=>p(n=>!n),disabled:i,title:"Saved commands, presets & recent",className:"flex items-center gap-1.5 px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm font-medium text-gray-300 hover:text-gray-100 hover:border-white/20 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx(dt,{size:15}),e.jsx("span",{children:"Commands"}),e.jsx(as,{size:13,className:`transition-transform ${h?"rotate-180":""}`})]}),h&&e.jsxs("div",{className:"absolute right-0 top-full mt-2 z-50 w-[420px] max-h-[70vh] overflow-hidden flex flex-col rounded-xl bg-white dark:bg-surface-1 border border-gray-200 dark:border-white/10 shadow-2xl",children:[e.jsx("div",{className:"p-2 border-b border-gray-100 dark:border-white/5",children:e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 rounded-lg bg-gray-100 dark:bg-surface-2",children:[e.jsx(rs,{size:13,className:"text-gray-400"}),e.jsx("input",{autoFocus:!0,value:b,onChange:n=>g(n.target.value),placeholder:"Search commands…",className:"flex-1 bg-transparent text-sm text-gray-700 dark:text-gray-200 outline-none placeholder-gray-400"}),b&&e.jsx("button",{onClick:()=>g(""),children:e.jsx(Le,{size:13,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-200"})})]})}),e.jsxs("div",{className:"overflow-y-auto",children:[e.jsx("div",{className:"p-2 border-b border-gray-100 dark:border-white/5",children:N?e.jsxs("div",{className:"space-y-2 px-1 py-1",children:[e.jsx("input",{autoFocus:!0,value:I,onChange:n=>L(n.target.value),onKeyDown:n=>{n.key==="Escape"&&_()},placeholder:"Command name (e.g. Smoke — headed)",className:"w-full bg-gray-100 dark:bg-surface-2 rounded-lg px-2.5 py-1.5 text-sm text-gray-700 dark:text-gray-200 outline-none placeholder-gray-400"}),e.jsx("input",{value:x,onChange:n=>y(n.target.value),onKeyDown:n=>{n.key==="Enter"&&fe(),n.key==="Escape"&&_()},placeholder:"Command (e.g. npx playwright test --headed)",className:"w-full bg-gray-100 dark:bg-surface-2 rounded-lg px-2.5 py-1.5 text-sm font-mono text-gray-700 dark:text-gray-200 outline-none placeholder-gray-400"}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:_,className:"px-2.5 py-1.5 rounded-lg text-sm text-gray-500 hover:bg-black/5 dark:hover:bg-white/5",children:"Cancel"}),e.jsxs("button",{onClick:fe,disabled:!I.trim()||!x.trim(),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-sm font-medium bg-brand-500/15 text-brand-500 hover:bg-brand-500/25 disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(Qe,{size:14})," Add"]})]})]}):e.jsxs("button",{onClick:()=>z(!0),className:"w-full flex items-center gap-2 px-2.5 py-2 rounded-lg text-sm font-medium text-brand-600 dark:text-brand-300 hover:bg-brand-500/10 transition-colors",children:[e.jsx(ue,{size:14})," Add Command"]})}),v.length>0&&e.jsx(ze,{title:"Saved",children:v.map(n=>d===n.id?e.jsxs("div",{className:"space-y-2 px-3 py-2 bg-white dark:bg-surface-1",children:[e.jsx("input",{autoFocus:!0,value:B,onChange:P=>F(P.target.value),onKeyDown:P=>{P.key==="Escape"&&k(null)},placeholder:"Command name",className:"w-full bg-gray-100 dark:bg-surface-2 rounded-lg px-2.5 py-1.5 text-sm text-gray-700 dark:text-gray-200 outline-none placeholder-gray-400"}),e.jsx("input",{value:M,onChange:P=>T(P.target.value),onKeyDown:P=>{P.key==="Enter"&&oe(n.id),P.key==="Escape"&&k(null)},placeholder:"Command",className:"w-full bg-gray-100 dark:bg-surface-2 rounded-lg px-2.5 py-1.5 text-sm font-mono text-gray-700 dark:text-gray-200 outline-none placeholder-gray-400"}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>k(null),className:"px-2.5 py-1.5 rounded-lg text-sm text-gray-500 hover:bg-black/5 dark:hover:bg-white/5",children:"Cancel"}),e.jsxs("button",{onClick:()=>oe(n.id),disabled:!B.trim()||!M.trim(),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-sm font-medium bg-brand-500/15 text-brand-500 hover:bg-brand-500/25 disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(Qe,{size:14})," Save"]})]})]},n.id):e.jsx(Te,{label:n.label,command:n.command,onPick:()=>O(n.command),onRun:()=>X(n.command),actions:e.jsxs(e.Fragment,{children:[e.jsx(re,{title:n.pinned?"Unpin":"Pin",onClick:()=>c(n.id,{pinned:!n.pinned}),children:e.jsx(ns,{size:13,className:n.pinned?"fill-amber-400 text-amber-400":""})}),e.jsx(re,{title:"Edit",onClick:()=>J(n),children:e.jsx(ls,{size:13})}),e.jsx(re,{title:"Delete",onClick:()=>V(n),children:e.jsx(Ie,{size:13})})]})},n.id))}),E.length>0&&e.jsx(ze,{title:"Presets",children:E.map(n=>e.jsx(Te,{label:n.label,command:n.command,onPick:()=>O(n.command),onRun:()=>X(n.command),actions:e.jsx(re,{title:"Save to my commands",onClick:()=>m(n.label,n.command),children:e.jsx(ue,{size:13})})},n.label))}),Q.length>0&&e.jsx(ze,{title:"Recent",children:Q.map((n,P)=>e.jsx(Te,{label:n,command:n,mono:!0,onPick:()=>O(n),onRun:()=>X(n),actions:e.jsx(re,{title:"Save to my commands",onClick:()=>m(n.length>40?n.slice(0,40)+"…":n,n),children:e.jsx(ue,{size:13})})},`${n}-${P}`))}),v.length===0&&E.length===0&&Q.length===0&&e.jsxs("p",{className:"px-4 py-6 text-center text-sm text-gray-400",children:["No commands match “",b,"”."]})]})]}),e.jsx(ps,{open:!!A,title:"Delete command?",description:A?`“${A.label}” (${A.command}) will be permanently removed from your saved commands. This can’t be undone.`:"",confirmLabel:"Delete",onConfirm:()=>{A&&f(A.id),V(null)},onCancel:()=>V(null)})]})}function ze({title:o,children:t}){return e.jsxs("div",{className:"py-1",children:[e.jsx("p",{className:"px-3 pt-2 pb-1 text-[10px] font-semibold uppercase tracking-wider text-gray-400 capitalize",children:o}),t]})}function re({title:o,onClick:t,children:i}){return e.jsx("button",{type:"button",title:o,onClick:r=>{r.stopPropagation(),t()},className:"p-1.5 rounded-md text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:bg-black/5 dark:hover:bg-white/10 transition-colors",children:i})}function Te({label:o,command:t,mono:i,onPick:r,onRun:u,actions:m}){return e.jsxs("div",{className:"group flex items-center gap-1 pl-3 pr-2 py-1.5 hover:bg-black/[0.04] dark:hover:bg-white/5 transition-colors",children:[e.jsxs("button",{type:"button",onClick:r,className:"flex-1 min-w-0 text-left",title:t,children:[e.jsx("span",{className:`block text-sm text-gray-700 dark:text-gray-200 truncate ${i?"font-mono text-[13px]":"font-medium"}`,children:o}),!i&&e.jsx("span",{className:"block text-[11px] text-gray-400 font-mono truncate",children:t})]}),e.jsxs("div",{className:"flex items-center flex-shrink-0",children:[m,e.jsx(re,{title:"Run now",onClick:u,children:e.jsx(xe,{size:13,className:"text-brand-500"})})]})]})}const te={browserstack:"BrowserStack",lambdatest:"LambdaTest",saucelabs:"Sauce Labs","local-appium":"Local Devices","testver-grid":"Testver Grid"};function $s(){var He,Oe,Ge,Ue;const{project:o,subscribe:t}=wt(),{runs:i}=At(),{toast:r}=nt(),u=Dt(),m=at(),{activeRun:c,output:f,runResult:h,run:p,cancel:b,attachToRun:g,waitingPrompt:N,sendInput:z}=gs(t),[I,L]=l.useState(""),[x,y]=l.useState(!1),[d,k]=l.useState(null),B=l.useRef(null);l.useEffect(()=>{var s;N&&((s=B.current)==null||s.focus())},[N]),l.useEffect(()=>{c||(L(""),k(null))},[c]);const F=async(s=!1)=>{var j;if(!(!c||x)){y(!0),k(null);try{await z(s?"":I,s),s||L("")}catch(C){k(String((C==null?void 0:C.message)||C))}finally{y(!1),(j=B.current)==null||j.focus()}}},M=(i??[]).filter(s=>s.runId!==(c==null?void 0:c.runId)),T=js(t,(c==null?void 0:c.runId)??null),{data:A}=Lt(),V=ut(),[K,D]=l.useState(""),[ae,W]=l.useState(!1),{data:$}=pe({queryKey:["run-commands-config"],queryFn:De,staleTime:1e4}),a=(((Oe=(He=$==null?void 0:$.configured)==null?void 0:He.fullRun)==null?void 0:Oe.trim())||((Ge=$==null?void 0:$.autoDetected)==null?void 0:Ge.fullRun)||"").trim(),v=((Ue=$==null?void 0:$.autoDetected)==null?void 0:Ue.wdioSuites)??[],E=new Set(v.map(s=>s.config)).size>1,Q=[...a?[{id:"preset-run-all",label:"Run All",command:a,preset:!0}]:[],...v.map(s=>({id:`preset-wdio-suite-${s.config}-${s.name}`,label:`Suite: ${s.name}${E?` (${s.config.split("/").pop()})`:""}`,command:s.command,preset:!0})),...V.saved.map(s=>({id:s.id,label:s.label,command:s.command}))],O=K.trim().toLowerCase(),X=O?Q.filter(s=>s.command.toLowerCase()!==O&&(s.command.toLowerCase().includes(O)||s.label.toLowerCase().includes(O))):Q,[_,fe]=l.useState([]),[J,oe]=l.useState(!1),[ee,U]=l.useState("local"),w=ee,[n,P]=l.useState(""),[Fe,xt]=l.useState(!1),[q,pt]=l.useState({deviceName:"",platformName:"Android",platformVersion:"",appId:"",appPath:""}),{showsMobile:Ce,mode:Me}=lt(),ft=Me!=="mobile"&&/\bplaywright(\.cmd)?\s+test\b|\bcypress\s+run\b/i.test(K),H=Ce&&!ft&&w!=="local"&&w!=="testver-grid",he=Me==="mobile",be=he&&_.length===0&&!J,Se=!H||!!q.deviceName&&(!!q.appId||!!q.appPath.trim()),[Y,qe]=l.useState(null);l.useEffect(()=>{if(!H){qe(null);return}let s=!1;const j=()=>{Mt().then(S=>{s||qe(S.ticket)}).catch(()=>{})};j();const C=fs(j,5e3);return()=>{s=!0,C()}},[H]);const[Be,ge]=l.useState(!1),[ie,ye]=l.useState(null),[Ve,Ke]=l.useState(!1);l.useEffect(()=>{ot().then(s=>{const j=s.providers.filter(C=>C.enabled);fe(j)}).catch(()=>{}),it().then(({config:s})=>oe(!!s.enabled)).catch(()=>oe(!1))},[]),l.useEffect(()=>{if(!(!he||w!=="local"))if(J)U("local-appium");else{const s=_.filter(j=>j.id!=="testver-grid");s.length>0&&U(s[0].id)}},[he,J,_,w]);const ce=async(s,j)=>{const C=(s??K).trim(),S=j??ee;try{const R={command:C,asTyped:!0,fromRunner:!0,...S==="local"?{plainCommand:!0}:{}};S!=="local"&&(R.cloudProvider=S,n.trim()&&(R.buildName=n.trim()),S==="testver-grid"&&Fe&&(R.gridTunnel=!0),H&&!j&&(q.deviceName&&(R.deviceName=q.deviceName),q.platformName&&(R.platformName=q.platformName),q.platformVersion&&(R.platformVersion=q.platformVersion),q.appId&&(R.appId=q.appId),q.appPath.trim()&&(R.appPath=q.appPath.trim()),Y&&!Y.claimed&&Date.now()<Y.expiresAt&&(R.reuseSessionId=Y.sessionId))),await p(R),V.pushRecent(C);const Z=S==="local"?"locally":`on ${te[S]||S}`;r("info",`Test run started ${Z}`)}catch(R){r("error",R.message||"The run could not be started")}},de=(s,j)=>u(()=>ht(s,j),{files:(s??K).split(/\s+/).filter(C=>/\.(spec|test)\.|\.(ts|tsx|js|jsx|py|java|cs|feature|robot)$/.test(C))}),ht=async(s,j)=>{const C=(s??K).trim(),S=j??ee;if(!C){r("error","Please enter a run command");return}if(s!==void 0&&D(s),be){r("error","Connect a device or enable a cloud grid in Connectors first");return}if(H&&!j&&!Se){r("error","Select a device and an app first");return}if(S==="local"){await ce(C,j);return}if(H&&!j){await ce(C,j);return}Ke(!0);try{const R=await Kt(S,C);ye(R),R.cloudReady||R.alreadyPatched?await ce(C,j):ge(!0)}catch(R){r("error",`Cloud analysis failed: ${R}`),await ce(C,j)}finally{Ke(!1)}},bt=async s=>{try{const[{tests:j},C,S]=await Promise.all([qt(s),Bt(),Vt(s).catch(()=>null)]),R=j.filter(ve=>ve.status==="failed"||ve.status==="error"),{tests:Z,unmatched:Re}=xs(R,C.suites);if(Z.length===0){r("error","The failed tests were not found in Test Explorer — run them from there.");return}Re>0&&r("info",`${Re} failed test${Re===1?" was":"s were"} not found in Test Explorer — re-running the other ${Z.length}.`);const G=S?S.source==="cloud"&&S.cloudProvider?String(S.cloudProvider):S.source==="local"||!S.source?"local":void 0:void 0;if(G&&G!==ee){const ve=G==="local"||(G==="local-appium"?J:_.some(Nt=>Nt.id===G)),Pe=G==="local"?"this machine":te[G]||G;if(!ve){r("error",`That run ran on ${Pe}, which is not set up now — pick a target and run the failed tests from the Run Command field.`),D(Ne(Z));return}if(S!=null&&S.targetDevice){U(G),D(Ne(Z)),r("info",`That run ran on ${Pe} — check the device and app, then press Run.`);return}r("info",`Re-running on ${Pe}, where the run executed.`),de(Ne(Z),G);return}de(Ne(Z))}catch(j){r("error",j.message||"The failed tests could not be re-run")}},gt=()=>{const s=(ie==null?void 0:ie.aiFixPrompt)||`Make this project run on ${te[w]||w} through Testver's cloud environment variables without changing local behavior, then verify with one test run and check the run's cloudExecution verdict.`;ge(!1),ye(null),us(m,{prompt:s,mode:"web"})},yt=async()=>{ge(!1),ye(null),await ce()},jt=()=>{ge(!1),ye(null)},vt=s=>{s.key==="Enter"&&!c&&de()},_e=!H&&w==="testver-grid"&&!!c,je=H&&!!c||_e;return e.jsxs("div",{className:`h-full flex animate-fade-in ${je?"":"flex-col"}`,children:[e.jsxs("div",{className:je?"flex-1 flex flex-col overflow-hidden":"contents",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-white/5 bg-surface-1 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h1",{className:"text-2xl font-bold text-gray-100 flex items-center gap-2.5",children:[e.jsx(dt,{size:22,className:"text-brand-400"}),"Runner"]}),e.jsx(Is,{saved:V.saved,recent:V.recent,onPick:s=>D(s),onRun:s=>{if(c){r("error","A run is already in progress — stop it first");return}de(s)},onSave:V.add,onUpdate:V.update,onDelete:V.remove})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx("label",{className:"text-sm font-medium text-gray-400 block mb-1",children:"Enter any run command to execute on the connected server"}),e.jsx("input",{value:K,onChange:s=>{D(s.target.value),W(!0)},onKeyDown:vt,onFocus:()=>W(!0),onBlur:()=>setTimeout(()=>W(!1),120),placeholder:"e.g., npm install or npx playwright test --headed",className:"w-full bg-surface-2 border border-white/10 rounded-xl px-3.5 py-2.5 text-[15px] text-gray-200 font-mono outline-none placeholder-gray-600 focus:border-brand-500/50",disabled:!!c}),ae&&!c&&X.length>0&&e.jsxs("div",{className:"absolute left-0 right-0 top-full mt-1 z-30 rounded-xl bg-white dark:bg-surface-1 border border-gray-200 dark:border-white/10 shadow-2xl py-1 overflow-hidden",children:[e.jsx("p",{className:"px-3 pt-1.5 pb-1 text-[10px] font-semibold uppercase tracking-wider text-gray-400",children:"Commands"}),e.jsx("div",{className:"max-h-[228px] overflow-y-auto",children:X.map(s=>e.jsxs("button",{onMouseDown:j=>{j.preventDefault(),D(s.command),W(!1)},className:"w-full text-left px-3 py-1.5 hover:bg-black/[0.04] dark:hover:bg-white/5 transition-colors",title:s.command,children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-200 truncate",children:s.label}),s.preset&&e.jsx("span",{className:"px-1.5 py-0 rounded text-[9px] font-semibold bg-brand-500/15 text-brand-500 flex-shrink-0",children:"preset"})]}),e.jsx("span",{className:"block text-[11px] font-mono text-gray-400 truncate",children:s.command})]},s.id))})]})]}),e.jsx("div",{className:"flex items-end gap-2",children:c?e.jsxs("button",{onClick:b,className:"flex items-center justify-center gap-2 px-5 py-2.5 rounded-xl bg-red-600 hover:bg-red-500 text-white text-[15px] font-medium",children:[e.jsx(Xe,{size:14}),"Stop"]}):e.jsx("button",{onClick:()=>de(),disabled:Ve||be||H&&!Se,title:be?"Connect a local device or enable a cloud grid in Connectors first":H&&!Se?"Select a device and an app first":void 0,className:"flex items-center justify-center gap-2 px-5 py-2.5 rounded-xl bg-brand-600 hover:bg-brand-500 text-white text-[15px] font-medium disabled:opacity-60 disabled:cursor-not-allowed",children:Ve?e.jsxs(e.Fragment,{children:[e.jsx(ne,{size:14,className:"animate-pulse"}),"Checking..."]}):e.jsxs(e.Fragment,{children:[e.jsx(xe,{size:14}),"Run"]})})})]}),(_.length>0||Ce&&J)&&e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsx("span",{className:"text-sm text-gray-400",children:"Run on:"}),e.jsxs("div",{className:"flex gap-1.5",children:[!he&&e.jsxs("button",{onClick:()=>U("local"),disabled:!!c,className:`flex items-center gap-1.5 px-2.5 h-8 text-xs rounded-lg border transition-colors ${w==="local"?"border-brand-500/50 bg-brand-500/10 text-brand-400 font-medium":"border-white/5 bg-surface-2 text-gray-400 hover:text-gray-300 hover:border-white/10"} disabled:opacity-50`,children:[e.jsx($e,{size:12}),"Local"]}),_.map(s=>e.jsxs("button",{onClick:()=>U(s.id),disabled:!!c,className:`flex items-center gap-1.5 px-2.5 h-8 text-xs rounded-lg border transition-colors ${w===s.id?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-medium":"border-white/5 bg-surface-2 text-gray-400 hover:text-gray-300 hover:border-white/10"} disabled:opacity-50`,children:[e.jsx(ne,{size:12}),te[s.id]]},s.id)),Ce&&J&&e.jsxs("button",{onClick:()=>U("local-appium"),disabled:!!c,className:`flex items-center gap-1.5 px-2.5 h-8 text-xs rounded-lg border transition-colors ${w==="local-appium"?"border-gray-300 dark:border-white/25 bg-gray-100/70 dark:bg-white/[0.08] text-gray-800 dark:text-gray-100 font-medium":"border-white/5 bg-surface-2 text-gray-400 hover:text-gray-300 hover:border-white/10"} disabled:opacity-50`,children:[e.jsx(Ae,{size:12}),"Local Devices"]})]}),w==="testver-grid"&&e.jsx("div",{className:"flex flex-wrap items-center gap-3",children:e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-gray-400 cursor-pointer select-none",title:"Let grid browsers reach your localhost / private apps — outbound tunnel, scoped to localhost + your baseURL host, closed when the run ends",children:[e.jsx("input",{type:"checkbox",checked:Fe,onChange:s=>xt(s.target.checked),disabled:!!c,className:"rounded border-gray-600 bg-surface-2 text-brand-500 focus:ring-brand-500"}),"Local tunnel"]})}),w!=="local"&&w!=="local-appium"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-gray-500",children:"Build:"}),e.jsx("input",{value:n,onChange:s=>P(s.target.value),placeholder:"auto",className:"w-36 bg-surface-2 border border-white/10 rounded-xl px-3 py-1.5 text-sm text-gray-300 outline-none placeholder-gray-600 focus:border-brand-500/50",disabled:!!c})]})]}),be&&e.jsxs("div",{className:"mt-3 flex items-start gap-2.5 px-3.5 py-3 rounded-xl border border-amber-500/25 bg-amber-500/10 text-sm text-amber-700 dark:text-amber-200",children:[e.jsx(Ae,{size:15,className:"mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-300"}),e.jsxs("span",{children:["No device target available. To run mobile tests, connect a local device or enable a cloud device grid in"," ",e.jsx("span",{className:"font-semibold",children:"Connectors"}),"."]})]}),H&&!c&&e.jsxs(e.Fragment,{children:[e.jsx(mt,{providerId:w,disabled:!!c,value:q,onChange:pt}),Y&&!Y.claimed&&Date.now()<Y.expiresAt&&e.jsxs("div",{className:"mt-2 flex items-center gap-2 px-3 py-1.5 rounded-lg bg-emerald-500/10 border border-emerald-500/25 text-xs",children:[e.jsx(Ee,{size:12,className:"text-emerald-300 flex-shrink-0"}),e.jsx("span",{className:"text-emerald-200",children:"Reusing live recording session"}),e.jsxs("span",{className:"text-emerald-400/70 ml-auto",children:["saves ~45s · expires in ",Math.max(0,Math.round((Y.expiresAt-Date.now())/1e3)),"s"]})]})]}),e.jsxs("div",{className:"mt-2 text-sm text-gray-500 flex items-center gap-3 flex-wrap",children:[(A==null?void 0:A.branch)&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-sky-400/70",children:[e.jsx(os,{size:10})," ",A.branch]}),w!=="local"&&!c&&e.jsxs("span",{className:w==="local-appium"?"text-gray-400":"text-blue-400",children:[w==="local-appium"?"Target":"Cloud",": ",te[w]||w]}),c&&e.jsxs("span",{className:"inline-flex items-center gap-2 min-w-0",children:[e.jsx(ms,{size:"xs"}),e.jsx("span",{className:"font-mono text-gray-400 truncate",title:c.command,children:c.command})]}),h&&!c&&e.jsxs("span",{className:h.status==="completed"?"text-emerald-400":"text-red-400",children:["Last run: ",h.status,typeof h.exitCode=="number"?` · exit code ${h.exitCode}`:""," ",h.duration?`(${(h.duration/1e3).toFixed(1)}s)`:""]})]})]}),e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[e.jsxs("div",{className:"flex-1 flex flex-col p-4 gap-3 overflow-hidden",children:[c&&T.current>0&&e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-400 uppercase mb-2",children:"Live Progress"}),e.jsx(Ss,{current:T.current,passed:T.passed,failed:T.failed,currentTestName:T.currentTestName,tests:T.tests,elapsedMs:T.elapsedMs})]}),!c&&T.summary&&e.jsx(Rs,{summary:T.summary,runId:T.summary.runId,onRerunFailed:()=>void bt(T.summary.runId)}),e.jsx("h3",{className:"text-sm font-semibold text-gray-400 uppercase",children:"Output"}),e.jsx(Ns,{output:f}),c&&e.jsxs("div",{className:"flex flex-col gap-1.5",children:[N&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-amber-300",children:[e.jsx(me,{size:12,className:"animate-pulse"}),e.jsxs("span",{children:["The command looks like it is waiting for an answer: ",e.jsx("span",{className:"font-mono text-amber-200",children:N})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-cyan-500/70 text-sm select-none",children:"›"}),e.jsx("input",{ref:B,type:"text",value:I,onChange:s=>L(s.target.value),onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),F(!1))},disabled:x,placeholder:N?"Type your answer and press Enter (empty Enter accepts the default)":"Send a line to the running command — press Enter","aria-label":"Input to the running command",spellCheck:!1,autoComplete:"off",className:"flex-1 h-9 px-3 rounded-lg bg-black/40 border border-white/10 focus:border-cyan-500/40 focus:outline-none font-mono text-sm text-gray-100 placeholder:text-gray-600 placeholder:font-sans disabled:opacity-60"}),e.jsx("button",{onClick:()=>void F(!1),disabled:x,className:"h-9 px-3 rounded-lg bg-cyan-600/20 text-cyan-300 border border-cyan-500/30 hover:bg-cyan-600/30 text-sm font-medium disabled:opacity-50",title:"Send the line followed by Enter",children:"Enter"}),e.jsx("button",{onClick:()=>void F(!0),disabled:x,className:"h-9 px-3 rounded-lg border border-white/10 text-gray-400 hover:text-gray-200 hover:bg-white/5 text-sm disabled:opacity-50",title:"Close the command's input (Ctrl-D) — for programs that read until input ends",children:"Send EOF"})]}),e.jsx("p",{className:"text-[11px] text-gray-600",children:d?e.jsx("span",{className:"text-red-400",children:d}):"What you type is echoed into the log above, so passwords will be visible there. Use Stop for Ctrl-C."})]})]}),!je&&e.jsxs("div",{className:"w-80 border-l border-white/5 bg-surface-1 p-4 overflow-y-auto flex-shrink-0",children:[M.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-amber-400 uppercase mb-3",children:"Current Runs"}),e.jsx("div",{className:"space-y-1.5",children:M.map(s=>e.jsxs("div",{className:"px-3 py-2.5 rounded-lg bg-amber-500/5 border border-amber-500/20 cursor-pointer hover:bg-amber-500/10 transition-colors",onClick:()=>g(s.runId,s.command),title:"Click to view output",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsxs("span",{className:"relative flex h-2 w-2 flex-shrink-0",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-amber-400"})]}),e.jsx("span",{className:"font-mono text-gray-300 text-xs flex-1 truncate",children:s.command})]}),e.jsxs("div",{className:"flex items-center gap-2 text-[10px]",children:[s.cloudProvider&&e.jsxs("span",{className:"flex items-center gap-0.5 text-blue-400",children:[e.jsx(ne,{size:8}),te[s.cloudProvider]||s.cloudProvider]}),s.source==="scheduler"&&e.jsxs("span",{className:"flex items-center gap-0.5 text-gray-500",children:[e.jsx(ke,{size:8})," Scheduled"]}),e.jsx("div",{className:"flex-1"}),e.jsxs("span",{className:"text-emerald-400 flex items-center gap-0.5",children:[e.jsx(se,{size:8})," ",s.passed]}),e.jsxs("span",{className:"text-red-400 flex items-center gap-0.5",children:[e.jsx(le,{size:8})," ",s.failed]}),e.jsx("span",{className:"text-gray-500 tabular-nums font-mono",children:e.jsx(Ft,{run:s,format:j=>`${Math.floor(j/1e3)}s`})}),e.jsx("button",{onClick:j=>{j.stopPropagation(),rt(s.runId).catch(()=>{})},className:"text-red-400 hover:text-red-300 p-0.5",title:"Cancel run",children:e.jsx(Xe,{size:8})})]})]},s.runId))})]}),e.jsx("h3",{className:"text-sm font-semibold text-gray-400 uppercase mb-3",children:"Run History"}),e.jsx(ks,{})]})]})]}),je&&e.jsx("div",{className:"w-[35%] min-w-[380px] max-w-[560px] border-l border-white/5 bg-surface-1 flex-shrink-0",children:_e?e.jsx(ds,{runId:(c==null?void 0:c.runId)??null,layout:"panel"}):e.jsx(cs,{testRunning:!!c})}),Be&&ie&&e.jsx(Ps,{open:Be,analysis:ie,providerLabel:te[w]||w,onAiFix:gt,onSkipAndRun:yt,onCancel:jt})]})}const As="w-full bg-surface-2 border border-white/10 rounded-xl px-3.5 py-2.5 text-[15px] text-gray-200 font-mono outline-none placeholder-gray-600 focus:border-brand-500/50";function Ds({value:o,onChange:t,placeholder:i,disabled:r,className:u,hint:m}){var I,L,x;const[c,f]=l.useState(!1),{saved:h}=ut(),{data:p}=pe({queryKey:["run-commands-config"],queryFn:De,staleTime:1e4}),b=(((L=(I=p==null?void 0:p.configured)==null?void 0:I.fullRun)==null?void 0:L.trim())||((x=p==null?void 0:p.autoDetected)==null?void 0:x.fullRun)||"").trim(),g=[...b?[{id:"preset-run-all",label:"Run All",command:b,preset:!0}]:[],...h.map(y=>({id:y.id,label:y.label,command:y.command}))],N=o.trim().toLowerCase(),z=N?g.filter(y=>y.command.toLowerCase()!==N&&(y.command.toLowerCase().includes(N)||y.label.toLowerCase().includes(N))):g;return e.jsxs("div",{className:"relative",children:[e.jsx("input",{value:o,disabled:r,onChange:y=>{t(y.target.value),f(!0)},onFocus:()=>f(!0),onBlur:()=>setTimeout(()=>f(!1),120),placeholder:i,className:u||As}),c&&!r&&z.length>0&&e.jsxs("div",{className:"absolute left-0 right-0 top-full mt-1 z-30 rounded-xl bg-white dark:bg-surface-1 border border-gray-200 dark:border-white/10 shadow-2xl py-1 overflow-hidden",children:[e.jsxs("p",{className:"px-3 pt-1.5 pb-1 text-[10px] font-semibold uppercase tracking-wider text-gray-400",children:["Commands",m&&e.jsxs("span",{className:"ml-1.5 normal-case font-normal tracking-normal text-gray-400/80",children:["· ",m]})]}),e.jsx("div",{className:"max-h-[228px] overflow-y-auto",children:z.map(y=>e.jsxs("button",{type:"button",onMouseDown:d=>{d.preventDefault(),t(y.command),f(!1)},className:"w-full text-left px-3 py-1.5 hover:bg-black/[0.04] dark:hover:bg-white/5 transition-colors",title:y.command,children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-200 truncate",children:y.label}),y.preset&&e.jsx("span",{className:"px-1.5 py-0 rounded text-[9px] font-semibold bg-brand-500/15 text-brand-500 flex-shrink-0",children:"preset"})]}),e.jsx("span",{className:"block text-[11px] font-mono text-gray-400 truncate",children:y.command})]},y.id))})]})]})}const Ls=[{label:"Every 5 minutes",cron:"*/5 * * * *"},{label:"Every 15 minutes",cron:"*/15 * * * *"},{label:"Every 30 minutes",cron:"*/30 * * * *"},{label:"Every hour",cron:"0 * * * *"},{label:"Every 2 hours",cron:"0 */2 * * *"},{label:"Daily at 8 AM",cron:"0 8 * * *"},{label:"Daily at 10 PM",cron:"0 22 * * *"},{label:"Weekdays at 9 AM",cron:"0 9 * * 1-5"},{label:"Weekly Sunday midnight",cron:"0 0 * * 0"},{label:"Custom",cron:""}],tt={browserstack:"BrowserStack",lambdatest:"LambdaTest",saucelabs:"Sauce Labs","local-appium":"Local Devices","testver-grid":"Testver Grid"},st=()=>({name:"",command:"",cron:"0 8 * * *",cloudProvider:"",enabled:!0,appPath:"",appId:"",deviceName:"",platformName:"Android",platformVersion:""});function Fs(o){const t=o.trim().split(/\s+/);if(t.length!==5)return o;const[i,r,u,m,c]=t;return i==="*"&&r==="*"&&u==="*"&&m==="*"&&c==="*"?"Every minute":i!=null&&i.startsWith("*/")&&r==="*"&&u==="*"&&m==="*"&&c==="*"?`Every ${i.slice(2)} min`:/^\d+$/.test(i)&&r==="*"&&u==="*"&&m==="*"&&c==="*"?`Hourly at :${i.padStart(2,"0")}`:/^\d+$/.test(i)&&/^\d+$/.test(r)&&u==="*"&&m==="*"&&c==="*"?`Daily ${r.padStart(2,"0")}:${i.padStart(2,"0")}`:/^\d+$/.test(i)&&/^\d+$/.test(r)&&u==="*"&&m==="*"&&bs(c)?`Weekdays ${r.padStart(2,"0")}:${i.padStart(2,"0")}`:/^\d+$/.test(i)&&/^\d+$/.test(r)&&u==="*"&&m==="*"&&c==="0"?`Sundays ${r.padStart(2,"0")}:${i.padStart(2,"0")}`:/^\d+$/.test(i)&&(r!=null&&r.startsWith("*/"))&&u==="*"&&m==="*"&&c==="*"?`Every ${r.slice(2)}h at :${i.padStart(2,"0")}`:o}function Ms(){const{toast:o}=nt(),[t,i]=l.useState([]),[r,u]=l.useState([]),[m,c]=l.useState(!1),{showsMobile:f}=lt(),[h,p]=l.useState(!0),[b,g]=l.useState(!1),[N,z]=l.useState(null),[I,L]=l.useState(null),[x,y]=l.useState(st()),[d,k]=l.useState(!1),[B,F]=l.useState({}),M=l.useCallback(async()=>{var a,v;try{const[E,Q,O]=await Promise.all([_t().catch(()=>Ht()),ot().catch(()=>({providers:[]})),it().catch(()=>({config:{enabled:!1}}))]);i(E.schedules||[]),u(((a=Q.providers)==null?void 0:a.filter(X=>X.enabled))||[]),c(!!((v=O.config)!=null&&v.enabled))}catch{}finally{p(!1)}},[]);l.useEffect(()=>{M()},[M]);const T=()=>{L(null),y(st()),g(!0)},A=a=>{L(a.id),y({name:a.name,command:a.command,cron:a.cron,cloudProvider:a.cloudProvider||"",enabled:a.enabled,appPath:a.appPath??"",appId:a.appId??"",deviceName:a.deviceName??"",platformName:a.platformName??"Android",platformVersion:a.platformVersion??""}),g(!0)},V=async()=>{if(!x.name.trim()){o("error","Name is required");return}if(!x.command.trim()){o("error","Command is required");return}if(!x.cron.trim()){o("error","Cron expression is required");return}k(!0);try{const v=f&&!!x.cloudProvider?{appPath:x.appPath.trim()||void 0,appId:x.appId||void 0,deviceName:x.deviceName||void 0,platformName:x.deviceName?x.platformName:void 0,platformVersion:x.platformVersion||void 0}:{};I?(await We(I,{name:x.name.trim(),command:x.command.trim(),cron:x.cron.trim(),cloudProvider:x.cloudProvider||void 0,enabled:x.enabled,...v}),o("success","Schedule updated")):(await Ut({id:"",name:x.name.trim(),command:x.command.trim(),cron:x.cron.trim(),cloudProvider:x.cloudProvider||void 0,enabled:x.enabled,...v}),o("success","Schedule created")),g(!1),await M()}catch(a){o("error",`Save failed: ${a}`)}finally{k(!1)}},K=(a,v)=>{z({id:a,name:v})},D=async()=>{if(N){try{await Gt(N.id),o("info",`Schedule '${N.name}' deleted`),await M()}catch(a){o("error",`Delete failed: ${a}`)}z(null)}},ae=async a=>{try{await We(a.id,{enabled:!a.enabled}),await M()}catch(v){o("error",`Toggle failed: ${v}`)}},W=async(a,v)=>{F(E=>({...E,[a]:!0}));try{const E=await Ot(a);E.runId?o("success",`'${v}' triggered (run: ${E.runId.slice(0,8)}...)`):o("info",E.message),await M()}catch(E){o("error",`Run failed: ${E}`)}finally{F(E=>({...E,[a]:!1}))}},$=Ls.find(a=>a.cron===x.cron);return!$||$.label,e.jsxs("div",{className:"min-h-screen bg-surface-0 text-gray-200 animate-fade-in",children:[e.jsx("div",{className:"border-b border-white/5 bg-surface-1",children:e.jsx("div",{className:"max-w-[1400px] mx-auto px-6 py-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-gray-100 flex items-center gap-3",children:[e.jsx(ke,{size:24,className:"text-brand-300"}),"Schedules",e.jsxs("span",{className:"text-sm font-normal bg-brand-500/15 text-brand-300 px-2.5 py-0.5 rounded-full",children:[t.length," schedules"]})]}),e.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"Schedule any run command to execute automatically on the connected server."})]}),e.jsxs("button",{onClick:T,className:"flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-brand-600 hover:bg-brand-500 rounded-lg transition-colors",children:[e.jsx(ue,{size:16}),"Add Schedule"]})]})})}),e.jsx("div",{className:"max-w-[1400px] mx-auto px-6 py-8",children:h?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(me,{size:20,className:"animate-spin text-gray-500"})}):t.length===0?e.jsxs("div",{className:"text-center py-16",children:[e.jsx(ke,{size:40,className:"text-gray-600 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-400 text-[15px]",children:"No schedules configured yet."}),e.jsx("p",{className:"text-gray-600 text-sm mt-1",children:"Create a schedule to automatically run tests on a recurring basis."}),e.jsxs("button",{onClick:T,className:"mt-4 flex items-center gap-1.5 px-5 py-2.5 rounded-xl bg-brand-600 hover:bg-brand-500 text-white text-[15px] font-medium mx-auto",children:[e.jsx(ue,{size:14}),"Create Schedule"]})]}):e.jsx("div",{className:"space-y-3",children:t.map(a=>e.jsx("div",{className:`bg-surface-1 rounded-xl border border-white/5 p-4 transition-opacity ${a.enabled?"":"opacity-50"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("p",{className:"text-sm font-medium text-gray-200 truncate",children:a.name}),a.enabled?e.jsxs("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium bg-emerald-500/15 text-emerald-400",children:[e.jsx(se,{size:8})," Active"]}):e.jsxs("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-500/15 text-gray-500",children:[e.jsx(Je,{size:8})," Paused"]}),a.cloudProvider?e.jsxs("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium bg-blue-500/15 text-blue-400",children:[e.jsx(ne,{size:8})," ",tt[a.cloudProvider]||a.cloudProvider]}):e.jsxs("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-500/15 text-gray-400",children:[e.jsx($e,{size:8})," Local"]})]}),e.jsx("p",{className:"text-xs text-gray-400 font-mono truncate mb-1",children:a.command}),e.jsxs("div",{className:"flex items-center gap-4 text-[11px] text-gray-500",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ct,{size:10}),Fs(a.cron),e.jsxs("span",{className:"text-gray-600",children:["(",a.cron,")"]})]}),a.lastRunTime&&e.jsxs("span",{children:["Last: ",Ye(a.lastRunTime)]}),a.nextRunTime&&e.jsxs("span",{className:"text-brand-400",children:["Next: ",Ye(a.nextRunTime)]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsxs("button",{onClick:()=>W(a.id,a.name),disabled:B[a.id],className:"flex items-center gap-1 px-2.5 py-1.5 rounded-lg bg-brand-600/20 hover:bg-brand-600/30 text-brand-400 text-xs border border-brand-500/20 disabled:opacity-50",title:"Run Now",children:[B[a.id]?e.jsx(me,{size:12,className:"animate-spin"}):e.jsx(xe,{size:12}),"Run"]}),e.jsx("button",{onClick:()=>ae(a),className:"px-2.5 py-1.5 rounded-lg bg-surface-2 hover:bg-surface-3 text-gray-400 text-xs border border-white/5",title:a.enabled?"Pause":"Enable",children:a.enabled?e.jsx(Je,{size:12}):e.jsx(xe,{size:12})}),e.jsx("button",{onClick:()=>A(a),className:"px-2.5 py-1.5 rounded-lg bg-surface-2 hover:bg-surface-3 text-gray-400 text-xs border border-white/5",title:"Edit",children:e.jsx(is,{size:12})}),e.jsx("button",{onClick:()=>K(a.id,a.name),className:"px-2.5 py-1.5 rounded-lg bg-red-600/20 hover:bg-red-600/30 text-red-400 text-xs border border-red-500/20",title:"Delete",children:e.jsx(Ie,{size:12})})]})]})},a.id))})}),N&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 animate-fade-in",children:e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/10 w-full max-w-sm mx-4 p-5",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/15 flex items-center justify-center flex-shrink-0",children:e.jsx(Ie,{size:18,className:"text-red-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-200",children:"Delete Schedule"}),e.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:"This action cannot be undone"})]})]}),e.jsxs("p",{className:"text-sm text-gray-400 mb-5",children:["Are you sure you want to delete ",e.jsxs("span",{className:"font-medium text-gray-200",children:['"',N.name,'"']}),"? All scheduled runs for this schedule will be cancelled."]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:()=>z(null),className:"px-4 py-2 rounded-lg text-sm text-gray-400 hover:text-gray-200 hover:bg-white/5 transition-colors",children:"Cancel"}),e.jsx("button",{onClick:D,className:"px-4 py-2 rounded-lg text-sm font-medium text-white bg-red-600 hover:bg-red-500 transition-colors",children:"Delete"})]})]})}),b&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 animate-fade-in overflow-y-auto py-6",children:e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/10 w-full max-w-lg mx-4 my-auto max-h-[calc(100vh-48px)] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/5",children:[e.jsx("h2",{className:"text-base font-semibold text-gray-200",children:I?"Edit Schedule":"New Schedule"}),e.jsx("button",{onClick:()=>g(!1),className:"text-gray-500 hover:text-gray-300",children:e.jsx(Le,{size:16})})]}),e.jsxs("div",{className:"p-4 space-y-4 overflow-y-auto flex-1",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-400 block mb-1",children:"Schedule Name"}),e.jsx("input",{value:x.name,onChange:a=>y(v=>({...v,name:a.target.value})),placeholder:"e.g., Nightly Regression",className:"w-full bg-surface-2 border border-white/10 rounded-xl px-3.5 py-2.5 text-[15px] text-gray-200 outline-none placeholder-gray-600 focus:border-brand-500/50"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-400 block mb-1",children:"Run Command"}),e.jsx(Ds,{value:x.command,onChange:a=>y(v=>({...v,command:a})),placeholder:"e.g., npx playwright test --headed",hint:"Add commands from the Runner screen"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-400 block mb-2",children:"Schedule"}),e.jsx(hs,{value:x.cron,onChange:a=>y(v=>({...v,cron:a}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-400 block mb-1",children:"Run On"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("button",{onClick:()=>y(a=>({...a,cloudProvider:""})),className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg border transition-colors ${x.cloudProvider?"border-white/5 bg-surface-2 text-gray-400 hover:text-gray-300":"border-brand-500/50 bg-brand-500/10 text-brand-400"}`,children:[e.jsx($e,{size:12})," Local"]}),r.map(a=>e.jsxs("button",{onClick:()=>y(v=>({...v,cloudProvider:a.id})),className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg border transition-colors ${x.cloudProvider===a.id?"border-blue-500/60 bg-blue-500/15 text-blue-300 font-medium shadow-[0_0_0_1px_rgba(59,130,246,0.15)]":"border-white/5 bg-surface-2 text-gray-400 hover:text-gray-300"}`,children:[e.jsx(ne,{size:12})," ",tt[a.id]||a.id]},a.id)),f&&m&&e.jsxs("button",{onClick:()=>y(a=>({...a,cloudProvider:"local-appium"})),className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg border transition-colors ${x.cloudProvider==="local-appium"?"border-gray-400 dark:border-white/30 bg-gray-100 dark:bg-white/10 text-gray-800 dark:text-gray-100 font-medium shadow-sm":"border-white/5 bg-surface-2 text-gray-400 hover:text-gray-300"}`,children:[e.jsx(Ae,{size:12})," Local Devices"]})]})]}),f&&x.cloudProvider&&e.jsx(mt,{providerId:x.cloudProvider,value:{deviceName:x.deviceName,platformName:x.platformName,platformVersion:x.platformVersion,appId:x.appId,appPath:x.appPath},onChange:a=>y(v=>({...v,deviceName:a.deviceName,platformName:a.platformName,platformVersion:a.platformVersion,appId:a.appId,appPath:a.appPath}))}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-300 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:x.enabled,onChange:a=>y(v=>({...v,enabled:a.target.checked})),className:"rounded border-gray-600 bg-surface-2 text-brand-500 focus:ring-brand-500"}),"Enable schedule immediately"]})]}),e.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-white/5",children:[e.jsx("button",{onClick:()=>g(!1),className:"px-5 py-2.5 text-[15px] rounded-xl bg-surface-2 hover:bg-surface-3 text-gray-300 border border-white/5",children:"Cancel"}),e.jsxs("button",{onClick:V,disabled:d,className:"flex items-center gap-1.5 px-5 py-2.5 text-[15px] rounded-xl bg-brand-600 hover:bg-brand-500 text-white font-medium disabled:opacity-50",children:[d&&e.jsx(me,{size:14,className:"animate-spin"}),I?"Update":"Create"]})]})]})})]})}function ta(){const[o,t]=kt("tab",["runner","schedules"],"runner"),i=(r,u,m)=>e.jsxs("button",{onClick:()=>t(r),className:`flex items-center gap-1.5 px-4 py-2 text-sm font-medium border-b-2 transition-colors ${o===r?"border-brand-400 text-brand-300":"border-transparent text-gray-400 hover:text-gray-200 hover:border-white/10"}`,children:[m,u]});return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-1 px-5 border-b border-white/5 bg-surface-1 flex-shrink-0",children:[i("runner","Runner",e.jsx(xe,{size:15})),i("schedules","Schedules",e.jsx(ke,{size:15}))]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:o==="runner"?e.jsx($s,{}):e.jsx(Ms,{})})]})}export{ta as AdvancedPage};
@@ -1 +1 @@
1
- import{j as e,r as E,R as Z}from"./vendor-react-CTbHBddL.js";import{u as ee}from"./vendor-query-BrzmPFT3.js";import{u as se}from"./useTabParam-ChbOedP1.js";import{E as te}from"./ExportButton-Dt5RhL-h.js";import{aw as ae,an as re,ax as le,ay as ie,F as ce}from"./useTestManagement-Xm4Bcx3u.js";import{ik as ne}from"./index-BYVxKLrT.js";import{C as G,H as de,cm as W,bP as D,e as Q,c as V,R as H,df as X,aC as oe,u as B,r as P,o as O,ap as xe,y as me,t as he,a0 as ue,q as z,g as ge}from"./vendor-icons-BKPiFyYV.js";const pe=[{key:"health",label:"Health Dashboard",icon:de},{key:"analytics",label:"Execution Analytics",icon:W},{key:"automation",label:"Automation Usage",icon:D},{key:"defects",label:"Defect Analytics",icon:Q},{key:"cases",label:"Test Case Overview",icon:V}],je={critical:"bg-red-500/20 text-red-300",high:"bg-orange-500/20 text-orange-300",medium:"bg-amber-500/20 text-amber-300",low:"bg-emerald-500/20 text-emerald-300"},I={passed:"bg-emerald-500",failed:"bg-red-500",blocked:"bg-amber-500",skipped:"bg-gray-500"},be={passed:"text-emerald-400",failed:"text-red-400",blocked:"text-amber-400",skipped:"text-gray-400"};function A(t){return t.replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function q(t){return t?new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"-"}function fe(t){if(!t&&t!==0)return"-";if(t<1e3)return`${Math.round(t)}ms`;if(t<6e4)return`${(t/1e3).toFixed(1)}s`;const n=Math.floor(t/6e4),r=Math.round(t%6e4/1e3);return`${n}m ${r}s`}function Y(t){return t>=75?"text-emerald-400":t>=50?"text-amber-400":"text-red-400"}function J(t){return t>=75?"bg-emerald-500":t>=50?"bg-amber-500":"bg-red-500"}function ye(t){return t>=75?"stroke-emerald-500":t>=50?"stroke-amber-500":"stroke-red-500"}function Ne(t){return t>=90?"Excellent":t>=75?"Good":t>=50?"Fair":t>=25?"Poor":"Critical"}function M(t,n=0,r=100){return Math.min(r,Math.max(n,t))}function R({value:t,color:n,className:r=""}){const l=M(t),x=n||J(l);return e.jsx("div",{className:`h-2 rounded-full bg-white/5 overflow-hidden ${r}`,children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${x}`,style:{width:`${l}%`}})})}function S({icon:t,label:n,value:r,sub:l,color:x}){return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${x||"bg-brand-500/15"}`,children:e.jsx(t,{className:`w-4 h-4 ${x?"":"text-brand-300"}`})}),e.jsx("span",{className:"text-sm text-gray-400",children:n})]}),e.jsx("p",{className:"text-2xl font-bold text-gray-100",children:r}),l&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:l})]})}function U({message:t}){return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-gray-500",children:[e.jsx(G,{className:"w-10 h-10 mb-3 opacity-40"}),e.jsx("p",{className:"text-sm",children:t})]})}function L(){return e.jsxs("div",{className:"space-y-6 animate-pulse",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[...Array(4)].map((t,n)=>e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-white/5"}),e.jsx("div",{className:"h-3 w-24 rounded bg-white/5"})]}),e.jsx("div",{className:"h-6 w-16 rounded bg-white/5"})]},n))}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("div",{className:"h-3 w-32 rounded bg-white/5 mb-4"}),e.jsx("div",{className:"h-32 rounded bg-white/5"})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("div",{className:"h-3 w-40 rounded bg-white/5 mb-4"}),e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((t,n)=>e.jsx("div",{className:"h-8 rounded bg-white/5"},n))})]})]})}function K({message:t}){return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-red-400",children:[e.jsx(O,{className:"w-10 h-10 mb-3 opacity-60"}),e.jsx("p",{className:"text-sm",children:t})]})}function ve({score:t}){const n=M(Math.round(t)),r=80,l=2*Math.PI*r,x=l-n/100*l,h=ye(n),d=Y(n),a=Ne(n);return e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("div",{className:"relative w-52 h-52",children:[e.jsxs("svg",{className:"w-full h-full -rotate-90",viewBox:"0 0 200 200",children:[e.jsx("circle",{cx:"100",cy:"100",r,fill:"none",stroke:"rgba(255,255,255,0.05)",strokeWidth:"12"}),e.jsx("circle",{cx:"100",cy:"100",r,fill:"none",className:h,strokeWidth:"12",strokeLinecap:"round",strokeDasharray:l,strokeDashoffset:x,style:{transition:"stroke-dashoffset 1s ease-out"}})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("span",{className:`text-5xl font-bold ${d}`,children:n}),e.jsx("span",{className:"text-xs text-gray-500 mt-1",children:a})]})]}),e.jsx("p",{className:"text-sm font-medium text-gray-400 mt-3",children:"Test Health Score"})]})}function _({icon:t,label:n,score:r,description:l}){const x=M(Math.round(r)),h=Y(x),d=J(x);return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t,{className:"w-4 h-4 text-gray-400"}),e.jsx("span",{className:"text-sm font-medium text-gray-200",children:n})]}),e.jsx("span",{className:`text-lg font-bold ${h}`,children:x})]}),e.jsx(R,{value:x,color:d,className:"mb-2"}),e.jsx("p",{className:"text-xs text-gray-500",children:l})]})}function we({data:t}){const n=Object.values(t).reduce((r,l)=>r+l,0);return n===0?e.jsx("div",{className:"h-6 rounded-full bg-white/5"}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-6 rounded-full bg-white/5 overflow-hidden flex",children:Object.entries(t).map(([r,l])=>{const x=l/n*100;if(x===0)return null;const h=I[r]||"bg-gray-500";return e.jsx("div",{className:`h-full ${h} transition-all duration-500`,style:{width:`${x}%`},title:`${A(r)}: ${l} (${x.toFixed(1)}%)`},r)})}),e.jsx("div",{className:"flex flex-wrap gap-4",children:Object.entries(t).map(([r,l])=>{const x=n>0?(l/n*100).toFixed(1):"0",h=be[r]||"text-gray-400",d=I[r]||"bg-gray-500";return e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${d}`}),e.jsx("span",{className:h,children:A(r)}),e.jsxs("span",{className:"text-gray-500",children:[l," (",x,"%)"]})]},r)})})]})}function ke({priority:t,total:n,passed:r,failed:l}){const x=je[t]||"bg-gray-500/20 text-gray-300",h=n>0?(r/n*100).toFixed(1):"0",d=n>0?(l/n*100).toFixed(1):"0";return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${x}`,children:A(t)}),e.jsxs("span",{className:"text-sm text-gray-400",children:[n," total"]})]}),e.jsxs("div",{className:"flex gap-4 mb-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-emerald-400",children:"Passed"}),e.jsxs("span",{className:"text-gray-400",children:[r," (",h,"%)"]})]}),e.jsx(R,{value:n>0?r/n*100:0,color:"bg-emerald-500"})]}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-red-400",children:"Failed"}),e.jsxs("span",{className:"text-gray-400",children:[l," (",d,"%)"]})]}),e.jsx(R,{value:n>0?l/n*100:0,color:"bg-red-500"})]})]})]})}function Ce(){const{data:t,isLoading:n,error:r,refetch:l}=ae(),{data:x,isLoading:h}=re();if(n||h)return e.jsx(L,{});if(r)return e.jsx(K,{message:"Failed to load health data"});const a=t||{},g=x||{},p=a.healthScore??a.overallScore??a.overall??a.score??0,v=a.automationCoverage??a.automation_coverage??g.automationCoverage??0,j=a.requirementCoverage??a.requirement_coverage??g.requirementCoverage??0,N=a.executionFreshness??a.execution_freshness??0,k=a.qualityAverage??a.qualityScore??a.quality_score??0,b=a.syncHealth??a.sync_health??0,c=a.staleTestCases??a.stale_test_cases??0,s=a.recentlyUpdated??a.recently_updated??0,u=g.totalTestCases??a.totalTestCases??a.total_test_cases??0,o=g.automatedTestCases??a.automatedCount??a.automated_count??0;return e.jsxs("div",{className:"space-y-8",children:[e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{onClick:()=>l(),className:"flex items-center gap-2 text-xs text-gray-400 hover:text-gray-200 transition-colors",children:[e.jsx(H,{className:"w-3.5 h-3.5"}),"Refresh"]})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(ve,{score:p})}),e.jsx("div",{className:"text-center",children:e.jsxs("p",{className:"text-lg text-gray-400",children:[e.jsx("span",{className:"text-gray-200 font-semibold",children:u})," Test Cases"," ","·"," ",e.jsx("span",{className:"text-gray-200 font-semibold",children:o})," Automated"]})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Health Breakdown"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5 gap-4",children:[e.jsx(_,{icon:X,label:"Automation Coverage",score:v,description:"Percentage of test cases with automation scripts"}),e.jsx(_,{icon:oe,label:"Requirement Coverage",score:j,description:"Requirements with linked test cases"}),e.jsx(_,{icon:B,label:"Execution Freshness",score:N,description:"How recently tests have been executed"}),e.jsx(_,{icon:P,label:"Quality Score",score:k,description:"Average quality across test executions"}),e.jsx(_,{icon:H,label:"Sync Health",score:b,description:"Script mappings and automation sync status"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Activity Indicators"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-lg bg-amber-500/15",children:e.jsx(O,{className:"w-5 h-5 text-amber-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-gray-400",children:"Stale Test Cases"}),e.jsx("p",{className:"text-xs text-gray-500",children:">30 days without update"})]}),e.jsx("span",{className:"text-2xl font-bold text-amber-400",children:c})]}),c>0&&u>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx(R,{value:c/u*100,color:"bg-amber-500"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[(c/u*100).toFixed(1),"% of total test cases"]})]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-lg bg-emerald-500/15",children:e.jsx(P,{className:"w-5 h-5 text-emerald-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-gray-400",children:"Recently Updated"}),e.jsx("p",{className:"text-xs text-gray-500",children:"<7 days since last update"})]}),e.jsx("span",{className:"text-2xl font-bold text-emerald-400",children:s})]}),s>0&&u>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx(R,{value:s/u*100,color:"bg-emerald-500"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[(s/u*100).toFixed(1),"% of total test cases"]})]})]})]})]})]})}function Te(){const{data:t,isLoading:n,error:r,refetch:l}=le(),[x,h]=E.useState(null);if(n)return e.jsx(L,{});if(r)return e.jsx(K,{message:"Failed to load execution analytics"});const d=t||{},a=d.totalExecutions??d.total_executions??0,g=d.passRate??d.pass_rate??0,p=d.failRate??d.fail_rate??0,v=d.avgDuration??d.avg_duration??0,j=d.byStatus??d.by_status??{},N=d.byPriority??d.by_priority??{},k=d.byCycle??d.cycles??d.cycleHistory??d.cycle_history??[],b=d.recentExecutions??d.trends??d.executionTrend??d.execution_trend??[],c=d.flakyTests??d.flaky_tests??[];return e.jsxs("div",{className:"space-y-8",children:[e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{onClick:()=>l(),className:"flex items-center gap-2 text-xs text-gray-400 hover:text-gray-200 transition-colors",children:[e.jsx(H,{className:"w-3.5 h-3.5"}),"Refresh"]})}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(S,{icon:W,label:"Total Executions",value:a.toLocaleString(),color:"bg-brand-500/15"}),e.jsx(S,{icon:P,label:"Pass Rate",value:`${typeof g=="number"?g.toFixed(1):g}%`,color:"bg-emerald-500/15"}),e.jsx(S,{icon:xe,label:"Fail Rate",value:`${typeof p=="number"?p.toFixed(1):p}%`,color:"bg-red-500/15"}),e.jsx(S,{icon:B,label:"Avg Duration",value:fe(v),color:"bg-sky-500/15"})]}),Object.keys(j).length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Status Distribution"}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:e.jsx(we,{data:j})})]}),Object.keys(N).length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Priority Breakdown"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:["critical","high","medium","low"].map(s=>{const u=N[s]||{},o=u.total??u.count??0,f=u.passed??0,y=u.failed??0;return o===0?null:e.jsx(ke,{priority:s,total:o,passed:f,failed:y},s)})})]}),Array.isArray(k)&&k.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Cycle History"}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/5",children:[e.jsx("th",{className:"text-left px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Cycle"}),e.jsx("th",{className:"text-left px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Plan"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Total"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Passed"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Failed"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Pass Rate"})]})}),e.jsx("tbody",{children:k.map((s,u)=>{const o=s.total??0,f=s.passed??0,y=s.failed??0,w=o>0?f/o*100:0,T=s.id||s._id||`cycle-${u}`,$=x===T,i=s.blocked??0,m=s.skipped??0,C=o-f-y-i-m;return e.jsxs(Z.Fragment,{children:[e.jsxs("tr",{className:"border-b border-white/5 last:border-0 hover:bg-white/[0.02] transition-colors cursor-pointer",onClick:()=>h($?null:T),children:[e.jsx("td",{className:"px-4 py-3 text-gray-200 font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[$?e.jsx(me,{className:"w-3.5 h-3.5 text-gray-500"}):e.jsx(he,{className:"w-3.5 h-3.5 text-gray-500"}),s.cycleName||s.cycle_name||s.name||"Unnamed Cycle"]})}),e.jsx("td",{className:"px-4 py-3 text-gray-400",children:s.planName||s.plan_name||"-"}),e.jsx("td",{className:"px-4 py-3 text-center text-gray-300",children:o}),e.jsx("td",{className:"px-4 py-3 text-center text-emerald-400",children:f}),e.jsx("td",{className:"px-4 py-3 text-center text-red-400",children:y}),e.jsx("td",{className:"px-4 py-3 text-center",children:e.jsxs("span",{className:`font-medium ${w>=75?"text-emerald-400":w>=50?"text-amber-400":"text-red-400"}`,children:[w.toFixed(1),"%"]})})]}),$&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"bg-surface-2/50 px-6 py-4 border-b border-white/5",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:"text-xs text-gray-500 w-20",children:"Distribution"}),e.jsxs("div",{className:"flex-1 h-4 rounded-full bg-white/5 overflow-hidden flex",children:[f>0&&e.jsx("div",{className:"h-full bg-emerald-500",style:{width:`${f/o*100}%`},title:`Passed: ${f}`}),y>0&&e.jsx("div",{className:"h-full bg-red-500",style:{width:`${y/o*100}%`},title:`Failed: ${y}`}),i>0&&e.jsx("div",{className:"h-full bg-amber-500",style:{width:`${i/o*100}%`},title:`Blocked: ${i}`}),m>0&&e.jsx("div",{className:"h-full bg-gray-500",style:{width:`${m/o*100}%`},title:`Skipped: ${m}`}),C>0&&e.jsx("div",{className:"h-full bg-sky-500",style:{width:`${C/o*100}%`},title:`In Progress: ${C}`})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-xs",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-emerald-500"})," Passed: ",e.jsx("strong",{className:"text-emerald-400",children:f})," (",o>0?(f/o*100).toFixed(1):0,"%)"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-red-500"})," Failed: ",e.jsx("strong",{className:"text-red-400",children:y})," (",o>0?(y/o*100).toFixed(1):0,"%)"]}),i>0&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-amber-500"})," Blocked: ",e.jsx("strong",{className:"text-amber-400",children:i})]}),m>0&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-500"})," Skipped: ",e.jsx("strong",{className:"text-gray-400",children:m})]}),s.passRate!==void 0&&e.jsxs("span",{className:"text-gray-500",children:["| Pass Rate: ",e.jsxs("strong",{className:w>=75?"text-emerald-400":w>=50?"text-amber-400":"text-red-400",children:[w.toFixed(1),"%"]})]})]})]})})})]},T)})})]})})})]}),Array.isArray(b)&&b.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Execution Trend"}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:(()=>{const s=[...b].sort((o,f)=>String(o.date||o.day||"").localeCompare(String(f.date||f.day||""))).slice(-14),u=Math.max(...s.map(o=>o.total??0),1);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-end gap-1 h-36",children:s.map((o,f)=>{const y=o.total??0,w=o.passed??0,T=o.failed??0,$=y-w-T,i=y/u*100,m=o.date||o.day||"";return e.jsxs("div",{className:"flex-1 h-full flex flex-col items-center justify-end group relative",children:[e.jsxs("div",{className:"absolute -top-10 bg-surface-2 border border-white/10 rounded px-2 py-1 text-xs text-gray-300 opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap z-10 pointer-events-none",children:[q(m),": ",y," total (",w,"P / ",T,"F)"]}),e.jsx("div",{className:"flex-1 w-full flex flex-col justify-end",children:e.jsxs("div",{className:"w-full rounded-t overflow-hidden flex flex-col justify-end",style:{height:`${i}%`,minHeight:y>0?"4px":"0"},children:[w>0&&e.jsx("div",{className:"bg-emerald-500",style:{flex:w}}),T>0&&e.jsx("div",{className:"bg-red-500",style:{flex:T}}),$>0&&e.jsx("div",{className:"bg-gray-500",style:{flex:$}})]})}),f%2===0&&e.jsx("span",{className:"text-[9px] text-gray-600 mt-1",children:(m||"").toString().slice(5)})]},f)})}),e.jsxs("div",{className:"flex items-center gap-4 mt-3 text-xs",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-emerald-500"})," Passed"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-red-500"})," Failed"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-500"})," Other"]}),e.jsxs("span",{className:"ml-auto text-gray-500",children:["Last ",s.length," day",s.length===1?"":"s"]})]})]})})()})]}),Array.isArray(c)&&c.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Unstable Tests"}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/5",children:[e.jsx("th",{className:"text-left px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Test Title"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Fail Rate"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Passed"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Failed"})]})}),e.jsx("tbody",{children:[...c].sort((s,u)=>(u.flakyScore??u.flaky_score??0)-(s.flakyScore??s.flaky_score??0)).map((s,u)=>{const o=s.flakyScore??s.flaky_score??0,f=s.passCount??s.pass_count??s.passed??0,y=s.failCount??s.fail_count??s.failed??0,w=s.title??s.testTitle??s.test_title??"Unknown",T=o>=60?"text-red-400":o>=30?"text-amber-400":"text-gray-400",$=o>=60?"bg-red-500":o>=30?"bg-amber-500":"bg-gray-500";return e.jsxs("tr",{className:"border-b border-white/5 last:border-0 hover:bg-white/[0.02]",children:[e.jsx("td",{className:"px-4 py-3 text-gray-200 max-w-xs truncate",children:w}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("div",{className:"w-20 h-2 rounded-full bg-white/5 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${$}`,style:{width:`${M(o)}%`}})}),e.jsxs("span",{className:`text-xs font-medium ${T}`,children:[o.toFixed(0),"%"]})]})}),e.jsx("td",{className:"px-4 py-3 text-center text-emerald-400",children:f}),e.jsx("td",{className:"px-4 py-3 text-center text-red-400",children:y})]},s.id||s._id||u)})})]})})})]}),a===0&&Object.keys(j).length===0&&e.jsx(U,{message:"No execution data available yet. Run some test cycles to see analytics."})]})}function Se(){const{data:t,isLoading:n}=ie();if(n)return e.jsx(L,{});const r=Array.isArray(t)?t:(t==null?void 0:t.defects)??[];if(r.length===0)return e.jsx(U,{message:"No defects found. Create defects in Integrations to see analytics."});const l={},x={},h={};let d=0,a=0,g=0,p=0;for(const c of r)l[c.severity||"unknown"]=(l[c.severity||"unknown"]||0)+1,x[c.status||"open"]=(x[c.status||"open"]||0)+1,h[c.priority||"medium"]=(h[c.priority||"medium"]||0)+1,["open","in_progress","reopened"].includes(c.status)&&d++,["closed","resolved","verified"].includes(c.status)&&a++,c.resolvedAt&&c.createdAt&&(g+=new Date(c.resolvedAt).getTime()-new Date(c.createdAt).getTime(),p++);const v=p>0?Math.round(g/p/36e5):0,j={};for(const c of r){const s=c.createdAt?new Date(c.createdAt).toISOString().slice(0,10):"";s&&(j[s]||(j[s]={total:0,open:0,closed:0}),j[s].total++,["open","in_progress","reopened"].includes(c.status)?j[s].open++:j[s].closed++)}const N=Object.entries(j).sort(([c],[s])=>c.localeCompare(s)).slice(-14),k={critical:"bg-red-500",blocker:"bg-red-600",high:"bg-orange-500",medium:"bg-amber-500",low:"bg-emerald-500",unknown:"bg-gray-500"},b={open:"bg-sky-500",in_progress:"bg-amber-500",resolved:"bg-emerald-500",closed:"bg-gray-500",verified:"bg-emerald-600",reopened:"bg-red-500",rejected:"bg-gray-600",deferred:"bg-violet-500"};return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(S,{icon:Q,label:"Total Defects",value:r.length,color:"bg-red-500/15"}),e.jsx(S,{icon:O,label:"Open Defects",value:d,sub:`${r.length>0?(d/r.length*100).toFixed(1):0}% of total`,color:"bg-amber-500/15"}),e.jsx(S,{icon:P,label:"Closed/Resolved",value:a,sub:`${r.length>0?(a/r.length*100).toFixed(1):0}% of total`,color:"bg-emerald-500/15"}),e.jsx(S,{icon:B,label:"Avg Resolution Time",value:v>0?`${v}h`:"-",sub:p>0?`Based on ${p} resolved defects`:"No resolved defects yet",color:"bg-sky-500/15"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("h4",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Severity Distribution"}),e.jsx("div",{className:"space-y-3",children:["critical","blocker","high","medium","low"].filter(c=>l[c]).map(c=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-gray-400 w-16 capitalize",children:c}),e.jsx("div",{className:"flex-1 h-5 rounded bg-white/5 overflow-hidden",children:e.jsx("div",{className:`h-full ${k[c]||"bg-gray-500"} rounded`,style:{width:`${l[c]/r.length*100}%`}})}),e.jsx("span",{className:"text-xs text-gray-300 w-8 text-right font-medium",children:l[c]}),e.jsxs("span",{className:"text-xs text-gray-500 w-12 text-right",children:[(l[c]/r.length*100).toFixed(0),"%"]})]},c))})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("h4",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Status Distribution"}),e.jsx("div",{className:"space-y-3",children:Object.entries(x).sort(([,c],[,s])=>s-c).map(([c,s])=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-gray-400 w-20 capitalize",children:A(c)}),e.jsx("div",{className:"flex-1 h-5 rounded bg-white/5 overflow-hidden",children:e.jsx("div",{className:`h-full ${b[c]||"bg-gray-500"} rounded`,style:{width:`${s/r.length*100}%`}})}),e.jsx("span",{className:"text-xs text-gray-300 w-8 text-right font-medium",children:s}),e.jsxs("span",{className:"text-xs text-gray-500 w-12 text-right",children:[(s/r.length*100).toFixed(0),"%"]})]},c))})]})]}),N.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Defect Creation Trend"}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:e.jsx("div",{className:"flex items-end gap-1 h-32",children:N.map(([c,s],u)=>{const o=Math.max(...N.map(([,y])=>y.total),1),f=s.total/o*100;return e.jsxs("div",{className:"flex-1 h-full flex flex-col items-center justify-end gap-1 group relative",children:[e.jsxs("div",{className:"absolute -top-8 bg-surface-2 border border-white/10 rounded px-2 py-1 text-xs text-gray-300 opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap z-10 pointer-events-none",children:[q(c),": ",s.total," (",s.open," open, ",s.closed," closed)"]}),e.jsx("span",{className:"text-[10px] text-gray-500 opacity-0 group-hover:opacity-100",children:s.total}),e.jsx("div",{className:"flex-1 w-full flex flex-col justify-end",children:e.jsx("div",{className:"w-full rounded-t overflow-hidden flex flex-col justify-end",style:{height:`${f}%`,minHeight:s.total>0?"4px":"0"},children:e.jsx("div",{className:"bg-sky-500/70 flex-1"})})}),u%2===0&&e.jsx("span",{className:"text-[9px] text-gray-600 mt-1",children:c.slice(5)})]},u)})})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Priority Breakdown"}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:["critical","high","medium","low"].map(c=>{const s=h[c]||0,u=r.length>0?(s/r.length*100).toFixed(1):"0",o={critical:"text-red-400",high:"text-orange-400",medium:"text-amber-400",low:"text-emerald-400"};return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4 text-center",children:[e.jsx("p",{className:"text-xs text-gray-500 uppercase mb-1",children:c}),e.jsx("p",{className:`text-2xl font-bold ${o[c]||"text-gray-300"}`,children:s}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[u,"%"]})]},c)})})]})]})}function $e(){var o,f,y,w,T,$;const{data:t,isLoading:n}=ce({limit:1e5});if(n)return e.jsx(L,{});const r=Array.isArray(t)?t:(t==null?void 0:t.testCases)??[],l=r.length;if(l===0)return e.jsx(U,{message:"No test cases found. Create test cases in Test Management to see Test Cases overview."});const x={},h={},d={},a={};let g=0,p=0;const v={};for(const i of r){x[i.status||"draft"]=(x[i.status||"draft"]||0)+1,h[i.priority||"medium"]=(h[i.priority||"medium"]||0)+1,d[i.type||"manual"]=(d[i.type||"manual"]||0)+1;const m=i.automationStatus||i.automation_status||"manual";a[m]=(a[m]||0)+1;const C=i.steps?typeof i.steps=="string"?JSON.parse(i.steps):i.steps:[];if(Array.isArray(C)&&C.length>0?g++:p++,i.createdAt){const F=new Date(i.createdAt).toISOString().slice(0,10);v[F]=(v[F]||0)+1}}const j=Object.entries(v).sort(([i],[m])=>i.localeCompare(m));let N=0;const b=j.map(([i,m])=>(N+=m,{day:i,count:m,cumulative:N})).slice(-30),c=b.length>0?b[b.length-1].cumulative:0,s=a.automated??0,u=l>0?(s/l*100).toFixed(1):"0";return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-4",children:[e.jsx(S,{icon:ge,label:"Total Test Cases",value:l,color:"bg-brand-500/15"}),e.jsx(S,{icon:X,label:"Automated",value:s,sub:`${u}% automation`,color:"bg-violet-500/15"}),e.jsx(S,{icon:P,label:"With Steps",value:g,sub:`${l>0?(g/l*100).toFixed(0):0}% complete`,color:"bg-emerald-500/15"}),e.jsx(S,{icon:O,label:"Without Steps",value:p,sub:"Need step definitions",color:"bg-amber-500/15"}),e.jsx(S,{icon:V,label:"Types",value:Object.keys(d).length,sub:Object.entries(d).map(([i,m])=>`${A(i)}: ${m}`).join(", "),color:"bg-sky-500/15"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("h4",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Status Distribution"}),e.jsx("div",{className:"space-y-3",children:Object.entries(x).sort(([,i],[,m])=>m-i).map(([i,m])=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-gray-400 w-20 capitalize",children:A(i)}),e.jsx("div",{className:"flex-1 h-5 rounded bg-white/5 overflow-hidden",children:e.jsx("div",{className:"h-full bg-brand-500 rounded",style:{width:`${m/l*100}%`}})}),e.jsx("span",{className:"text-xs text-gray-300 w-8 text-right font-medium",children:m})]},i))})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("h4",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Priority Distribution"}),e.jsx("div",{className:"space-y-3",children:["critical","high","medium","low"].filter(i=>h[i]).map(i=>{const m=h[i],C={critical:"bg-red-500",high:"bg-orange-500",medium:"bg-amber-500",low:"bg-emerald-500"};return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-gray-400 w-16 capitalize",children:i}),e.jsx("div",{className:"flex-1 h-5 rounded bg-white/5 overflow-hidden",children:e.jsx("div",{className:`h-full ${C[i]} rounded`,style:{width:`${m/l*100}%`}})}),e.jsx("span",{className:"text-xs text-gray-300 w-8 text-right font-medium",children:m}),e.jsxs("span",{className:"text-xs text-gray-500 w-12 text-right",children:[(m/l*100).toFixed(0),"%"]})]},i)})})]})]}),b.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:["Test Case Growth ",e.jsx("span",{className:"text-gray-500 font-normal",children:"(Last 30 days)"})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("div",{className:"flex items-end gap-0.5 h-40",children:b.map((i,m)=>{const C=c>0?i.cumulative/c*100:0;return e.jsxs("div",{className:"flex-1 h-full flex flex-col items-center justify-end group relative",children:[e.jsxs("div",{className:"absolute -top-10 bg-surface-2 border border-white/10 rounded px-2 py-1 text-xs text-gray-300 opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap z-10 pointer-events-none",children:[q(i.day),": +",i.count," (Total: ",i.cumulative,")"]}),e.jsx("div",{className:"flex-1 w-full flex flex-col justify-end",children:e.jsx("div",{className:"w-full bg-gradient-to-t from-brand-600/80 to-brand-400/60 rounded-t transition-all duration-300 group-hover:from-brand-500 group-hover:to-brand-300",style:{height:`${C}%`,minHeight:"2px"}})}),m%5===0&&e.jsx("span",{className:"text-[9px] text-gray-600 mt-1",children:i.day.slice(5)})]},m)})}),e.jsxs("div",{className:"flex items-center justify-between mt-3 text-xs text-gray-500",children:[e.jsxs("span",{children:["Started: ",(((o=b[0])==null?void 0:o.cumulative)??0)-(((f=b[0])==null?void 0:f.count)??0)," test cases"]}),e.jsxs("span",{children:["Current: ",(y=b[b.length-1])==null?void 0:y.cumulative," test cases"]}),e.jsxs("span",{className:"text-emerald-400",children:["+",(((w=b[b.length-1])==null?void 0:w.cumulative)??0)-((((T=b[0])==null?void 0:T.cumulative)??0)-((($=b[0])==null?void 0:$.count)??0))," new"]})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Automation Status"}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("div",{className:"h-6 rounded-full bg-white/5 overflow-hidden flex mb-3",children:Object.entries(a).map(([i,m])=>{const C=m/l*100;if(C===0)return null;const F={automated:"bg-emerald-500",manual:"bg-gray-500",in_progress:"bg-amber-500",planned:"bg-sky-500"};return e.jsx("div",{className:`h-full ${F[i]||"bg-gray-500"}`,style:{width:`${C}%`},title:`${A(i)}: ${m}`},i)})}),e.jsx("div",{className:"flex flex-wrap gap-4",children:Object.entries(a).map(([i,m])=>{const C={automated:"text-emerald-400",manual:"text-gray-400",in_progress:"text-amber-400",planned:"text-sky-400"},F={automated:"bg-emerald-500",manual:"bg-gray-500",in_progress:"bg-amber-500",planned:"bg-sky-500"};return e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${F[i]||"bg-gray-500"}`}),e.jsx("span",{className:C[i]||"text-gray-400",children:A(i)}),e.jsxs("span",{className:"text-gray-500",children:[m," (",(m/l*100).toFixed(1),"%)"]})]},i)})})]})]})]})}function Ae(){const{data:t,isLoading:n}=ee({queryKey:["tm-automation-usage"],queryFn:ne}),r=E.useMemo(()=>{const a=(t==null?void 0:t.cycles)||[];return Array.isArray(a)?a:[]},[t]),l=E.useMemo(()=>{let a=0,g=0,p=0,v=0,j=0,N=0,k=0,b=0;for(const s of r)a+=s.manual.total,g+=s.manual.passed,p+=s.manual.failed,v+=s.manual.duration,j+=s.automated.total,N+=s.automated.passed,k+=s.automated.failed,b+=s.automated.duration;const c=a+j;return{manualTotal:a,manualPassed:g,manualFailed:p,manualDuration:v,autoTotal:j,autoPassed:N,autoFailed:k,autoDuration:b,grandTotal:c}},[r]);if(n)return e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(ue,{className:"w-6 h-6 animate-spin text-brand-400"})});if(r.length===0)return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[e.jsx(D,{className:"w-12 h-12 text-gray-600 mb-3"}),e.jsx("h3",{className:"text-gray-300 font-medium",children:"No Cycle Executions Yet"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Execute test cycles to see automation usage statistics"})]});const x=l.grandTotal>0?Math.round(l.autoTotal/l.grandTotal*100):0,h=100-x,d=a=>a>6e4?`${(a/6e4).toFixed(1)}m`:a>0?`${(a/1e3).toFixed(1)}s`:"—";return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"Total Executions"}),e.jsx("div",{className:"text-2xl font-bold text-gray-100",children:l.grandTotal}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:["Across ",r.length," cycle",r.length!==1?"s":""]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-500 mb-1",children:[e.jsx(D,{size:12})," Automated"]}),e.jsx("div",{className:"text-2xl font-bold text-emerald-300",children:l.autoTotal}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:[x,"% of total · Pass: ",l.autoTotal>0?Math.round(l.autoPassed/l.autoTotal*100):0,"%"]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-500 mb-1",children:[e.jsx(z,{size:12})," Manual"]}),e.jsx("div",{className:"text-2xl font-bold text-amber-300",children:l.manualTotal}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:[h,"% of total · Pass: ",l.manualTotal>0?Math.round(l.manualPassed/l.manualTotal*100):0,"%"]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"Automation Rate"}),e.jsxs("div",{className:"text-2xl font-bold text-emerald-300",children:[x,"%"]}),e.jsx("div",{className:"w-full bg-gray-700/50 rounded-full h-2 mt-2",children:e.jsx("div",{className:"bg-emerald-400 h-2 rounded-full transition-all",style:{width:`${x}%`}})})]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-200 mb-3",children:"Overall Manual vs Automated Split"}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("div",{className:"flex-1",children:e.jsxs("div",{className:"flex h-8 rounded-lg overflow-hidden",children:[x>0&&e.jsx("div",{className:"bg-emerald-500/60 flex items-center justify-center text-xs font-medium text-white transition-all",style:{width:`${x}%`},children:x>10&&`${x}% Auto`}),h>0&&e.jsx("div",{className:"bg-amber-500/50 flex items-center justify-center text-xs font-medium text-white transition-all",style:{width:`${h}%`},children:h>10&&`${h}% Manual`})]})})}),e.jsxs("div",{className:"flex items-center gap-4 mt-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-400",children:[e.jsx("div",{className:"w-3 h-3 rounded bg-emerald-500/60"})," Automated (",l.autoTotal,")"]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-400",children:[e.jsx("div",{className:"w-3 h-3 rounded bg-amber-500/50"})," Manual (",l.manualTotal,")"]})]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 overflow-hidden",children:[e.jsx("div",{className:"px-5 py-4 border-b border-white/5",children:e.jsx("h3",{className:"text-sm font-semibold text-gray-200",children:"Per-Cycle Breakdown"})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsxs("thead",{children:[e.jsxs("tr",{className:"border-b border-white/5 text-xs text-gray-500 uppercase tracking-wider",children:[e.jsx("th",{className:"text-left px-5 py-3 font-medium",children:"Plan / Cycle"}),e.jsx("th",{className:"text-center px-3 py-3 font-medium",colSpan:5,children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(z,{size:11})," Manual"]})}),e.jsx("th",{className:"text-center px-3 py-3 font-medium",colSpan:5,children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(D,{size:11})," Automated"]})}),e.jsx("th",{className:"text-center px-3 py-3 font-medium",children:"Split"})]}),e.jsxs("tr",{className:"border-b border-white/5 text-[10px] text-gray-600 uppercase",children:[e.jsx("th",{className:"px-5 py-1.5"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Total"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Pass"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Fail"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Rate"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Time"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Total"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Pass"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Fail"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Rate"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Time"}),e.jsx("th",{className:"text-center px-2 py-1.5"})]})]}),e.jsx("tbody",{children:r.map(a=>{const g=a.manual.total,p=a.automated.total,v=g+p,j=v>0?Math.round(p/v*100):0,N=g>0?Math.round(a.manual.passed/g*100):0,k=p>0?Math.round(a.automated.passed/p*100):0;return e.jsxs("tr",{className:"border-b border-white/5 hover:bg-white/[0.02] transition-colors",children:[e.jsxs("td",{className:"px-5 py-3",children:[e.jsx("div",{className:"text-xs font-medium text-gray-200",children:a.planName}),e.jsx("div",{className:"text-[10px] text-gray-500",children:a.cycleName})]}),e.jsx("td",{className:"text-center px-2 py-3 text-xs text-gray-300",children:g||"—"}),e.jsx("td",{className:"text-center px-2 py-3 text-xs text-emerald-400",children:a.manual.passed||"—"}),e.jsx("td",{className:"text-center px-2 py-3 text-xs text-red-400",children:a.manual.failed||"—"}),e.jsx("td",{className:"text-center px-2 py-3",children:g>0?e.jsxs("span",{className:`text-xs font-medium ${N>=80?"text-emerald-400":N>=50?"text-amber-400":"text-red-400"}`,children:[N,"%"]}):e.jsx("span",{className:"text-xs text-gray-600",children:"—"})}),e.jsx("td",{className:"text-center px-2 py-3 text-[10px] text-gray-500",children:d(a.manual.duration)}),e.jsx("td",{className:"text-center px-2 py-3 text-xs text-emerald-300 font-medium",children:p||"—"}),e.jsx("td",{className:"text-center px-2 py-3 text-xs text-emerald-400",children:a.automated.passed||"—"}),e.jsx("td",{className:"text-center px-2 py-3 text-xs text-red-400",children:a.automated.failed||"—"}),e.jsx("td",{className:"text-center px-2 py-3",children:p>0?e.jsxs("span",{className:`text-xs font-medium ${k>=80?"text-emerald-400":k>=50?"text-amber-400":"text-red-400"}`,children:[k,"%"]}):e.jsx("span",{className:"text-xs text-gray-600",children:"—"})}),e.jsx("td",{className:"text-center px-2 py-3 text-[10px] text-gray-500",children:d(a.automated.duration)}),e.jsx("td",{className:"px-3 py-3",children:v>0?e.jsxs("div",{className:"flex items-center justify-center gap-1.5",children:[e.jsxs("div",{className:"flex h-2 w-16 rounded-full overflow-hidden bg-gray-700/50",children:[j>0&&e.jsx("div",{className:"bg-emerald-400 h-full",style:{width:`${j}%`}}),100-j>0&&e.jsx("div",{className:"bg-amber-400/60 h-full",style:{width:`${100-j}%`}})]}),e.jsxs("span",{className:"text-[10px] text-gray-500 w-8",children:[j,"%"]})]}):e.jsx("span",{className:"text-xs text-gray-600",children:"—"})})]},a.cycleId)})})]})})]})]})}function Le(){const[t,n]=se("tab",["health","analytics","automation","defects","cases"],"health");return e.jsxs("div",{className:"min-h-screen bg-surface-0 text-gray-200",children:[e.jsx("div",{className:"border-b border-white/5 bg-surface-1",children:e.jsx("div",{className:"max-w-[1400px] mx-auto px-6 py-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-gray-100 flex items-center gap-3",children:[e.jsx(G,{size:24,className:"text-brand-300"}),"Analytics & Reports"]}),e.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"Test health dashboard, execution analytics, and AI-generated reports"})]}),e.jsx(te,{type:"analytics",formats:["pdf"],label:"Export Report"})]})})}),e.jsx("div",{className:"border-b border-white/5 bg-surface-1",children:e.jsx("div",{className:"max-w-[1400px] mx-auto px-6 flex gap-1",children:pe.map(r=>{const l=r.icon,x=t===r.key;return e.jsxs("button",{onClick:()=>n(r.key),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium border-b-2 transition-colors ${x?"border-brand-400 text-brand-300":"border-transparent text-gray-400 hover:text-gray-200 hover:border-white/10"}`,children:[e.jsx(l,{size:16}),r.label]},r.key)})})}),e.jsxs("div",{className:"max-w-[1400px] mx-auto px-6 py-8",children:[t==="health"&&e.jsx(Ce,{}),t==="analytics"&&e.jsx(Te,{}),t==="automation"&&e.jsx(Ae,{}),t==="defects"&&e.jsx(Se,{}),t==="cases"&&e.jsx($e,{})]})]})}export{Le as AnalyticsPage};
1
+ import{j as e,r as E,R as Z}from"./vendor-react-DOVfxdUy.js";import{u as ee}from"./vendor-query-DkZSMtfn.js";import{u as se}from"./useTabParam-CyYAP90W.js";import{E as te}from"./ExportButton-xrS_AnfS.js";import{aw as ae,ap as re,ax as le,ay as ie,F as ce}from"./useTestManagement-ommXjx0q.js";import{iy as ne}from"./index-BlA8ntjb.js";import{b as G,H as de,cp as W,bQ as D,g as Q,e as V,R as H,dg as X,aD as oe,v as B,s as P,p as O,aq as xe,z as me,u as he,a1 as ue,r as U,j as ge}from"./vendor-icons-Cm92aSc5.js";const pe=[{key:"health",label:"Health Dashboard",icon:de},{key:"analytics",label:"Execution Analytics",icon:W},{key:"automation",label:"Automation Usage",icon:D},{key:"defects",label:"Defect Analytics",icon:Q},{key:"cases",label:"Test Case Overview",icon:V}],je={critical:"bg-red-500/20 text-red-300",high:"bg-orange-500/20 text-orange-300",medium:"bg-amber-500/20 text-amber-300",low:"bg-emerald-500/20 text-emerald-300"},I={passed:"bg-emerald-500",failed:"bg-red-500",blocked:"bg-amber-500",skipped:"bg-gray-500"},be={passed:"text-emerald-400",failed:"text-red-400",blocked:"text-amber-400",skipped:"text-gray-400"};function A(t){return t.replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function q(t){return t?new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"-"}function fe(t){if(!t&&t!==0)return"-";if(t<1e3)return`${Math.round(t)}ms`;if(t<6e4)return`${(t/1e3).toFixed(1)}s`;const n=Math.floor(t/6e4),r=Math.round(t%6e4/1e3);return`${n}m ${r}s`}function Y(t){return t>=75?"text-emerald-400":t>=50?"text-amber-400":"text-red-400"}function J(t){return t>=75?"bg-emerald-500":t>=50?"bg-amber-500":"bg-red-500"}function ye(t){return t>=75?"stroke-emerald-500":t>=50?"stroke-amber-500":"stroke-red-500"}function Ne(t){return t>=90?"Excellent":t>=75?"Good":t>=50?"Fair":t>=25?"Poor":"Critical"}function M(t,n=0,r=100){return Math.min(r,Math.max(n,t))}function R({value:t,color:n,className:r=""}){const l=M(t),x=n||J(l);return e.jsx("div",{className:`h-2 rounded-full bg-white/5 overflow-hidden ${r}`,children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${x}`,style:{width:`${l}%`}})})}function S({icon:t,label:n,value:r,sub:l,color:x}){return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${x||"bg-brand-500/15"}`,children:e.jsx(t,{className:`w-4 h-4 ${x?"":"text-brand-300"}`})}),e.jsx("span",{className:"text-sm text-gray-400",children:n})]}),e.jsx("p",{className:"text-2xl font-bold text-gray-100",children:r}),l&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:l})]})}function z({message:t}){return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-gray-500",children:[e.jsx(G,{className:"w-10 h-10 mb-3 opacity-40"}),e.jsx("p",{className:"text-sm",children:t})]})}function L(){return e.jsxs("div",{className:"space-y-6 animate-pulse",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[...Array(4)].map((t,n)=>e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-white/5"}),e.jsx("div",{className:"h-3 w-24 rounded bg-white/5"})]}),e.jsx("div",{className:"h-6 w-16 rounded bg-white/5"})]},n))}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("div",{className:"h-3 w-32 rounded bg-white/5 mb-4"}),e.jsx("div",{className:"h-32 rounded bg-white/5"})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("div",{className:"h-3 w-40 rounded bg-white/5 mb-4"}),e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((t,n)=>e.jsx("div",{className:"h-8 rounded bg-white/5"},n))})]})]})}function K({message:t}){return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-red-400",children:[e.jsx(O,{className:"w-10 h-10 mb-3 opacity-60"}),e.jsx("p",{className:"text-sm",children:t})]})}function ve({score:t}){const n=M(Math.round(t)),r=80,l=2*Math.PI*r,x=l-n/100*l,h=ye(n),d=Y(n),a=Ne(n);return e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("div",{className:"relative w-52 h-52",children:[e.jsxs("svg",{className:"w-full h-full -rotate-90",viewBox:"0 0 200 200",children:[e.jsx("circle",{cx:"100",cy:"100",r,fill:"none",stroke:"rgba(255,255,255,0.05)",strokeWidth:"12"}),e.jsx("circle",{cx:"100",cy:"100",r,fill:"none",className:h,strokeWidth:"12",strokeLinecap:"round",strokeDasharray:l,strokeDashoffset:x,style:{transition:"stroke-dashoffset 1s ease-out"}})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("span",{className:`text-5xl font-bold ${d}`,children:n}),e.jsx("span",{className:"text-xs text-gray-500 mt-1",children:a})]})]}),e.jsx("p",{className:"text-sm font-medium text-gray-400 mt-3",children:"Test Health Score"})]})}function _({icon:t,label:n,score:r,description:l}){const x=M(Math.round(r)),h=Y(x),d=J(x);return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t,{className:"w-4 h-4 text-gray-400"}),e.jsx("span",{className:"text-sm font-medium text-gray-200",children:n})]}),e.jsx("span",{className:`text-lg font-bold ${h}`,children:x})]}),e.jsx(R,{value:x,color:d,className:"mb-2"}),e.jsx("p",{className:"text-xs text-gray-500",children:l})]})}function we({data:t}){const n=Object.values(t).reduce((r,l)=>r+l,0);return n===0?e.jsx("div",{className:"h-6 rounded-full bg-white/5"}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-6 rounded-full bg-white/5 overflow-hidden flex",children:Object.entries(t).map(([r,l])=>{const x=l/n*100;if(x===0)return null;const h=I[r]||"bg-gray-500";return e.jsx("div",{className:`h-full ${h} transition-all duration-500`,style:{width:`${x}%`},title:`${A(r)}: ${l} (${x.toFixed(1)}%)`},r)})}),e.jsx("div",{className:"flex flex-wrap gap-4",children:Object.entries(t).map(([r,l])=>{const x=n>0?(l/n*100).toFixed(1):"0",h=be[r]||"text-gray-400",d=I[r]||"bg-gray-500";return e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${d}`}),e.jsx("span",{className:h,children:A(r)}),e.jsxs("span",{className:"text-gray-500",children:[l," (",x,"%)"]})]},r)})})]})}function ke({priority:t,total:n,passed:r,failed:l}){const x=je[t]||"bg-gray-500/20 text-gray-300",h=n>0?(r/n*100).toFixed(1):"0",d=n>0?(l/n*100).toFixed(1):"0";return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${x}`,children:A(t)}),e.jsxs("span",{className:"text-sm text-gray-400",children:[n," total"]})]}),e.jsxs("div",{className:"flex gap-4 mb-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-emerald-400",children:"Passed"}),e.jsxs("span",{className:"text-gray-400",children:[r," (",h,"%)"]})]}),e.jsx(R,{value:n>0?r/n*100:0,color:"bg-emerald-500"})]}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-red-400",children:"Failed"}),e.jsxs("span",{className:"text-gray-400",children:[l," (",d,"%)"]})]}),e.jsx(R,{value:n>0?l/n*100:0,color:"bg-red-500"})]})]})]})}function Ce(){const{data:t,isLoading:n,error:r,refetch:l}=ae(),{data:x,isLoading:h}=re();if(n||h)return e.jsx(L,{});if(r)return e.jsx(K,{message:"Failed to load health data"});const a=t||{},g=x||{},p=a.healthScore??a.overallScore??a.overall??a.score??0,v=a.automationCoverage??a.automation_coverage??g.automationCoverage??0,j=a.requirementCoverage??a.requirement_coverage??g.requirementCoverage??0,N=a.executionFreshness??a.execution_freshness??0,k=a.qualityAverage??a.qualityScore??a.quality_score??0,b=a.syncHealth??a.sync_health??0,c=a.staleTestCases??a.stale_test_cases??0,s=a.recentlyUpdated??a.recently_updated??0,u=g.totalTestCases??a.totalTestCases??a.total_test_cases??0,o=g.automatedTestCases??a.automatedCount??a.automated_count??0;return e.jsxs("div",{className:"space-y-8",children:[e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{onClick:()=>l(),className:"flex items-center gap-2 text-xs text-gray-400 hover:text-gray-200 transition-colors",children:[e.jsx(H,{className:"w-3.5 h-3.5"}),"Refresh"]})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(ve,{score:p})}),e.jsx("div",{className:"text-center",children:e.jsxs("p",{className:"text-lg text-gray-400",children:[e.jsx("span",{className:"text-gray-200 font-semibold",children:u})," Test Cases"," ","·"," ",e.jsx("span",{className:"text-gray-200 font-semibold",children:o})," Automated"]})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Health Breakdown"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5 gap-4",children:[e.jsx(_,{icon:X,label:"Automation Coverage",score:v,description:"Percentage of test cases with automation scripts"}),e.jsx(_,{icon:oe,label:"Requirement Coverage",score:j,description:"Requirements with linked test cases"}),e.jsx(_,{icon:B,label:"Execution Freshness",score:N,description:"How recently tests have been executed"}),e.jsx(_,{icon:P,label:"Quality Score",score:k,description:"Average quality across test executions"}),e.jsx(_,{icon:H,label:"Sync Health",score:b,description:"Script mappings and automation sync status"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Activity Indicators"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-lg bg-amber-500/15",children:e.jsx(O,{className:"w-5 h-5 text-amber-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-gray-400",children:"Stale Test Cases"}),e.jsx("p",{className:"text-xs text-gray-500",children:">30 days without update"})]}),e.jsx("span",{className:"text-2xl font-bold text-amber-400",children:c})]}),c>0&&u>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx(R,{value:c/u*100,color:"bg-amber-500"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[(c/u*100).toFixed(1),"% of total test cases"]})]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-lg bg-emerald-500/15",children:e.jsx(P,{className:"w-5 h-5 text-emerald-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-gray-400",children:"Recently Updated"}),e.jsx("p",{className:"text-xs text-gray-500",children:"<7 days since last update"})]}),e.jsx("span",{className:"text-2xl font-bold text-emerald-400",children:s})]}),s>0&&u>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx(R,{value:s/u*100,color:"bg-emerald-500"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[(s/u*100).toFixed(1),"% of total test cases"]})]})]})]})]})]})}function Te(){const{data:t,isLoading:n,error:r,refetch:l}=le(),[x,h]=E.useState(null);if(n)return e.jsx(L,{});if(r)return e.jsx(K,{message:"Failed to load execution analytics"});const d=t||{},a=d.totalExecutions??d.total_executions??0,g=d.passRate??d.pass_rate??0,p=d.failRate??d.fail_rate??0,v=d.avgDuration??d.avg_duration??0,j=d.byStatus??d.by_status??{},N=d.byPriority??d.by_priority??{},k=d.byCycle??d.cycles??d.cycleHistory??d.cycle_history??[],b=d.recentExecutions??d.trends??d.executionTrend??d.execution_trend??[],c=d.flakyTests??d.flaky_tests??[];return e.jsxs("div",{className:"space-y-8",children:[e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{onClick:()=>l(),className:"flex items-center gap-2 text-xs text-gray-400 hover:text-gray-200 transition-colors",children:[e.jsx(H,{className:"w-3.5 h-3.5"}),"Refresh"]})}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(S,{icon:W,label:"Total Executions",value:a.toLocaleString(),color:"bg-brand-500/15"}),e.jsx(S,{icon:P,label:"Pass Rate",value:`${typeof g=="number"?g.toFixed(1):g}%`,color:"bg-emerald-500/15"}),e.jsx(S,{icon:xe,label:"Fail Rate",value:`${typeof p=="number"?p.toFixed(1):p}%`,color:"bg-red-500/15"}),e.jsx(S,{icon:B,label:"Avg Duration",value:fe(v),color:"bg-sky-500/15"})]}),Object.keys(j).length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Status Distribution"}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:e.jsx(we,{data:j})})]}),Object.keys(N).length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Priority Breakdown"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:["critical","high","medium","low"].map(s=>{const u=N[s]||{},o=u.total??u.count??0,f=u.passed??0,y=u.failed??0;return o===0?null:e.jsx(ke,{priority:s,total:o,passed:f,failed:y},s)})})]}),Array.isArray(k)&&k.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Cycle History"}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/5",children:[e.jsx("th",{className:"text-left px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Cycle"}),e.jsx("th",{className:"text-left px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Plan"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Total"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Passed"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Failed"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Pass Rate"})]})}),e.jsx("tbody",{children:k.map((s,u)=>{const o=s.total??0,f=s.passed??0,y=s.failed??0,w=o>0?f/o*100:0,T=s.id||s._id||`cycle-${u}`,$=x===T,i=s.blocked??0,m=s.skipped??0,C=o-f-y-i-m;return e.jsxs(Z.Fragment,{children:[e.jsxs("tr",{className:"border-b border-white/5 last:border-0 hover:bg-white/[0.02] transition-colors cursor-pointer",onClick:()=>h($?null:T),children:[e.jsx("td",{className:"px-4 py-3 text-gray-200 font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[$?e.jsx(me,{className:"w-3.5 h-3.5 text-gray-500"}):e.jsx(he,{className:"w-3.5 h-3.5 text-gray-500"}),s.cycleName||s.cycle_name||s.name||"Unnamed Cycle"]})}),e.jsx("td",{className:"px-4 py-3 text-gray-400",children:s.planName||s.plan_name||"-"}),e.jsx("td",{className:"px-4 py-3 text-center text-gray-300",children:o}),e.jsx("td",{className:"px-4 py-3 text-center text-emerald-400",children:f}),e.jsx("td",{className:"px-4 py-3 text-center text-red-400",children:y}),e.jsx("td",{className:"px-4 py-3 text-center",children:e.jsxs("span",{className:`font-medium ${w>=75?"text-emerald-400":w>=50?"text-amber-400":"text-red-400"}`,children:[w.toFixed(1),"%"]})})]}),$&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"bg-surface-2/50 px-6 py-4 border-b border-white/5",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:"text-xs text-gray-500 w-20",children:"Distribution"}),e.jsxs("div",{className:"flex-1 h-4 rounded-full bg-white/5 overflow-hidden flex",children:[f>0&&e.jsx("div",{className:"h-full bg-emerald-500",style:{width:`${f/o*100}%`},title:`Passed: ${f}`}),y>0&&e.jsx("div",{className:"h-full bg-red-500",style:{width:`${y/o*100}%`},title:`Failed: ${y}`}),i>0&&e.jsx("div",{className:"h-full bg-amber-500",style:{width:`${i/o*100}%`},title:`Blocked: ${i}`}),m>0&&e.jsx("div",{className:"h-full bg-gray-500",style:{width:`${m/o*100}%`},title:`Skipped: ${m}`}),C>0&&e.jsx("div",{className:"h-full bg-sky-500",style:{width:`${C/o*100}%`},title:`In Progress: ${C}`})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-xs",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-emerald-500"})," Passed: ",e.jsx("strong",{className:"text-emerald-400",children:f})," (",o>0?(f/o*100).toFixed(1):0,"%)"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-red-500"})," Failed: ",e.jsx("strong",{className:"text-red-400",children:y})," (",o>0?(y/o*100).toFixed(1):0,"%)"]}),i>0&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-amber-500"})," Blocked: ",e.jsx("strong",{className:"text-amber-400",children:i})]}),m>0&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-500"})," Skipped: ",e.jsx("strong",{className:"text-gray-400",children:m})]}),s.passRate!==void 0&&e.jsxs("span",{className:"text-gray-500",children:["| Pass Rate: ",e.jsxs("strong",{className:w>=75?"text-emerald-400":w>=50?"text-amber-400":"text-red-400",children:[w.toFixed(1),"%"]})]})]})]})})})]},T)})})]})})})]}),Array.isArray(b)&&b.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Execution Trend"}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:(()=>{const s=[...b].sort((o,f)=>String(o.date||o.day||"").localeCompare(String(f.date||f.day||""))).slice(-14),u=Math.max(...s.map(o=>o.total??0),1);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-end gap-1 h-36",children:s.map((o,f)=>{const y=o.total??0,w=o.passed??0,T=o.failed??0,$=y-w-T,i=y/u*100,m=o.date||o.day||"";return e.jsxs("div",{className:"flex-1 h-full flex flex-col items-center justify-end group relative",children:[e.jsxs("div",{className:"absolute -top-10 bg-surface-2 border border-white/10 rounded px-2 py-1 text-xs text-gray-300 opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap z-10 pointer-events-none",children:[q(m),": ",y," total (",w,"P / ",T,"F)"]}),e.jsx("div",{className:"flex-1 w-full flex flex-col justify-end",children:e.jsxs("div",{className:"w-full rounded-t overflow-hidden flex flex-col justify-end",style:{height:`${i}%`,minHeight:y>0?"4px":"0"},children:[w>0&&e.jsx("div",{className:"bg-emerald-500",style:{flex:w}}),T>0&&e.jsx("div",{className:"bg-red-500",style:{flex:T}}),$>0&&e.jsx("div",{className:"bg-gray-500",style:{flex:$}})]})}),f%2===0&&e.jsx("span",{className:"text-[9px] text-gray-600 mt-1",children:(m||"").toString().slice(5)})]},f)})}),e.jsxs("div",{className:"flex items-center gap-4 mt-3 text-xs",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-emerald-500"})," Passed"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-red-500"})," Failed"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-500"})," Other"]}),e.jsxs("span",{className:"ml-auto text-gray-500",children:["Last ",s.length," day",s.length===1?"":"s"]})]})]})})()})]}),Array.isArray(c)&&c.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Unstable Tests"}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/5",children:[e.jsx("th",{className:"text-left px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Test Title"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Fail Rate"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Passed"}),e.jsx("th",{className:"text-center px-4 py-3 text-gray-400 font-medium text-xs uppercase tracking-wider",children:"Failed"})]})}),e.jsx("tbody",{children:[...c].sort((s,u)=>(u.flakyScore??u.flaky_score??0)-(s.flakyScore??s.flaky_score??0)).map((s,u)=>{const o=s.flakyScore??s.flaky_score??0,f=s.passCount??s.pass_count??s.passed??0,y=s.failCount??s.fail_count??s.failed??0,w=s.title??s.testTitle??s.test_title??"Unknown",T=o>=60?"text-red-400":o>=30?"text-amber-400":"text-gray-400",$=o>=60?"bg-red-500":o>=30?"bg-amber-500":"bg-gray-500";return e.jsxs("tr",{className:"border-b border-white/5 last:border-0 hover:bg-white/[0.02]",children:[e.jsx("td",{className:"px-4 py-3 text-gray-200 max-w-xs truncate",children:w}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("div",{className:"w-20 h-2 rounded-full bg-white/5 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${$}`,style:{width:`${M(o)}%`}})}),e.jsxs("span",{className:`text-xs font-medium ${T}`,children:[o.toFixed(0),"%"]})]})}),e.jsx("td",{className:"px-4 py-3 text-center text-emerald-400",children:f}),e.jsx("td",{className:"px-4 py-3 text-center text-red-400",children:y})]},s.id||s._id||u)})})]})})})]}),a===0&&Object.keys(j).length===0&&e.jsx(z,{message:"No execution data available yet. Run some test cycles to see analytics."})]})}function Se(){const{data:t,isLoading:n}=ie();if(n)return e.jsx(L,{});const r=Array.isArray(t)?t:(t==null?void 0:t.defects)??[];if(r.length===0)return e.jsx(z,{message:"No defects found. Create defects in Integrations to see analytics."});const l={},x={},h={};let d=0,a=0,g=0,p=0;for(const c of r)l[c.severity||"unknown"]=(l[c.severity||"unknown"]||0)+1,x[c.status||"open"]=(x[c.status||"open"]||0)+1,h[c.priority||"medium"]=(h[c.priority||"medium"]||0)+1,["open","in_progress","reopened"].includes(c.status)&&d++,["closed","resolved","verified"].includes(c.status)&&a++,c.resolvedAt&&c.createdAt&&(g+=new Date(c.resolvedAt).getTime()-new Date(c.createdAt).getTime(),p++);const v=p>0?Math.round(g/p/36e5):0,j={};for(const c of r){const s=c.createdAt?new Date(c.createdAt).toISOString().slice(0,10):"";s&&(j[s]||(j[s]={total:0,open:0,closed:0}),j[s].total++,["open","in_progress","reopened"].includes(c.status)?j[s].open++:j[s].closed++)}const N=Object.entries(j).sort(([c],[s])=>c.localeCompare(s)).slice(-14),k={critical:"bg-red-500",blocker:"bg-red-600",high:"bg-orange-500",medium:"bg-amber-500",low:"bg-emerald-500",unknown:"bg-gray-500"},b={open:"bg-sky-500",in_progress:"bg-amber-500",resolved:"bg-emerald-500",closed:"bg-gray-500",verified:"bg-emerald-600",reopened:"bg-red-500",rejected:"bg-gray-600",deferred:"bg-violet-500"};return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(S,{icon:Q,label:"Total Defects",value:r.length,color:"bg-red-500/15"}),e.jsx(S,{icon:O,label:"Open Defects",value:d,sub:`${r.length>0?(d/r.length*100).toFixed(1):0}% of total`,color:"bg-amber-500/15"}),e.jsx(S,{icon:P,label:"Closed/Resolved",value:a,sub:`${r.length>0?(a/r.length*100).toFixed(1):0}% of total`,color:"bg-emerald-500/15"}),e.jsx(S,{icon:B,label:"Avg Resolution Time",value:v>0?`${v}h`:"-",sub:p>0?`Based on ${p} resolved defects`:"No resolved defects yet",color:"bg-sky-500/15"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("h4",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Severity Distribution"}),e.jsx("div",{className:"space-y-3",children:["critical","blocker","high","medium","low"].filter(c=>l[c]).map(c=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-gray-400 w-16 capitalize",children:c}),e.jsx("div",{className:"flex-1 h-5 rounded bg-white/5 overflow-hidden",children:e.jsx("div",{className:`h-full ${k[c]||"bg-gray-500"} rounded`,style:{width:`${l[c]/r.length*100}%`}})}),e.jsx("span",{className:"text-xs text-gray-300 w-8 text-right font-medium",children:l[c]}),e.jsxs("span",{className:"text-xs text-gray-500 w-12 text-right",children:[(l[c]/r.length*100).toFixed(0),"%"]})]},c))})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("h4",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Status Distribution"}),e.jsx("div",{className:"space-y-3",children:Object.entries(x).sort(([,c],[,s])=>s-c).map(([c,s])=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-gray-400 w-20 capitalize",children:A(c)}),e.jsx("div",{className:"flex-1 h-5 rounded bg-white/5 overflow-hidden",children:e.jsx("div",{className:`h-full ${b[c]||"bg-gray-500"} rounded`,style:{width:`${s/r.length*100}%`}})}),e.jsx("span",{className:"text-xs text-gray-300 w-8 text-right font-medium",children:s}),e.jsxs("span",{className:"text-xs text-gray-500 w-12 text-right",children:[(s/r.length*100).toFixed(0),"%"]})]},c))})]})]}),N.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Defect Creation Trend"}),e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:e.jsx("div",{className:"flex items-end gap-1 h-32",children:N.map(([c,s],u)=>{const o=Math.max(...N.map(([,y])=>y.total),1),f=s.total/o*100;return e.jsxs("div",{className:"flex-1 h-full flex flex-col items-center justify-end gap-1 group relative",children:[e.jsxs("div",{className:"absolute -top-8 bg-surface-2 border border-white/10 rounded px-2 py-1 text-xs text-gray-300 opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap z-10 pointer-events-none",children:[q(c),": ",s.total," (",s.open," open, ",s.closed," closed)"]}),e.jsx("span",{className:"text-[10px] text-gray-500 opacity-0 group-hover:opacity-100",children:s.total}),e.jsx("div",{className:"flex-1 w-full flex flex-col justify-end",children:e.jsx("div",{className:"w-full rounded-t overflow-hidden flex flex-col justify-end",style:{height:`${f}%`,minHeight:s.total>0?"4px":"0"},children:e.jsx("div",{className:"bg-sky-500/70 flex-1"})})}),u%2===0&&e.jsx("span",{className:"text-[9px] text-gray-600 mt-1",children:c.slice(5)})]},u)})})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Priority Breakdown"}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:["critical","high","medium","low"].map(c=>{const s=h[c]||0,u=r.length>0?(s/r.length*100).toFixed(1):"0",o={critical:"text-red-400",high:"text-orange-400",medium:"text-amber-400",low:"text-emerald-400"};return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4 text-center",children:[e.jsx("p",{className:"text-xs text-gray-500 uppercase mb-1",children:c}),e.jsx("p",{className:`text-2xl font-bold ${o[c]||"text-gray-300"}`,children:s}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[u,"%"]})]},c)})})]})]})}function $e(){var o,f,y,w,T,$;const{data:t,isLoading:n}=ce({limit:1e5});if(n)return e.jsx(L,{});const r=Array.isArray(t)?t:(t==null?void 0:t.testCases)??[],l=r.length;if(l===0)return e.jsx(z,{message:"No test cases found. Create test cases in Test Management to see Test Cases overview."});const x={},h={},d={},a={};let g=0,p=0;const v={};for(const i of r){x[i.status||"draft"]=(x[i.status||"draft"]||0)+1,h[i.priority||"medium"]=(h[i.priority||"medium"]||0)+1,d[i.type||"manual"]=(d[i.type||"manual"]||0)+1;const m=i.automationStatus||i.automation_status||"manual";a[m]=(a[m]||0)+1;const C=i.steps?typeof i.steps=="string"?JSON.parse(i.steps):i.steps:[];if(Array.isArray(C)&&C.length>0?g++:p++,i.createdAt){const F=new Date(i.createdAt).toISOString().slice(0,10);v[F]=(v[F]||0)+1}}const j=Object.entries(v).sort(([i],[m])=>i.localeCompare(m));let N=0;const b=j.map(([i,m])=>(N+=m,{day:i,count:m,cumulative:N})).slice(-30),c=b.length>0?b[b.length-1].cumulative:0,s=a.automated??0,u=l>0?(s/l*100).toFixed(1):"0";return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-4",children:[e.jsx(S,{icon:ge,label:"Total Test Cases",value:l,color:"bg-brand-500/15"}),e.jsx(S,{icon:X,label:"Automated",value:s,sub:`${u}% automation`,color:"bg-violet-500/15"}),e.jsx(S,{icon:P,label:"With Steps",value:g,sub:`${l>0?(g/l*100).toFixed(0):0}% complete`,color:"bg-emerald-500/15"}),e.jsx(S,{icon:O,label:"Without Steps",value:p,sub:"Need step definitions",color:"bg-amber-500/15"}),e.jsx(S,{icon:V,label:"Types",value:Object.keys(d).length,sub:Object.entries(d).map(([i,m])=>`${A(i)}: ${m}`).join(", "),color:"bg-sky-500/15"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("h4",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Status Distribution"}),e.jsx("div",{className:"space-y-3",children:Object.entries(x).sort(([,i],[,m])=>m-i).map(([i,m])=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-gray-400 w-20 capitalize",children:A(i)}),e.jsx("div",{className:"flex-1 h-5 rounded bg-white/5 overflow-hidden",children:e.jsx("div",{className:"h-full bg-brand-500 rounded",style:{width:`${m/l*100}%`}})}),e.jsx("span",{className:"text-xs text-gray-300 w-8 text-right font-medium",children:m})]},i))})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("h4",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Priority Distribution"}),e.jsx("div",{className:"space-y-3",children:["critical","high","medium","low"].filter(i=>h[i]).map(i=>{const m=h[i],C={critical:"bg-red-500",high:"bg-orange-500",medium:"bg-amber-500",low:"bg-emerald-500"};return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-gray-400 w-16 capitalize",children:i}),e.jsx("div",{className:"flex-1 h-5 rounded bg-white/5 overflow-hidden",children:e.jsx("div",{className:`h-full ${C[i]} rounded`,style:{width:`${m/l*100}%`}})}),e.jsx("span",{className:"text-xs text-gray-300 w-8 text-right font-medium",children:m}),e.jsxs("span",{className:"text-xs text-gray-500 w-12 text-right",children:[(m/l*100).toFixed(0),"%"]})]},i)})})]})]}),b.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:["Test Case Growth ",e.jsx("span",{className:"text-gray-500 font-normal",children:"(Last 30 days)"})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("div",{className:"flex items-end gap-0.5 h-40",children:b.map((i,m)=>{const C=c>0?i.cumulative/c*100:0;return e.jsxs("div",{className:"flex-1 h-full flex flex-col items-center justify-end group relative",children:[e.jsxs("div",{className:"absolute -top-10 bg-surface-2 border border-white/10 rounded px-2 py-1 text-xs text-gray-300 opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap z-10 pointer-events-none",children:[q(i.day),": +",i.count," (Total: ",i.cumulative,")"]}),e.jsx("div",{className:"flex-1 w-full flex flex-col justify-end",children:e.jsx("div",{className:"w-full bg-gradient-to-t from-brand-600/80 to-brand-400/60 rounded-t transition-all duration-300 group-hover:from-brand-500 group-hover:to-brand-300",style:{height:`${C}%`,minHeight:"2px"}})}),m%5===0&&e.jsx("span",{className:"text-[9px] text-gray-600 mt-1",children:i.day.slice(5)})]},m)})}),e.jsxs("div",{className:"flex items-center justify-between mt-3 text-xs text-gray-500",children:[e.jsxs("span",{children:["Started: ",(((o=b[0])==null?void 0:o.cumulative)??0)-(((f=b[0])==null?void 0:f.count)??0)," test cases"]}),e.jsxs("span",{children:["Current: ",(y=b[b.length-1])==null?void 0:y.cumulative," test cases"]}),e.jsxs("span",{className:"text-emerald-400",children:["+",(((w=b[b.length-1])==null?void 0:w.cumulative)??0)-((((T=b[0])==null?void 0:T.cumulative)??0)-((($=b[0])==null?void 0:$.count)??0))," new"]})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4",children:"Automation Status"}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("div",{className:"h-6 rounded-full bg-white/5 overflow-hidden flex mb-3",children:Object.entries(a).map(([i,m])=>{const C=m/l*100;if(C===0)return null;const F={automated:"bg-emerald-500",manual:"bg-gray-500",in_progress:"bg-amber-500",planned:"bg-sky-500"};return e.jsx("div",{className:`h-full ${F[i]||"bg-gray-500"}`,style:{width:`${C}%`},title:`${A(i)}: ${m}`},i)})}),e.jsx("div",{className:"flex flex-wrap gap-4",children:Object.entries(a).map(([i,m])=>{const C={automated:"text-emerald-400",manual:"text-gray-400",in_progress:"text-amber-400",planned:"text-sky-400"},F={automated:"bg-emerald-500",manual:"bg-gray-500",in_progress:"bg-amber-500",planned:"bg-sky-500"};return e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${F[i]||"bg-gray-500"}`}),e.jsx("span",{className:C[i]||"text-gray-400",children:A(i)}),e.jsxs("span",{className:"text-gray-500",children:[m," (",(m/l*100).toFixed(1),"%)"]})]},i)})})]})]})]})}function Ae(){const{data:t,isLoading:n}=ee({queryKey:["tm-automation-usage"],queryFn:ne}),r=E.useMemo(()=>{const a=(t==null?void 0:t.cycles)||[];return Array.isArray(a)?a:[]},[t]),l=E.useMemo(()=>{let a=0,g=0,p=0,v=0,j=0,N=0,k=0,b=0;for(const s of r)a+=s.manual.total,g+=s.manual.passed,p+=s.manual.failed,v+=s.manual.duration,j+=s.automated.total,N+=s.automated.passed,k+=s.automated.failed,b+=s.automated.duration;const c=a+j;return{manualTotal:a,manualPassed:g,manualFailed:p,manualDuration:v,autoTotal:j,autoPassed:N,autoFailed:k,autoDuration:b,grandTotal:c}},[r]);if(n)return e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(ue,{className:"w-6 h-6 animate-spin text-brand-400"})});if(r.length===0)return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[e.jsx(D,{className:"w-12 h-12 text-gray-600 mb-3"}),e.jsx("h3",{className:"text-gray-300 font-medium",children:"No Cycle Executions Yet"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Execute test cycles to see automation usage statistics"})]});const x=l.grandTotal>0?Math.round(l.autoTotal/l.grandTotal*100):0,h=100-x,d=a=>a>6e4?`${(a/6e4).toFixed(1)}m`:a>0?`${(a/1e3).toFixed(1)}s`:"—";return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"Total Executions"}),e.jsx("div",{className:"text-2xl font-bold text-gray-100",children:l.grandTotal}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:["Across ",r.length," cycle",r.length!==1?"s":""]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-500 mb-1",children:[e.jsx(D,{size:12})," Automated"]}),e.jsx("div",{className:"text-2xl font-bold text-emerald-300",children:l.autoTotal}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:[x,"% of total · Pass: ",l.autoTotal>0?Math.round(l.autoPassed/l.autoTotal*100):0,"%"]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-500 mb-1",children:[e.jsx(U,{size:12})," Manual"]}),e.jsx("div",{className:"text-2xl font-bold text-amber-300",children:l.manualTotal}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:[h,"% of total · Pass: ",l.manualTotal>0?Math.round(l.manualPassed/l.manualTotal*100):0,"%"]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"Automation Rate"}),e.jsxs("div",{className:"text-2xl font-bold text-emerald-300",children:[x,"%"]}),e.jsx("div",{className:"w-full bg-gray-700/50 rounded-full h-2 mt-2",children:e.jsx("div",{className:"bg-emerald-400 h-2 rounded-full transition-all",style:{width:`${x}%`}})})]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-200 mb-3",children:"Overall Manual vs Automated Split"}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("div",{className:"flex-1",children:e.jsxs("div",{className:"flex h-8 rounded-lg overflow-hidden",children:[x>0&&e.jsx("div",{className:"bg-emerald-500/60 flex items-center justify-center text-xs font-medium text-white transition-all",style:{width:`${x}%`},children:x>10&&`${x}% Auto`}),h>0&&e.jsx("div",{className:"bg-amber-500/50 flex items-center justify-center text-xs font-medium text-white transition-all",style:{width:`${h}%`},children:h>10&&`${h}% Manual`})]})})}),e.jsxs("div",{className:"flex items-center gap-4 mt-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-400",children:[e.jsx("div",{className:"w-3 h-3 rounded bg-emerald-500/60"})," Automated (",l.autoTotal,")"]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-400",children:[e.jsx("div",{className:"w-3 h-3 rounded bg-amber-500/50"})," Manual (",l.manualTotal,")"]})]})]}),e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 overflow-hidden",children:[e.jsx("div",{className:"px-5 py-4 border-b border-white/5",children:e.jsx("h3",{className:"text-sm font-semibold text-gray-200",children:"Per-Cycle Breakdown"})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsxs("thead",{children:[e.jsxs("tr",{className:"border-b border-white/5 text-xs text-gray-500 uppercase tracking-wider",children:[e.jsx("th",{className:"text-left px-5 py-3 font-medium",children:"Plan / Cycle"}),e.jsx("th",{className:"text-center px-3 py-3 font-medium",colSpan:5,children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(U,{size:11})," Manual"]})}),e.jsx("th",{className:"text-center px-3 py-3 font-medium",colSpan:5,children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(D,{size:11})," Automated"]})}),e.jsx("th",{className:"text-center px-3 py-3 font-medium",children:"Split"})]}),e.jsxs("tr",{className:"border-b border-white/5 text-[10px] text-gray-600 uppercase",children:[e.jsx("th",{className:"px-5 py-1.5"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Total"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Pass"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Fail"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Rate"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Time"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Total"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Pass"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Fail"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Rate"}),e.jsx("th",{className:"text-center px-2 py-1.5",children:"Time"}),e.jsx("th",{className:"text-center px-2 py-1.5"})]})]}),e.jsx("tbody",{children:r.map(a=>{const g=a.manual.total,p=a.automated.total,v=g+p,j=v>0?Math.round(p/v*100):0,N=g>0?Math.round(a.manual.passed/g*100):0,k=p>0?Math.round(a.automated.passed/p*100):0;return e.jsxs("tr",{className:"border-b border-white/5 hover:bg-white/[0.02] transition-colors",children:[e.jsxs("td",{className:"px-5 py-3",children:[e.jsx("div",{className:"text-xs font-medium text-gray-200",children:a.planName}),e.jsx("div",{className:"text-[10px] text-gray-500",children:a.cycleName})]}),e.jsx("td",{className:"text-center px-2 py-3 text-xs text-gray-300",children:g||"—"}),e.jsx("td",{className:"text-center px-2 py-3 text-xs text-emerald-400",children:a.manual.passed||"—"}),e.jsx("td",{className:"text-center px-2 py-3 text-xs text-red-400",children:a.manual.failed||"—"}),e.jsx("td",{className:"text-center px-2 py-3",children:g>0?e.jsxs("span",{className:`text-xs font-medium ${N>=80?"text-emerald-400":N>=50?"text-amber-400":"text-red-400"}`,children:[N,"%"]}):e.jsx("span",{className:"text-xs text-gray-600",children:"—"})}),e.jsx("td",{className:"text-center px-2 py-3 text-[10px] text-gray-500",children:d(a.manual.duration)}),e.jsx("td",{className:"text-center px-2 py-3 text-xs text-emerald-300 font-medium",children:p||"—"}),e.jsx("td",{className:"text-center px-2 py-3 text-xs text-emerald-400",children:a.automated.passed||"—"}),e.jsx("td",{className:"text-center px-2 py-3 text-xs text-red-400",children:a.automated.failed||"—"}),e.jsx("td",{className:"text-center px-2 py-3",children:p>0?e.jsxs("span",{className:`text-xs font-medium ${k>=80?"text-emerald-400":k>=50?"text-amber-400":"text-red-400"}`,children:[k,"%"]}):e.jsx("span",{className:"text-xs text-gray-600",children:"—"})}),e.jsx("td",{className:"text-center px-2 py-3 text-[10px] text-gray-500",children:d(a.automated.duration)}),e.jsx("td",{className:"px-3 py-3",children:v>0?e.jsxs("div",{className:"flex items-center justify-center gap-1.5",children:[e.jsxs("div",{className:"flex h-2 w-16 rounded-full overflow-hidden bg-gray-700/50",children:[j>0&&e.jsx("div",{className:"bg-emerald-400 h-full",style:{width:`${j}%`}}),100-j>0&&e.jsx("div",{className:"bg-amber-400/60 h-full",style:{width:`${100-j}%`}})]}),e.jsxs("span",{className:"text-[10px] text-gray-500 w-8",children:[j,"%"]})]}):e.jsx("span",{className:"text-xs text-gray-600",children:"—"})})]},a.cycleId)})})]})})]})]})}function Le(){const[t,n]=se("tab",["health","analytics","automation","defects","cases"],"health");return e.jsxs("div",{className:"min-h-screen bg-surface-0 text-gray-200",children:[e.jsx("div",{className:"border-b border-white/5 bg-surface-1",children:e.jsx("div",{className:"max-w-[1400px] mx-auto px-6 py-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-gray-100 flex items-center gap-3",children:[e.jsx(G,{size:24,className:"text-brand-300"}),"Analytics & Reports"]}),e.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"Test health dashboard, execution analytics, and AI-generated reports"})]}),e.jsx(te,{type:"analytics",formats:["pdf"],label:"Export Report"})]})})}),e.jsx("div",{className:"border-b border-white/5 bg-surface-1",children:e.jsx("div",{className:"max-w-[1400px] mx-auto px-6 flex gap-1",children:pe.map(r=>{const l=r.icon,x=t===r.key;return e.jsxs("button",{onClick:()=>n(r.key),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium border-b-2 transition-colors ${x?"border-brand-400 text-brand-300":"border-transparent text-gray-400 hover:text-gray-200 hover:border-white/10"}`,children:[e.jsx(l,{size:16}),r.label]},r.key)})})}),e.jsxs("div",{className:"max-w-[1400px] mx-auto px-6 py-8",children:[t==="health"&&e.jsx(Ce,{}),t==="analytics"&&e.jsx(Te,{}),t==="automation"&&e.jsx(Ae,{}),t==="defects"&&e.jsx(Se,{}),t==="cases"&&e.jsx($e,{})]})]})}export{Le as AnalyticsPage};
@@ -0,0 +1 @@
1
+ import{r as b,j as e}from"./vendor-react-DOVfxdUy.js";import{f as D}from"./formatDate-T65-Y6Mi.js";import{u as z}from"./vendor-query-DkZSMtfn.js";import{fL as P,fS as M,fT as q,fU as J}from"./index-BlA8ntjb.js";import{l as C,a6 as $,z as G,u as F,ch as K,k as y,a9 as u,S,a_ as k,ac as L,a as h,a3 as B,da as O,aD as i,D as H,aj as Q}from"./vendor-icons-Cm92aSc5.js";const T={"auth.login":{icon:e.jsx(Q,{size:14}),color:"text-emerald-400"},"auth.logout":{icon:e.jsx(H,{size:14}),color:"text-gray-400"},"auth.login_failed":{icon:e.jsx(h,{size:14}),color:"text-red-400"},"auth.password_change":{icon:e.jsx(i,{size:14}),color:"text-amber-400"},"auth.setup":{icon:e.jsx(i,{size:14}),color:"text-brand-400"},"auth.2fa_enabled":{icon:e.jsx(i,{size:14}),color:"text-emerald-400"},"auth.2fa_disabled":{icon:e.jsx(i,{size:14}),color:"text-amber-400"},"auth.2fa_failed":{icon:e.jsx(h,{size:14}),color:"text-red-400"},"auth.2fa_recovery_used":{icon:e.jsx(i,{size:14}),color:"text-amber-400"},"user.2fa_reset":{icon:e.jsx(i,{size:14}),color:"text-amber-400"},"user.create":{icon:e.jsx(O,{size:14}),color:"text-brand-400"},"user.update":{icon:e.jsx(y,{size:14}),color:"text-sky-400"},"user.delete":{icon:e.jsx(h,{size:14}),color:"text-red-400"},"user.role_change":{icon:e.jsx(i,{size:14}),color:"text-amber-400"},"user.disable":{icon:e.jsx(h,{size:14}),color:"text-red-400"},"user.enable":{icon:e.jsx(O,{size:14}),color:"text-emerald-400"},"run.start":{icon:e.jsx(B,{size:14}),color:"text-emerald-400"},"run.cancel":{icon:e.jsx(h,{size:14}),color:"text-amber-400"},"file.create":{icon:e.jsx(L,{size:14}),color:"text-sky-400"},"file.update":{icon:e.jsx(L,{size:14}),color:"text-sky-400"},"file.delete":{icon:e.jsx(L,{size:14}),color:"text-red-400"},"git.commit":{icon:e.jsx(k,{size:14}),color:"text-emerald-400"},"git.push":{icon:e.jsx(k,{size:14}),color:"text-brand-400"},"git.pull":{icon:e.jsx(k,{size:14}),color:"text-sky-400"},"ai.generate":{icon:e.jsx(S,{size:14}),color:"text-purple-400"},"ai.fix":{icon:e.jsx(S,{size:14}),color:"text-purple-400"},"ai.chat":{icon:e.jsx(S,{size:14}),color:"text-purple-400"},"token.create":{icon:e.jsx(u,{size:14}),color:"text-brand-400"},"token.renew":{icon:e.jsx(u,{size:14}),color:"text-sky-400"},"token.revoke":{icon:e.jsx(u,{size:14}),color:"text-red-400"},"token.use":{icon:e.jsx(u,{size:14}),color:"text-gray-400"},"token.mcp_end":{icon:e.jsx(u,{size:14}),color:"text-red-400"}};function V(t){return T[t]?T[t]:t.startsWith("settings.")?/_(delete|remove|disconnect|reset)$/.test(t)?{icon:e.jsx(y,{size:14}),color:"text-red-400"}:{icon:e.jsx(y,{size:14}),color:"text-sky-400"}:{icon:e.jsx(y,{size:14}),color:"text-gray-400"}}const p=50,W=[{value:"",label:"All Actions"},{value:"auth.*",label:"Authentication"},{value:"user.*",label:"User Management"},{value:"run.*",label:"Test Runs"},{value:"file.*",label:"File Operations"},{value:"git.*",label:"Git Operations"},{value:"ai.*",label:"AI Actions"},{value:"settings.*",label:"Settings"},{value:"token.*",label:"Access Tokens"}];function oe(){const[t,a]=b.useState(0),[o,r]=b.useState(""),[l,N]=b.useState(""),[E,U]=b.useState(null),{data:v}=z({queryKey:["users"],queryFn:P}),{data:n}=z({queryKey:["audit-stats"],queryFn:M}),{data:c,isLoading:I,isFetching:g}=z({queryKey:["audit",t,o,l],placeholderData:s=>s,queryFn:()=>q({limit:p,offset:t*p,action:o||void 0,userId:l||void 0})}),A=(c==null?void 0:c.entries)??[],m=(c==null?void 0:c.total)??0,x=Math.ceil(m/p),R=async()=>{try{const s=await J(),j=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),d=URL.createObjectURL(j),w=document.createElement("a");w.href=d,w.download=`audit-log-${new Date().toISOString().slice(0,10)}.json`,w.click(),URL.revokeObjectURL(d)}catch{}};return e.jsxs("div",{className:"min-h-screen bg-surface-0 text-gray-200",children:[e.jsx("div",{className:"border-b border-white/5 bg-surface-1",children:e.jsx("div",{className:"max-w-[1400px] mx-auto px-6 py-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-gray-100 flex items-center gap-3",children:[e.jsx(C,{size:24,className:"text-brand-300"}),"Audit Log",e.jsxs("span",{className:"text-sm font-normal bg-brand-500/15 text-brand-300 px-2.5 py-0.5 rounded-full",children:[m.toLocaleString()," ",m===1?"entry":"entries"]})]}),e.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"Track all user actions and system events"})]}),e.jsxs("button",{onClick:R,className:"flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-brand-600 hover:bg-brand-500 rounded-lg transition-colors",children:[e.jsx($,{size:16}),"Export JSON"]})]})})}),e.jsxs("div",{className:"max-w-[1400px] mx-auto px-6 py-8 space-y-6",children:[n&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(f,{label:"Total Events",value:n.totalEntries}),e.jsx(f,{label:"Unique Users",value:n.uniqueUsers}),e.jsx(f,{label:"Logins (24h)",value:n.recentLoginCount,color:"emerald"}),e.jsx(f,{label:"Failed Logins (24h)",value:n.recentFailedLogins,color:n.recentFailedLogins>0?"red":"gray"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("select",{value:o,onChange:s=>{r(s.target.value),a(0)},className:"px-3.5 py-2 bg-surface-2 border border-white/10 rounded-xl text-[15px] text-gray-300 focus:outline-none focus:border-brand-500/50",children:W.map(s=>e.jsx("option",{value:s.value,children:s.label},s.value))}),e.jsxs("select",{value:l,onChange:s=>{N(s.target.value),a(0)},className:"px-3.5 py-2 bg-surface-2 border border-white/10 rounded-xl text-[15px] text-gray-300 focus:outline-none focus:border-brand-500/50",children:[e.jsx("option",{value:"",children:"All Users"}),v==null?void 0:v.users.map(s=>e.jsxs("option",{value:s.id,children:[s.displayName," (@",s.username,")"]},s.id))]})]}),I?e.jsx("div",{className:"text-sm text-gray-500",children:"Loading audit log..."}):A.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(C,{size:40,className:"mx-auto text-gray-600 mb-3"}),e.jsx("p",{className:"text-gray-400",children:"No audit entries found"}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:"Entries will appear as users perform actions"})]}):e.jsx("div",{className:"bg-surface-1 rounded-xl border border-white/5 overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/5 text-sm text-gray-500",children:[e.jsx("th",{className:"text-left px-4 py-3 font-medium w-8"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium",children:"Timestamp"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium",children:"User"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium",children:"Action"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium",children:"Resource"})]})}),e.jsx("tbody",{className:"divide-y divide-white/5",children:A.map(s=>{const j=V(s.action),d=E===s.id;return e.jsxs(Z,{children:[e.jsxs("tr",{className:"hover:bg-white/[0.02] cursor-pointer",onClick:()=>U(d?null:s.id),children:[e.jsx("td",{className:"px-4 py-2.5 text-gray-500",children:s.details?d?e.jsx(G,{size:14}):e.jsx(F,{size:14}):null}),e.jsx("td",{className:"px-4 py-2.5 text-xs text-gray-400 whitespace-nowrap",children:Y(s.timestamp)}),e.jsxs("td",{className:"px-4 py-2.5 text-sm text-gray-300",children:["@",s.username]}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsxs("span",{className:`flex items-center gap-1.5 text-sm ${j.color}`,children:[j.icon,ee(s.action)]})}),e.jsx("td",{className:"px-4 py-2.5 text-xs text-gray-500",children:s.resourceType&&e.jsxs("span",{children:[s.resourceType,s.resourceId&&e.jsxs("span",{className:"text-gray-600",children:[" / ",s.resourceId]})]})})]}),d&&s.details&&e.jsx("tr",{className:"bg-surface-2/50",children:e.jsx("td",{colSpan:5,className:"px-8 py-3",children:e.jsx(X,{details:s.details})})})]},s.id)})})]})}),x>1&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsxs("span",{className:"text-gray-500",children:["Showing ",(t*p+1).toLocaleString(),"–",Math.min((t+1)*p,m).toLocaleString()," of ",m.toLocaleString()]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>a(0),disabled:t===0||g,className:"h-8 px-3 rounded-lg border border-white/10 text-gray-300 hover:bg-white/5 disabled:opacity-40 disabled:cursor-not-allowed",children:"First"}),e.jsxs("button",{onClick:()=>a(Math.max(0,t-1)),disabled:t===0||g,className:"flex items-center gap-1 h-8 px-3 rounded-lg border border-white/10 text-gray-300 hover:bg-white/5 disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(K,{size:14})," Previous"]}),e.jsxs("span",{className:"text-gray-400 tabular-nums min-w-[96px] text-center",children:["Page ",t+1," of ",x]}),e.jsxs("button",{onClick:()=>a(Math.min(x-1,t+1)),disabled:t>=x-1||g,className:"flex items-center gap-1 h-8 px-3 rounded-lg border border-white/10 text-gray-300 hover:bg-white/5 disabled:opacity-40 disabled:cursor-not-allowed",children:["Next ",e.jsx(F,{size:14})]}),e.jsx("button",{onClick:()=>a(x-1),disabled:t>=x-1||g,className:"h-8 px-3 rounded-lg border border-white/10 text-gray-300 hover:bg-white/5 disabled:opacity-40 disabled:cursor-not-allowed",children:"Last"})]})]})]})]})}function Z({children:t}){return e.jsx(e.Fragment,{children:t})}function _(t){return t===void 0?"":typeof t=="string"?t:JSON.stringify(t)}function X({details:t}){const a=Array.isArray(t.changes)?t.changes:null,o=Object.fromEntries(Object.entries(t).filter(([l])=>!["changes","tab","item","moreChanges"].includes(l))),r=Object.keys(o).length>0;return!a&&typeof t.tab!="string"?e.jsx("pre",{className:"text-xs text-gray-400 font-mono whitespace-pre-wrap",children:JSON.stringify(t,null,2)}):e.jsxs("div",{className:"space-y-3",children:[typeof t.tab=="string"&&e.jsxs("p",{className:"text-xs text-gray-400",children:["Settings › ",e.jsx("span",{className:"text-gray-300",children:t.tab}),typeof t.item=="string"&&e.jsxs(e.Fragment,{children:[" › ",e.jsx("span",{className:"text-gray-300",children:t.item})]})]}),a&&a.length>0&&e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-gray-500 text-left",children:[e.jsx("th",{className:"py-1 pr-4 font-medium w-1/3",children:"Field"}),e.jsx("th",{className:"py-1 pr-4 font-medium w-1/3",children:"Before"}),e.jsx("th",{className:"py-1 font-medium w-1/3",children:"After"})]})}),e.jsx("tbody",{className:"divide-y divide-white/5",children:a.map((l,N)=>e.jsxs("tr",{className:"align-top",children:[e.jsx("td",{className:"py-1.5 pr-4 font-mono text-gray-300 break-all",children:l.field}),e.jsx("td",{className:"py-1.5 pr-4 font-mono break-all",children:l.from===void 0?e.jsx("span",{className:"text-gray-600 italic",children:"not set"}):e.jsx("span",{className:"text-red-400",children:_(l.from)})}),e.jsx("td",{className:"py-1.5 font-mono break-all",children:l.to===void 0?e.jsx("span",{className:"text-gray-600 italic",children:"removed"}):e.jsx("span",{className:"text-emerald-400",children:_(l.to)})})]},N))})]}),typeof t.moreChanges=="number"&&t.moreChanges>0&&e.jsxs("p",{className:"text-xs text-gray-500",children:["…and ",t.moreChanges," more field(s)"]}),r&&e.jsx("pre",{className:"text-xs text-gray-400 font-mono whitespace-pre-wrap",children:JSON.stringify(o,null,2)})]})}function f({label:t,value:a,color:o="gray"}){const r={gray:"text-gray-200",emerald:"text-emerald-400",red:"text-red-400",brand:"text-brand-400"};return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsx("p",{className:"text-sm text-gray-500",children:t}),e.jsx("p",{className:`text-2xl font-bold mt-1 ${r[o]??r.gray}`,children:a.toLocaleString()})]})}function Y(t){const a=new Date(t),r=new Date().getTime()-a.getTime();return r<6e4?"Just now":r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:D(a)}function ee(t){return t.replace(/\./g," ").replace(/_/g," ").replace(/\b\w/g,a=>a.toUpperCase()).replace(/\b2fa\b/gi,"2FA")}export{oe as AuditLogPage};