@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,19 @@
1
+ import{r as x,j as e,e as jt,L as vt}from"./vendor-react-DOVfxdUy.js";import{u as Me,a as ae,c as ge}from"./vendor-query-DkZSMtfn.js";import{$ as Nt,a0 as wt,eG as ct,eH as kt,eI as Ct,eJ as St,eK as zt,eL as $t,eM as Et,eN as Pt,a1 as Rt,eO as Dt,b as Ke,eP as At,eQ as qt,eR as Ot,eS as We,eT as It,eU as Tt,eV as Ft,eW as Lt,eX as Vt,a3 as Ut,eY as Ht,eZ as Bt,e_ as _t}from"./index-BlA8ntjb.js";import{c_ as $e,b5 as pe,ah as we,X as he,z as oe,u as xe,F as He,c$ as Ye,b7 as Xe,b8 as ie,a3 as Be,bJ as Mt,ai as Ee,aM as Ze,bt as et,s as je,aq as ve,Q as Kt,a1 as Te,a7 as dt,am as xt,v as Le,av as Jt,cY as Ie,ad as mt,a6 as Fe,bn as Je,O as ze,aa as Qt,ab as Gt,I as Wt,a as Yt,cq as tt,ak as Xt,E as Zt,J as es,cC as st,d0 as ts}from"./vendor-icons-Cm92aSc5.js";import{u as ut}from"./useTabParam-CyYAP90W.js";import{F as Qe}from"./index-DLmlY2Ol.js";import{u as Ge}from"./useChartTheme-CTIe6M63.js";import{f as pt}from"./formatDate-T65-Y6Mi.js";function ss(){return Me({queryKey:["api-collections"],queryFn:Nt})}function as(t){return Me({queryKey:["api-collection",t],queryFn:()=>wt(t),enabled:!!t,placeholderData:a=>a})}function rs(){const t=ae();return ge({mutationFn:a=>Ct(a),onSuccess:()=>{t.invalidateQueries({queryKey:["api-collections"]})}})}function ns(){const t=ae();return ge({mutationFn:({id:a,data:s})=>zt(a,s),onSuccess:(a,s)=>{t.invalidateQueries({queryKey:["api-collections"]}),t.invalidateQueries({queryKey:["api-collection",s.id]})}})}function ls(){const t=ae();return ge({mutationFn:a=>St(a),onSuccess:()=>{t.invalidateQueries({queryKey:["api-collections"]})}})}function is(){const t=ae();return ge({mutationFn:({collectionId:a,request:s,folderId:n})=>ct(a,s,n),onSuccess:(a,s)=>{t.invalidateQueries({queryKey:["api-collection",s.collectionId]})}})}function os(){const t=ae();return ge({mutationFn:({collectionId:a,requestId:s})=>Pt(a,s),onSuccess:(a,s)=>{t.invalidateQueries({queryKey:["api-collection",s.collectionId]})}})}function cs(){const t=ae();return ge({mutationFn:({collectionId:a,name:s})=>$t(a,s),onSuccess:(a,s)=>{t.invalidateQueries({queryKey:["api-collection",s.collectionId]})}})}function ds(){const t=ae();return ge({mutationFn:({collectionId:a,folderId:s})=>Et(a,s),onSuccess:(a,s)=>{t.invalidateQueries({queryKey:["api-collection",s.collectionId]})}})}function xs(){const t=ae();return ge({mutationFn:({request:a,variables:s,collectionId:n,environmentId:d})=>kt(a,s,n,d),onSuccess:()=>{t.invalidateQueries({queryKey:["api-history"]})}})}function ms(t=50){return Me({queryKey:["api-history",t],queryFn:()=>Rt(t)})}function us(){const t=ae();return ge({mutationFn:Dt,onSuccess:()=>{t.invalidateQueries({queryKey:["api-history"]})}})}const ps={GET:"text-emerald-400",POST:"text-blue-400",PUT:"text-amber-400",PATCH:"text-brand-400",DELETE:"text-red-400",HEAD:"text-purple-400",OPTIONS:"text-gray-400"};function hs({collections:t,selectedCollection:a,selectedRequestId:s,onSelectCollection:n,onSelectRequest:d,onImport:c,onRunChain:m}){const[b,i]=x.useState(new Set),[p,u]=x.useState(new Set);x.useEffect(()=>{if(!a||!s)return;const h=a.folders.find(V=>V.requests.some(g=>g.id===s)),R=a.requests.some(V=>V.id===s);!h&&!R||(i(V=>V.has(a.id)?V:new Set(V).add(a.id)),h&&u(V=>V.has(h.id)?V:new Set(V).add(h.id)))},[a,s]);const[l,w]=x.useState(!1),[f,S]=x.useState(""),[z,H]=x.useState(null),[F,q]=x.useState(""),[y,P]=x.useState(null),[M,K]=x.useState(""),[r,k]=x.useState(null),[v,L]=x.useState(""),[A,Y]=x.useState(null),{toast:O}=Ke(),re=rs(),me=ls(),ue=ns(),Ne=cs(),be=ds(),Z=os(),ce=(h,R,V)=>{Y({type:h,name:R,action:V})},fe=()=>{if(!A)return;A.action();const h=A.type==="collection"?"Collection":A.type==="folder"?"Folder":"Request";O("success",`${h} "${A.name}" deleted`),Y(null)},[ne,ee]=x.useState(null),[B,X]=x.useState(null),te=x.useRef(!1),le=ae(),ke=async(h,R,V)=>{const g={...h,id:`req-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,name:`${h.name} (Copy)`};try{await ct(R,g,V),le.invalidateQueries({queryKey:["api-collection",R]}),O("success",`Duplicated "${h.name}"`)}catch{O("error","Failed to duplicate request")}},ye=x.useRef(null),se=h=>{ye.current&&clearTimeout(ye.current),ye.current=setTimeout(()=>{le.refetchQueries({queryKey:["api-collection",h]})},500)},o=(h,R)=>{te.current=!0;const V=ne,g=a;if(ee(null),X(null),!V||!g)return;const de=g.id,Ce=(V.folderId||null)===h;Ce&&!R||(async()=>{var Re;try{if(Ce&&R){const $=(h?((Re=g.folders.find(D=>D.id===h))==null?void 0:Re.requests)||[]:g.requests).map(D=>D.id).filter(D=>D!==V.req.id),U=R==="__end__"?$.length:$.indexOf(R);$.splice(U>=0?U:$.length,0,V.req.id),await qt(de,h,$),O("success",`Reordered "${V.req.name}"`)}else await Ot(de,V.req.id,h),O("success",`Moved "${V.req.name}" to ${h?"folder":"root"}`);se(de)}catch{O("error","Failed to move request"),se(de)}})()},C=h=>{const R=new Set(b);R.has(h)?R.delete(h):R.add(h),i(R),n(h)},N=h=>{const R=new Set(p);R.has(h)?R.delete(h):R.add(h),u(R)},T=()=>{f.trim()&&re.mutate({name:f.trim()},{onSuccess:()=>{w(!1),S(""),O("success","Collection created")},onError:h=>O("error",String(h))})},I=h=>{F.trim()&&Ne.mutate({collectionId:h,name:F.trim()},{onSuccess:()=>{H(null),q(""),O("success","Folder created")},onError:R=>O("error",String(R))})},G=(h,R)=>{P(h),K(R)},_=h=>{if(!M.trim()){P(null);return}ue.mutate({id:h,data:{name:M.trim()}},{onSuccess:()=>{P(null),O("success","Collection renamed")},onError:R=>{O("error",String(R))}})},W=(h,R)=>{k(h),L(R)},Q=async(h,R)=>{if(!v.trim()){k(null);return}try{await At(h,R,{name:v.trim()}),k(null),O("success","Folder renamed"),n(h)}catch(V){O("error",String(V))}};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-white/5 flex-shrink-0",children:[e.jsx("span",{className:"text-sm font-semibold uppercase text-gray-500 tracking-wider",children:"Collections"}),e.jsxs("div",{className:"flex gap-1",children:[c&&e.jsx("button",{onClick:c,className:"p-1 text-gray-500 hover:text-gray-300",title:"Import",children:e.jsx($e,{size:13})}),e.jsx("button",{onClick:()=>w(!0),className:"p-1 text-gray-500 hover:text-gray-300",title:"New Collection",children:e.jsx(pe,{size:13})})]})]}),l&&e.jsx("div",{className:"px-3 py-2 border-b border-white/5",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{autoFocus:!0,value:f,onChange:h=>S(h.target.value),onKeyDown:h=>{h.key==="Enter"&&T(),h.key==="Escape"&&(w(!1),S(""))},placeholder:"Collection name",className:"flex-1 px-2 py-1.5 text-sm bg-surface-2 border border-brand-500/30 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none"}),e.jsx("button",{onClick:T,disabled:!f.trim(),className:"p-1.5 rounded-lg text-emerald-500 hover:bg-emerald-500/25 transition-colors disabled:opacity-30",title:"Create",children:e.jsx(we,{size:14})}),e.jsx("button",{onClick:()=>{w(!1),S("")},className:"p-1.5 rounded-lg text-red-500 hover:bg-red-500/25 transition-colors",title:"Cancel",children:e.jsx(he,{size:14})})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-1",children:[t.length===0&&!l&&e.jsxs("div",{className:"px-3 py-6 text-center",children:[e.jsx("p",{className:"text-sm text-gray-600",children:"No collections yet"}),e.jsx("button",{onClick:()=>w(!0),className:"text-sm text-brand-400 hover:text-brand-300 mt-1",children:"Create one"})]}),t.map(h=>{const R=b.has(h.id),V=(a==null?void 0:a.id)===h.id;return e.jsxs("div",{children:[e.jsxs("div",{className:`flex items-center gap-1.5 px-3 py-1.5 cursor-pointer hover:bg-white/5 group ${V?"bg-brand-500/10":""}`,onClick:()=>C(h.id),children:[R?e.jsx(oe,{size:14,className:"text-gray-500 flex-shrink-0"}):e.jsx(xe,{size:14,className:"text-gray-500 flex-shrink-0"}),R?e.jsx(He,{size:13,className:"text-brand-400 flex-shrink-0"}):e.jsx(Ye,{size:13,className:"text-gray-400 flex-shrink-0"}),y===h.id?e.jsx("input",{autoFocus:!0,value:M,onChange:g=>K(g.target.value),onKeyDown:g=>{g.key==="Enter"&&_(h.id),g.key==="Escape"&&P(null)},onBlur:()=>_(h.id),onClick:g=>g.stopPropagation(),className:"flex-1 px-1.5 py-0 text-sm bg-surface-2 border border-brand-500/30 rounded text-gray-200 focus:outline-none min-w-0"}):e.jsx("span",{className:"text-sm text-gray-300 truncate flex-1",onDoubleClick:g=>{g.stopPropagation(),G(h.id,h.name)},children:h.name}),e.jsx("span",{className:"text-sm text-gray-600 flex-shrink-0",children:h.requestCount}),e.jsx("button",{onClick:g=>{g.stopPropagation(),G(h.id,h.name)},className:"p-0.5 text-gray-600 hover:text-brand-300 opacity-0 group-hover:opacity-100 transition-all flex-shrink-0",title:"Rename",children:e.jsx(Xe,{size:13})}),e.jsx("button",{onClick:g=>{g.stopPropagation(),ce("collection",h.name,()=>me.mutate(h.id))},className:"p-0.5 text-gray-600 hover:text-red-400 opacity-0 group-hover:opacity-100 transition-all flex-shrink-0",children:e.jsx(ie,{size:13})})]}),R&&V&&a&&e.jsxs("div",{className:"ml-3",children:[a.folders.map(g=>{const de=p.has(g.id);return e.jsxs("div",{children:[e.jsxs("div",{className:`flex items-center gap-1.5 px-3 py-1 cursor-pointer hover:bg-white/5 group transition-colors ${(B==null?void 0:B.type)==="folder"&&B.id===g.id?"bg-brand-500/15 border-l-2 border-l-brand-400":""}`,onClick:()=>N(g.id),onDragOver:E=>{E.preventDefault(),E.stopPropagation(),X({type:"folder",id:g.id})},onDragLeave:()=>X(null),onDrop:E=>{E.preventDefault(),E.stopPropagation(),o(g.id)},children:[de?e.jsx(oe,{size:13,className:"text-gray-600"}):e.jsx(xe,{size:13,className:"text-gray-600"}),e.jsx(Ye,{size:14,className:"text-amber-500/60"}),r===g.id?e.jsx("input",{autoFocus:!0,value:v,onChange:E=>L(E.target.value),onKeyDown:E=>{E.key==="Enter"&&Q(h.id,g.id),E.key==="Escape"&&k(null)},onBlur:()=>Q(h.id,g.id),onClick:E=>E.stopPropagation(),className:"flex-1 px-1.5 py-0 text-sm bg-surface-2 border border-brand-500/30 rounded text-gray-200 focus:outline-none min-w-0"}):e.jsx("span",{className:"text-sm text-gray-400 truncate flex-1",onDoubleClick:E=>{E.stopPropagation(),W(g.id,g.name)},children:g.name}),m&&e.jsx("button",{onClick:E=>{E.stopPropagation(),g.requests.length>0&&m(g)},disabled:g.requests.length===0,className:`p-0.5 opacity-0 group-hover:opacity-100 transition-all flex-shrink-0 ${g.requests.length>0?"text-gray-600 hover:text-emerald-400":"text-gray-700 cursor-not-allowed"}`,title:g.requests.length>0?"Run as chain":"Add requests to run as chain",children:e.jsx(Be,{size:13})}),e.jsx("button",{onClick:E=>{E.stopPropagation(),W(g.id,g.name)},className:"p-0.5 text-gray-600 hover:text-brand-300 opacity-0 group-hover:opacity-100 transition-all flex-shrink-0",title:"Rename",children:e.jsx(Xe,{size:13})}),e.jsx("button",{onClick:E=>{E.stopPropagation(),ce("folder",g.name,()=>be.mutate({collectionId:h.id,folderId:g.id}))},className:"p-0.5 text-gray-600 hover:text-red-400 opacity-0 group-hover:opacity-100 transition-all flex-shrink-0",children:e.jsx(ie,{size:13})})]}),de&&e.jsxs(e.Fragment,{children:[g.requests.map(E=>e.jsx(at,{request:E,selected:s===E.id,onSelect:()=>d(E,g.id),onDelete:()=>ce("request",E.name,()=>Z.mutate({collectionId:h.id,requestId:E.id})),onDuplicate:()=>ke(E,h.id,g.id),onDragStart:()=>{te.current=!1,ee({req:E,collectionId:h.id,folderId:g.id})},onDragEnd:()=>{te.current||(ee(null),X(null)),te.current=!1},onDragOverItem:()=>X({type:"between",id:g.id,beforeId:E.id}),isDropTarget:(B==null?void 0:B.type)==="between"&&B.id===g.id&&B.beforeId===E.id,onDropItem:()=>o(g.id,E.id),indent:2},E.id)),ne&&e.jsx("div",{className:`h-4 mx-2 ${(B==null?void 0:B.type)==="between"&&B.id===g.id&&B.beforeId==="__end__"?"border-t-2 border-brand-500":""}`,onDragOver:E=>{E.preventDefault(),X({type:"between",id:g.id,beforeId:"__end__"})},onDragLeave:()=>X(null),onDrop:E=>{E.preventDefault(),o(g.id,"__end__")}}),e.jsx("div",{style:{paddingLeft:"36px",paddingRight:"12px"},className:"py-0.5",children:e.jsx("button",{onClick:E=>{E.stopPropagation();const Ce={id:`req-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,name:"New Request",method:"GET",url:"",headers:[],queryParams:[],body:{type:"none"},auth:{type:"none"},validations:[],followRedirects:!0,sortOrder:g.requests.length};d(Ce,g.id)},className:"text-sm text-gray-600 hover:text-gray-400",children:"+ Request"})})]})]},g.id)}),ne&&ne.folderId&&e.jsx("div",{className:`mx-2 my-1 py-2 rounded-lg border-2 border-dashed text-center text-sm transition-colors ${(B==null?void 0:B.type)==="root"?"border-brand-500/50 bg-brand-500/10 text-brand-400":"border-white/10 text-gray-600"}`,onDragOver:g=>{g.preventDefault(),g.stopPropagation(),X({type:"root",id:"root"})},onDragLeave:()=>X(null),onDrop:g=>{g.preventDefault(),g.stopPropagation(),o(null)},children:"Drop here for root level"}),a.requests.map(g=>e.jsx(at,{request:g,selected:s===g.id,onSelect:()=>d(g),onDelete:()=>ce("request",g.name,()=>Z.mutate({collectionId:h.id,requestId:g.id})),onDuplicate:()=>ke(g,h.id),onDragStart:()=>{te.current=!1,ee({req:g,collectionId:h.id})},onDragEnd:()=>{te.current||(ee(null),X(null)),te.current=!1},onDragOverItem:()=>X({type:"between",id:"__root__",beforeId:g.id}),isDropTarget:(B==null?void 0:B.type)==="between"&&B.id==="__root__"&&B.beforeId===g.id,onDropItem:()=>o(null,g.id),indent:1},g.id)),z===h.id?e.jsx("div",{className:"px-5 py-1",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{autoFocus:!0,value:F,onChange:g=>q(g.target.value),onKeyDown:g=>{g.key==="Enter"&&I(h.id),g.key==="Escape"&&(H(null),q(""))},placeholder:"Folder name",className:"flex-1 px-2 py-1.5 text-sm bg-surface-2 border border-brand-500/30 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none"}),e.jsx("button",{onClick:()=>I(h.id),disabled:!F.trim(),className:"p-1.5 rounded-lg text-emerald-500 hover:bg-emerald-500/25 transition-colors disabled:opacity-30",title:"Create",children:e.jsx(we,{size:14})}),e.jsx("button",{onClick:()=>{H(null),q("")},className:"p-1.5 rounded-lg text-red-500 hover:bg-red-500/25 transition-colors",title:"Cancel",children:e.jsx(he,{size:14})})]})}):e.jsxs("div",{className:"flex gap-2 px-5 py-1",children:[e.jsx("button",{onClick:()=>H(h.id),className:"text-sm text-gray-600 hover:text-gray-400",children:"+ Folder"}),e.jsx("button",{onClick:()=>{const g={id:`req-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,name:"New Request",method:"GET",url:"",headers:[],queryParams:[],body:{type:"none"},auth:{type:"none"},validations:[],followRedirects:!0,sortOrder:0};d(g)},className:"text-sm text-gray-600 hover:text-gray-400",children:"+ Request"})]})]})]},h.id)})]}),A&&e.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>Y(null),children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-2xl shadow-xl w-full max-w-md p-6",onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-red-500/10 flex items-center justify-center flex-shrink-0",children:e.jsx(ie,{size:20,className:"text-red-400"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-base font-semibold text-gray-200",children:["Delete ",A.type==="collection"?"Collection":A.type==="folder"?"Folder":"Request"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-0.5",children:"This action cannot be undone"})]})]}),e.jsxs("p",{className:"text-sm text-gray-400 mb-2",children:["Are you sure you want to delete this ",A.type,"?"]}),e.jsx("div",{className:"flex items-center gap-2 px-3 py-2.5 rounded-lg bg-surface-2 border border-white/5 mb-2",children:e.jsx("span",{className:"text-sm font-medium text-gray-200 truncate",children:A.name})}),A.type==="collection"&&e.jsx("p",{className:"text-sm text-orange-400/80 mb-4",children:"All folders, requests, and environments in this collection will be permanently deleted."}),A.type==="folder"&&e.jsx("p",{className:"text-sm text-orange-400/80 mb-4",children:"All requests inside this folder will be permanently deleted."}),A.type==="request"&&e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"This request and its validations will be permanently deleted."}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>Y(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:fe,className:"px-4 py-2 rounded-lg text-sm font-medium text-white bg-red-600 hover:bg-red-500 transition-colors",children:"Delete"})]})]})})]})}function at({request:t,selected:a,onSelect:s,onDelete:n,onDuplicate:d,onDragStart:c,onDragEnd:m,onDragOverItem:b,onDropItem:i,isDropTarget:p,indent:u}){return e.jsxs("div",{children:[p&&e.jsx("div",{className:"h-0.5 bg-brand-500 mx-2 rounded-full",style:{marginLeft:`${u*12+12}px`}}),e.jsxs("div",{className:`flex items-center gap-1 py-1 cursor-pointer hover:bg-white/5 group ${a?"bg-brand-500/10":""}`,style:{paddingLeft:`${u*12+12}px`,paddingRight:"8px"},onClick:s,draggable:!0,onDragStart:l=>{l.dataTransfer.effectAllowed="move",l.dataTransfer.setData("text/plain",t.id),c()},onDragEnd:m,onDragOver:l=>{l.preventDefault(),b()},onDrop:l=>{l.preventDefault(),l.stopPropagation(),i()},children:[e.jsx(Mt,{size:12,className:"text-gray-700 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0 cursor-grab"}),e.jsx("span",{className:`text-sm font-bold w-8 flex-shrink-0 ${ps[t.method]}`,children:t.method.slice(0,3)}),e.jsx("span",{className:"text-sm text-gray-400 truncate flex-1",children:t.name||t.url||"Untitled"}),e.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all flex-shrink-0",children:[e.jsx("button",{onClick:l=>{l.stopPropagation(),d()},className:"p-0.5 text-gray-600 hover:text-cyan-400 transition-colors",title:"Duplicate request",children:e.jsx(Ee,{size:12})}),e.jsx("button",{onClick:l=>{l.stopPropagation(),n()},className:"p-0.5 text-gray-600 hover:text-red-400 transition-colors",title:"Delete request",children:e.jsx(ie,{size:13})})]})]})]})}function rt({pairs:t,onChange:a,keyPlaceholder:s="Key",valuePlaceholder:n="Value",showDescription:d=!1}){const c=(i,p,u)=>{const l=[...t];l[i]={...l[i],[p]:u},a(l)},m=()=>{a([...t,{key:"",value:"",enabled:!0}])},b=i=>{a(t.filter((p,u)=>u!==i))};return e.jsxs("div",{className:"space-y-1",children:[t.map((i,p)=>e.jsxs("div",{className:"flex items-center gap-1.5 group",children:[e.jsx("input",{type:"checkbox",checked:i.enabled,onChange:u=>c(p,"enabled",u.target.checked),className:"w-3.5 h-3.5 rounded border-gray-600 bg-surface-2 accent-brand-500 flex-shrink-0"}),e.jsx("input",{type:"text",value:i.key,onChange:u=>c(p,"key",u.target.value),placeholder:s,className:"flex-1 min-w-0 px-2 py-1 text-sm bg-surface-2 border border-white/5 rounded text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"}),e.jsx("input",{type:"text",value:i.value,onChange:u=>c(p,"value",u.target.value),placeholder:n,className:"flex-1 min-w-0 px-2 py-1 text-sm bg-surface-2 border border-white/5 rounded text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"}),d&&e.jsx("input",{type:"text",value:i.description||"",onChange:u=>c(p,"description",u.target.value),placeholder:"Description",className:"w-32 px-2 py-1 text-sm bg-surface-2 border border-white/5 rounded text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"}),e.jsx("button",{onClick:()=>b(p),className:"p-1 text-gray-600 hover:text-red-400 opacity-0 group-hover:opacity-100 transition-all flex-shrink-0",children:e.jsx(ie,{size:14})})]},p)),e.jsxs("button",{onClick:m,className:"flex items-center gap-1 text-sm text-gray-500 hover:text-gray-300 transition-colors pt-1",children:[e.jsx(pe,{size:13})," Add"]})]})}const gs=[{value:"none",label:"None"},{value:"json",label:"JSON"},{value:"text",label:"Text"},{value:"form-data",label:"Form Data"},{value:"graphql",label:"GraphQL"}];function bs({body:t,onChange:a}){const{monacoTheme:s}=Ge();return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex gap-1",children:gs.map(n=>e.jsx("button",{onClick:()=>a({...t,type:n.value}),className:`px-2.5 py-1 text-sm rounded transition-colors ${t.type===n.value?"bg-brand-500/20 text-brand-300":"text-gray-500 hover:text-gray-300 hover:bg-white/5"}`,children:n.label},n.value))}),t.type==="none"&&e.jsx("p",{className:"text-sm text-gray-600 italic",children:"No body content"}),t.type==="json"&&e.jsx("div",{className:"border border-white/5 rounded-lg overflow-hidden",style:{height:"240px"},children:e.jsx(Qe,{value:t.raw||"",onChange:n=>a({...t,raw:n||""}),language:"json",theme:s,options:{minimap:{enabled:!1},fontSize:14,lineHeight:22,scrollBeyondLastLine:!1,wordWrap:"on",padding:{top:8,bottom:8},scrollbar:{verticalScrollbarSize:8,horizontalScrollbarSize:8},lineNumbers:"on",folding:!0,bracketPairColorization:{enabled:!0},tabSize:2,renderLineHighlight:"line",automaticLayout:!0}})}),t.type==="text"&&e.jsx("textarea",{value:t.raw||"",onChange:n=>a({...t,raw:n.target.value}),placeholder:"Plain text body...",className:"w-full h-48 px-3 py-2 text-sm font-mono bg-surface-2 border border-white/5 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50 resize-y",spellCheck:!1}),t.type==="form-data"&&e.jsx(fs,{pairs:t.formData||[],onChange:n=>a({...t,formData:n})}),t.type==="graphql"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Query"}),e.jsx("textarea",{value:t.raw||"",onChange:n=>a({...t,raw:n.target.value}),placeholder:`query {
2
+ users {
3
+ id
4
+ name
5
+ }
6
+ }`,className:"w-full h-36 px-3 py-2 text-sm font-mono bg-surface-2 border border-white/5 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50 resize-y",spellCheck:!1})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Variables"}),e.jsx("textarea",{value:t.graphqlVariables||"",onChange:n=>a({...t,graphqlVariables:n.target.value}),placeholder:`{
7
+ "id": 1
8
+ }`,className:"w-full h-20 px-3 py-2 text-sm font-mono bg-surface-2 border border-white/5 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50 resize-y",spellCheck:!1})]})]})]})}function fs({pairs:t,onChange:a}){const s=x.useRef({}),n=(p,u)=>{const l=[...t];l[p]={...l[p],...u},a(l)},d=p=>{a(t.filter((u,l)=>l!==p))},c=()=>{a([...t,{key:"",value:"",enabled:!0,fieldType:"text"}])},m=()=>{a([...t,{key:"",value:"",enabled:!0,fieldType:"file"}])},b=(p,u)=>{const l=new FileReader;l.onload=()=>{const w=l.result.split(",")[1]||"";n(p,{value:w,fileName:u.name,fileSize:u.size})},l.readAsDataURL(u)},i=p=>p<1024?`${p} B`:p<1024*1024?`${(p/1024).toFixed(1)} KB`:`${(p/(1024*1024)).toFixed(1)} MB`;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500 px-1 mb-1",children:[e.jsx("span",{className:"w-6"}),e.jsx("span",{className:"w-14 text-center",children:"Type"}),e.jsx("span",{className:"flex-1",children:"Key"}),e.jsx("span",{className:"flex-1",children:"Value"}),e.jsx("span",{className:"w-8"})]}),t.map((p,u)=>e.jsxs("div",{className:"flex items-center gap-2 group",children:[e.jsx("input",{type:"checkbox",checked:p.enabled,onChange:l=>n(u,{enabled:l.target.checked}),className:"w-4 h-4 accent-brand-500 flex-shrink-0"}),e.jsxs("button",{onClick:()=>n(u,{fieldType:p.fieldType==="file"?"text":"file",value:"",fileName:void 0,fileSize:void 0}),className:`w-14 flex items-center justify-center gap-1 px-1.5 py-1.5 rounded-lg text-sm font-medium transition-colors flex-shrink-0 ${p.fieldType==="file"?"bg-purple-500/15 text-purple-400":"bg-surface-2 text-gray-500 hover:text-gray-300"}`,title:p.fieldType==="file"?"Switch to text":"Switch to file",children:[p.fieldType==="file"?e.jsx(Ze,{size:12}):e.jsx(et,{size:12}),p.fieldType==="file"?"File":"Text"]}),e.jsx("input",{value:p.key,onChange:l=>n(u,{key:l.target.value}),placeholder:"Field name",className:"flex-1 px-3 py-2 text-sm font-mono bg-surface-2 border border-white/10 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"}),p.fieldType==="file"?e.jsxs("div",{className:"flex-1 flex items-center gap-1.5",children:[e.jsx("input",{ref:l=>{s.current[u]=l},type:"file",className:"hidden",onChange:l=>{var f;const w=(f=l.target.files)==null?void 0:f[0];w&&b(u,w),l.target.value=""}}),p.fileName?e.jsxs("div",{className:"flex-1 flex items-center gap-2 px-3 py-2 bg-purple-500/10 border border-purple-500/20 rounded-lg",children:[e.jsx(Ze,{size:13,className:"text-purple-400 flex-shrink-0"}),e.jsx("span",{className:"text-sm text-gray-200 truncate",children:p.fileName}),e.jsx("span",{className:"text-sm text-gray-500",children:p.fileSize?i(p.fileSize):""}),e.jsx("button",{onClick:()=>n(u,{value:"",fileName:void 0,fileSize:void 0}),className:"p-0.5 text-gray-500 hover:text-red-400 transition-colors ml-auto flex-shrink-0",children:e.jsx(he,{size:12})})]}):e.jsxs("button",{onClick:()=>{var l;return(l=s.current[u])==null?void 0:l.click()},className:"flex-1 flex items-center justify-center gap-2 px-3 py-2 bg-surface-2 border border-dashed border-white/10 rounded-lg text-sm text-gray-500 hover:text-purple-400 hover:border-purple-500/30 transition-colors",children:[e.jsx($e,{size:14})," Choose File"]})]}):e.jsx("input",{value:p.value,onChange:l=>n(u,{value:l.target.value}),placeholder:"Field value",className:"flex-1 px-3 py-2 text-sm font-mono bg-surface-2 border border-white/10 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"}),e.jsx("button",{onClick:()=>d(u),className:"p-1.5 text-gray-600 hover:text-red-400 opacity-0 group-hover:opacity-100 transition-all flex-shrink-0",children:e.jsx(ie,{size:14})})]},u)),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsxs("button",{onClick:c,className:"flex items-center gap-1.5 text-sm text-gray-500 hover:text-gray-300 transition-colors",children:[e.jsx(pe,{size:13})," ",e.jsx(et,{size:12})," Text Field"]}),e.jsx("span",{className:"text-gray-700",children:"|"}),e.jsxs("button",{onClick:m,className:"flex items-center gap-1.5 text-sm text-purple-400 hover:text-purple-300 transition-colors",children:[e.jsx(pe,{size:13})," ",e.jsx($e,{size:12})," File Field"]})]})]})}const ys=[{value:"none",label:"None"},{value:"bearer",label:"Bearer Token"},{value:"basic",label:"Basic Auth"},{value:"api-key",label:"API Key"},{value:"oauth2-client-credentials",label:"OAuth2 (client credentials)"}],Pe="w-full px-2.5 py-1.5 text-sm bg-surface-2 border border-white/5 rounded text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50";function js({auth:t,onChange:a}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex gap-1",children:ys.map(s=>e.jsx("button",{onClick:()=>a({...t,type:s.value}),className:`px-2.5 py-1 text-sm rounded transition-colors ${t.type===s.value?"bg-brand-500/20 text-brand-300":"text-gray-500 hover:text-gray-300 hover:bg-white/5"}`,children:s.label},s.value))}),t.type==="none"&&e.jsx("p",{className:"text-sm text-gray-600 italic",children:"No authentication"}),t.type==="bearer"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Token"}),e.jsx("input",{type:"text",value:t.bearerToken||"",onChange:s=>a({...t,bearerToken:s.target.value}),placeholder:"Enter bearer token or {{variable}}",className:"w-full px-2.5 py-1.5 text-sm font-mono bg-surface-2 border border-white/5 rounded text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"})]}),t.type==="basic"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Username"}),e.jsx("input",{type:"text",value:t.basicUsername||"",onChange:s=>a({...t,basicUsername:s.target.value}),placeholder:"Username",className:"w-full px-2.5 py-1.5 text-sm bg-surface-2 border border-white/5 rounded text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Password"}),e.jsx(We,{value:t.basicPassword||"",onChange:s=>a({...t,basicPassword:s.target.value}),placeholder:"Password",className:"w-full px-2.5 py-1.5 text-sm bg-surface-2 border border-white/5 rounded text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"})]})]}),t.type==="api-key"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Key Name"}),e.jsx("input",{type:"text",value:t.apiKeyName||"",onChange:s=>a({...t,apiKeyName:s.target.value}),placeholder:"e.g. X-API-Key",className:"w-full px-2.5 py-1.5 text-sm bg-surface-2 border border-white/5 rounded text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Key Value"}),e.jsx("input",{type:"text",value:t.apiKeyValue||"",onChange:s=>a({...t,apiKeyValue:s.target.value}),placeholder:"API key value or {{variable}}",className:"w-full px-2.5 py-1.5 text-sm font-mono bg-surface-2 border border-white/5 rounded text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Add to"}),e.jsx("div",{className:"flex gap-2",children:["header","query"].map(s=>e.jsx("button",{onClick:()=>a({...t,apiKeyIn:s}),className:`px-2.5 py-1 text-sm rounded transition-colors ${(t.apiKeyIn||"header")===s?"bg-brand-500/20 text-brand-300":"text-gray-500 hover:text-gray-300 hover:bg-white/5"}`,children:s==="header"?"Header":"Query Param"},s))})]})]}),t.type==="oauth2-client-credentials"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-xs text-gray-500",children:["Service-to-service auth: the token is requested from the token URL, cached until it expires, and sent as a Bearer token. Use ",e.jsx("code",{children:"{{variables}}"})," for the secret so it lives in an environment."]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Token URL"}),e.jsx("input",{type:"text",value:t.oauth2TokenUrl||"",onChange:s=>a({...t,oauth2TokenUrl:s.target.value}),placeholder:"https://auth.example.com/oauth/token",className:`${Pe} font-mono`})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Client ID"}),e.jsx("input",{type:"text",value:t.oauth2ClientId||"",onChange:s=>a({...t,oauth2ClientId:s.target.value}),placeholder:"orders-service or {{clientId}}",className:Pe})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Client Secret"}),e.jsx(We,{value:t.oauth2ClientSecret||"",onChange:s=>a({...t,oauth2ClientSecret:s.target.value}),placeholder:"{{clientSecret}}",className:Pe})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Scope"}),e.jsx("input",{type:"text",value:t.oauth2Scope||"",onChange:s=>a({...t,oauth2Scope:s.target.value}),placeholder:"optional",className:Pe})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Audience"}),e.jsx("input",{type:"text",value:t.oauth2Audience||"",onChange:s=>a({...t,oauth2Audience:s.target.value}),placeholder:"optional",className:Pe})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm uppercase text-gray-500 font-medium mb-1 block",children:"Send credentials"}),e.jsx("div",{className:"flex gap-2",children:["body","basic"].map(s=>e.jsx("button",{onClick:()=>a({...t,oauth2ClientAuth:s}),className:`px-2.5 py-1 text-sm rounded transition-colors ${(t.oauth2ClientAuth||"body")===s?"bg-brand-500/20 text-brand-300":"text-gray-500 hover:text-gray-300 hover:bg-white/5"}`,children:s==="body"?"In the request body":"As Basic auth header"},s))})]})]})]})}const vs=[{value:"status",label:"Status Code"},{value:"header",label:"Header"},{value:"body-contains",label:"Body Contains"},{value:"body-json-path",label:"JSON Path"},{value:"response-time",label:"Response Time"},{value:"schema",label:"JSON Schema"}],Ns=[{value:"equals",label:"="},{value:"not-equals",label:"!="},{value:"contains",label:"contains"},{value:"not-contains",label:"!contains"},{value:"greater-than",label:">"},{value:"less-than",label:"<"},{value:"exists",label:"exists"},{value:"matches-regex",label:"regex"}];function ws({rules:t,onChange:a,results:s,onQuickAdd:n}){const d=()=>{a([...t,{id:`vr-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"status",operator:"equals",expected:"200",enabled:!0}])},c=(i,p)=>{const u=[...t];u[i]={...u[i],...p},a(u)},m=i=>{a(t.filter((p,u)=>u!==i))},b=i=>s==null?void 0:s.find(p=>p.ruleId===i);return e.jsxs("div",{className:"space-y-2",children:[t.length===0&&e.jsx("p",{className:"text-sm text-gray-600 italic",children:"No validations configured"}),t.map((i,p)=>{const u=b(i.id);return e.jsxs("div",{className:"flex items-center gap-1.5 group",children:[e.jsx("input",{type:"checkbox",checked:i.enabled,onChange:l=>c(p,{enabled:l.target.checked}),className:"w-3.5 h-3.5 rounded border-gray-600 bg-surface-2 accent-brand-500 flex-shrink-0"}),e.jsx("select",{value:i.type,onChange:l=>c(p,{type:l.target.value}),className:"px-1.5 py-1 text-sm bg-surface-2 border border-white/5 rounded text-gray-300 focus:outline-none focus:border-brand-500/50",children:vs.map(l=>e.jsx("option",{value:l.value,children:l.label},l.value))}),(i.type==="header"||i.type==="body-json-path")&&e.jsx("input",{type:"text",value:i.target||"",onChange:l=>c(p,{target:l.target.value}),placeholder:i.type==="header"?"Header name":"$.path",className:"w-24 px-1.5 py-1 text-sm font-mono bg-surface-2 border border-white/5 rounded text-gray-300 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"}),i.type!=="schema"&&e.jsx("select",{value:i.operator,onChange:l=>c(p,{operator:l.target.value}),className:"px-1.5 py-1 text-sm bg-surface-2 border border-white/5 rounded text-gray-300 focus:outline-none focus:border-brand-500/50",children:Ns.map(l=>e.jsx("option",{value:l.value,children:l.label},l.value))}),i.type==="schema"?e.jsx("textarea",{value:i.expected,onChange:l=>c(p,{expected:l.target.value}),placeholder:'{"type":"object","properties":{...}}',rows:3,className:"flex-1 min-w-0 px-1.5 py-1 text-sm font-mono bg-surface-2 border border-white/5 rounded text-gray-300 placeholder-gray-600 focus:outline-none focus:border-brand-500/50 resize-y"}):e.jsx("input",{type:"text",value:i.expected,onChange:l=>c(p,{expected:l.target.value}),placeholder:"Expected",className:"flex-1 min-w-0 px-1.5 py-1 text-sm font-mono bg-surface-2 border border-white/5 rounded text-gray-300 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"}),u&&(u.passed?e.jsx(je,{size:14,className:"text-emerald-400 flex-shrink-0"}):e.jsx("span",{title:u.message,className:"flex-shrink-0",children:e.jsx(ve,{size:14,className:"text-red-400"})})),e.jsx("button",{onClick:()=>m(p),className:"p-1 text-gray-600 hover:text-red-400 opacity-0 group-hover:opacity-100 transition-all flex-shrink-0",children:e.jsx(ie,{size:14})})]},i.id)}),e.jsxs("div",{className:"flex items-center gap-3 pt-1",children:[e.jsxs("button",{onClick:d,className:"flex items-center gap-1 text-sm text-gray-500 hover:text-gray-300 transition-colors",children:[e.jsx(pe,{size:13})," Add Validation"]}),n&&e.jsxs("button",{onClick:n,className:"flex items-center gap-1 text-sm text-brand-400 hover:text-brand-300 transition-colors",children:[e.jsx(pe,{size:13})," Quick Add from Response"]})]})]})}function ks({preRequestScript:t="",postResponseScript:a="",onChangePreRequest:s,onChangePostResponse:n}){const[d,c]=x.useState(!!t),[m,b]=x.useState(!!a),[i,p]=x.useState(!1),[u,l]=x.useState(""),[w,f]=x.useState(""),S=()=>{if(!u.trim()||!w.trim())return;const z=`set("${u.trim()}", jsonpath(response.body, "${w.trim()}"))`,H=a?`${a}
9
+ ${z}`:z;n(H),l(""),f(""),b(!0)};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"p-3 bg-surface-2 rounded-lg border border-white/5",children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsx("span",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wider",children:"Quick Extract Variable"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{value:u,onChange:z=>l(z.target.value),placeholder:"Variable name",className:"w-28 px-2 py-1 text-sm bg-surface-1 border border-white/5 rounded text-gray-300 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"}),e.jsx("span",{className:"text-sm text-gray-600",children:"="}),e.jsx("input",{value:w,onChange:z=>f(z.target.value),onKeyDown:z=>{z.key==="Enter"&&S()},placeholder:"$.data.token",className:"flex-1 px-2 py-1 text-sm font-mono bg-surface-1 border border-white/5 rounded text-gray-300 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"}),e.jsxs("button",{onClick:S,disabled:!u.trim()||!w.trim(),className:"flex items-center gap-1 px-2.5 py-1 rounded bg-brand-500 text-white text-sm font-medium hover:bg-brand-600 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:[e.jsx(pe,{size:13})," Add"]})]}),e.jsx("p",{className:"text-sm text-gray-600 mt-1.5",children:"Tip: Use the Extract Variable feature in the Response panel to auto-fill the JSONPath"})]}),e.jsxs("div",{className:"rounded-lg border border-white/5 overflow-hidden",children:[e.jsxs("button",{onClick:()=>c(!d),className:"w-full flex items-center gap-2 px-3 py-2 bg-surface-2 hover:bg-surface-3 transition-colors text-left",children:[d?e.jsx(oe,{size:14,className:"text-gray-500"}):e.jsx(xe,{size:14,className:"text-gray-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-300",children:"Pre-Request Script"}),t&&e.jsx("span",{className:"text-sm px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-300 ml-auto",children:"active"})]}),d&&e.jsx("textarea",{value:t,onChange:z=>s(z.target.value),placeholder:`// Runs before the request is sent
10
+ // Example: setHeader('Authorization', 'Bearer ' + get('token'))`,className:"w-full h-32 px-3 py-2 text-sm font-mono bg-surface-1 text-gray-300 placeholder-gray-600 border-t border-white/5 resize-y focus:outline-none"})]}),e.jsxs("div",{className:"rounded-lg border border-white/5 overflow-hidden",children:[e.jsxs("button",{onClick:()=>b(!m),className:"w-full flex items-center gap-2 px-3 py-2 bg-surface-2 hover:bg-surface-3 transition-colors text-left",children:[m?e.jsx(oe,{size:14,className:"text-gray-500"}):e.jsx(xe,{size:14,className:"text-gray-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-300",children:"Post-Response Script"}),a&&e.jsx("span",{className:"text-sm px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-300 ml-auto",children:"active"})]}),m&&e.jsx("textarea",{value:a,onChange:z=>n(z.target.value),placeholder:`// Runs after the response is received
11
+ // Example: set('userId', jsonpath(response.body, '$.data.id'))`,className:"w-full h-32 px-3 py-2 text-sm font-mono bg-surface-1 text-gray-300 placeholder-gray-600 border-t border-white/5 resize-y focus:outline-none"})]}),e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>p(!i),className:"flex items-center gap-1.5 text-sm text-gray-500 hover:text-gray-300 transition-colors",children:[e.jsx(Kt,{size:13})," Script DSL Reference"]}),i&&e.jsxs("div",{className:"mt-2 p-3 bg-surface-2 rounded-lg border border-white/5 space-y-2",children:[e.jsxs("div",{children:[e.jsx("code",{className:"text-sm text-brand-300",children:"get(key)"}),e.jsx("span",{className:"text-sm text-gray-500 ml-2",children:"Read a chain variable"})]}),e.jsxs("div",{children:[e.jsx("code",{className:"text-sm text-brand-300",children:"set(key, value)"}),e.jsx("span",{className:"text-sm text-gray-500 ml-2",children:"Store a chain variable for subsequent requests"})]}),e.jsxs("div",{children:[e.jsx("code",{className:"text-sm text-brand-300",children:"jsonpath(body, path)"}),e.jsx("span",{className:"text-sm text-gray-500 ml-2",children:"Extract value from JSON body using path like $.data.id"})]}),e.jsxs("div",{children:[e.jsx("code",{className:"text-sm text-brand-300",children:"setHeader(name, value)"}),e.jsx("span",{className:"text-sm text-gray-500 ml-2",children:"Set/override a header for the current request (pre-request only)"})]}),e.jsx("hr",{className:"border-white/5"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Example: Extract a token from login response and use it in the next request:"}),e.jsx("code",{className:"block text-sm text-gray-400 font-mono bg-surface-1 p-2 rounded",children:`// Post-Response Script (on login request):
12
+ set("token", jsonpath(response.body, "$.access_token"))
13
+
14
+ // Pre-Request Script (on next request):
15
+ setHeader("Authorization", "Bearer " + get("token"))`})]})]})]})}function Cs(t,a){if(!t||!t.includes("{{"))return null;const s=t.replace(/\{\{(\w+)\}\}/g,(n,d)=>a[d]??`{{${d}}}`);return s!==t?s:null}const Ss=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"],zs={GET:"text-emerald-400",POST:"text-blue-400",PUT:"text-amber-400",PATCH:"text-brand-400",DELETE:"text-red-400",HEAD:"text-purple-400",OPTIONS:"text-gray-400"};function $s({request:t,onChange:a,onSend:s,onSave:n,onQuickValidate:d,sending:c,validationResults:m,variables:b}){const[i,p]=ut("reqtab",["params","headers","body","auth","validations","scripts"],"params"),u=x.useMemo(()=>!b||Object.keys(b).length===0?null:Cs(t.url,b),[t.url,b]),l=(f,S)=>{a({...t,[f]:S})},w=[{id:"params",label:"Params",count:t.queryParams.filter(f=>f.enabled&&f.key).length},{id:"headers",label:"Headers",count:t.headers.filter(f=>f.enabled&&f.key).length},{id:"body",label:"Body"},{id:"auth",label:"Auth"},{id:"validations",label:"Validations",count:t.validations.length},{id:"scripts",label:"Scripts",count:t.preRequestScript||t.postResponseScript?1:0}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"px-3 pt-2 pb-1 border-b border-white/5 flex-shrink-0",children:e.jsx("input",{type:"text",value:t.name,onChange:f=>l("name",f.target.value),onBlur:()=>n==null?void 0:n(),placeholder:"Request name",className:"w-full px-1 py-0.5 text-sm font-medium bg-transparent border-none text-gray-200 placeholder-gray-600 focus:outline-none hover:bg-surface-2 focus:bg-surface-2 rounded transition-colors"})}),e.jsxs("div",{className:"flex gap-1.5 px-3 py-2 border-b border-white/5 flex-shrink-0",children:[e.jsx("select",{value:t.method,onChange:f=>l("method",f.target.value),className:`px-2 py-1.5 text-sm font-bold bg-surface-2 border border-white/5 rounded-lg focus:outline-none focus:border-brand-500/50 ${zs[t.method]}`,children:Ss.map(f=>e.jsx("option",{value:f,children:f},f))}),e.jsx("input",{type:"text",value:t.url,onChange:f=>l("url",f.target.value),onKeyDown:f=>{f.key==="Enter"&&!c&&s()},placeholder:"https://api.example.com/endpoint or {{baseUrl}}/path",className:"flex-1 px-3 py-1.5 text-sm font-mono bg-surface-2 border border-white/5 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"}),e.jsxs("button",{onClick:s,disabled:c||!t.url,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-lg bg-brand-500 text-white text-sm font-medium hover:bg-brand-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[c?e.jsx(Te,{size:13,className:"animate-spin"}):e.jsx(dt,{size:13}),"Send"]})]}),u&&e.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-1 border-b border-white/5 bg-surface-1/50 flex-shrink-0",children:[e.jsx(xt,{size:13,className:"text-emerald-500/60 flex-shrink-0"}),e.jsx("span",{className:"text-sm font-mono text-gray-500 truncate",title:u,children:u})]}),e.jsx("div",{className:"flex gap-0.5 px-3 py-1 border-b border-white/5 flex-shrink-0",children:w.map(f=>e.jsxs("button",{onClick:()=>p(f.id),className:`px-2.5 py-1 text-sm rounded transition-colors ${i===f.id?"bg-brand-500/15 text-brand-300":"text-gray-500 hover:text-gray-300"}`,children:[f.label,f.count!==void 0&&f.count>0&&e.jsx("span",{className:"ml-1 text-sm px-1 py-0.5 rounded-full bg-surface-2 text-gray-400",children:f.count})]},f.id))}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3",children:[i==="params"&&e.jsx(rt,{pairs:t.queryParams,onChange:f=>l("queryParams",f),keyPlaceholder:"Parameter",valuePlaceholder:"Value"}),i==="headers"&&e.jsx(rt,{pairs:t.headers,onChange:f=>l("headers",f),keyPlaceholder:"Header name",valuePlaceholder:"Header value"}),i==="body"&&e.jsx(bs,{body:t.body,onChange:f=>l("body",f)}),i==="auth"&&e.jsx(js,{auth:t.auth,onChange:f=>l("auth",f)}),i==="validations"&&e.jsx(ws,{rules:t.validations,onChange:f=>l("validations",f),results:m,onQuickAdd:d}),i==="scripts"&&e.jsx(ks,{preRequestScript:t.preRequestScript||"",postResponseScript:t.postResponseScript||"",onChangePreRequest:f=>l("preRequestScript",f),onChangePostResponse:f=>l("postResponseScript",f)})]})]})}function Es(t,a){return typeof a=="number"?`${t}[${a}]`:/[.\s\-\[\]]/.test(a)?`${t}["${a}"]`:t?`${t}.${a}`:`$.${a}`}function ht(t){return t===null?{text:"null",color:"text-gray-500"}:t===void 0?{text:"undefined",color:"text-gray-500"}:typeof t=="boolean"?{text:String(t),color:"text-blue-400"}:typeof t=="number"?{text:String(t),color:"text-amber-400"}:typeof t=="string"?{text:t.length>60?`"${t.slice(0,57)}..."`:`"${t}"`,color:"text-emerald-400"}:Array.isArray(t)?{text:`Array(${t.length})`,color:"text-purple-400"}:typeof t=="object"?{text:`Object{${Object.keys(t).length}}`,color:"text-purple-400"}:{text:String(t),color:"text-gray-400"}}function Ps(t){return t==null||typeof t!="object"}function gt(t){return t==null?"exists":typeof t=="boolean"||typeof t=="number"?"equals":typeof t=="string"?t.length>50?"contains":"equals":"exists"}const nt=50;function _e({data:t,onSelectPath:a,rootPath:s="$"}){let n=t;if(typeof t=="string")try{n=JSON.parse(t)}catch{}if(n==null||typeof n!="object"){const d=ht(n);return e.jsx("button",{onClick:()=>a(s,n),className:`text-sm font-mono ${d.color} hover:bg-white/10 px-1 rounded cursor-pointer transition-colors`,children:d.text})}return e.jsx("div",{className:"text-sm font-mono",children:e.jsx(bt,{value:n,path:s,onSelectPath:a,depth:0,isRoot:!0})})}function bt({value:t,path:a,onSelectPath:s,depth:n,isRoot:d,keyName:c}){const[m,b]=x.useState(n===0),[i,p]=x.useState(nt);if(Ps(t)){const F=ht(t);return e.jsxs("div",{className:"flex items-center gap-1 py-0.5 group",style:{paddingLeft:n*16},children:[c!==void 0&&e.jsx("span",{className:"text-gray-400",children:typeof c=="number"?`${c}:`:`"${c}":`}),e.jsx("button",{onClick:()=>s(a,t),className:`${F.color} hover:bg-brand-500/20 px-1 rounded cursor-pointer transition-colors border border-transparent hover:border-brand-500/30`,title:`Click to select: ${a}`,children:F.text}),e.jsx("span",{className:"text-gray-700 opacity-0 group-hover:opacity-100 text-sm transition-opacity ml-1",children:a})]})}const u=Array.isArray(t),l=u?t.map((F,q)=>[q,F]):Object.entries(t),w=l.length,f=l.slice(0,i),S=w>i,z=u?"[":"{",H=u?"]":"}";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1 py-0.5 cursor-pointer hover:bg-white/5 rounded",style:{paddingLeft:n*16},onClick:()=>b(!m),children:[m?e.jsx(oe,{size:13,className:"text-gray-600 flex-shrink-0"}):e.jsx(xe,{size:13,className:"text-gray-600 flex-shrink-0"}),c!==void 0&&e.jsx("span",{className:"text-gray-400",children:typeof c=="number"?`${c}:`:`"${c}":`}),e.jsxs("span",{className:"text-gray-500",children:[z,!m&&e.jsxs("span",{className:"text-gray-600",children:[" ",w," ",u?"items":"keys"," ",H]})]})]}),m&&e.jsxs(e.Fragment,{children:[f.map(([F,q])=>{const y=Es(a,F);return e.jsx(bt,{value:q,path:y,onSelectPath:s,depth:n+1,keyName:F},String(F))}),S&&e.jsx("div",{style:{paddingLeft:(n+1)*16},className:"py-1",children:e.jsxs("button",{onClick:F=>{F.stopPropagation(),p(q=>q+nt)},className:"text-sm text-brand-400 hover:text-brand-300 hover:bg-brand-500/10 px-2 py-0.5 rounded transition-colors",children:["Show more (",w-i," remaining)"]})}),e.jsx("div",{style:{paddingLeft:n*16},className:"text-gray-500 py-0.5",children:H})]})]})}function Rs(t){return t>=200&&t<300?"bg-emerald-500/15 text-emerald-400":t>=300&&t<400?"bg-blue-500/15 text-blue-400":t>=400&&t<500?"bg-amber-500/15 text-amber-400":t>=500?"bg-red-500/15 text-red-400":"bg-gray-500/15 text-gray-400"}function lt(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Ds(t){try{const a=JSON.parse(t);return{formatted:JSON.stringify(a,null,2),language:"json"}}catch{return t.trim().startsWith("<")?{formatted:t,language:"html"}:{formatted:t,language:"text"}}}function As({response:t,loading:a,onAddValidation:s,onExtractVariable:n,variables:d={},request:c,extractedVars:m={}}){const[b,i]=ut("restab",["body","headers","validations","variables","timing"],"body"),[p,u]=x.useState("none"),[l,w]=x.useState(""),[f,S]=x.useState(""),{monacoTheme:z}=Ge();if(a)return e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),e.jsx("span",{className:"text-sm text-gray-500",children:"Sending request..."})]})});if(!t)return e.jsx("div",{className:"flex items-center justify-center h-full text-gray-600 text-sm",children:"Send a request to see the response"});const{formatted:H,language:F}=Ds(t.body),q=F==="json",y=t.validationResults||[],P=y.filter(r=>r.passed).length,M=Object.keys(d).length,K=[{id:"body",label:"Body"},{id:"headers",label:`Headers (${Object.keys(t.headers).length})`},{id:"validations",label:"Validations",badge:y.length>0?`${P}/${y.length}`:void 0},{id:"variables",label:"Variables",badge:M>0?String(M):void 0},{id:"timing",label:"Timing"}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 border-b border-white/5 flex-shrink-0",children:[e.jsxs("span",{className:`px-2 py-0.5 rounded text-sm font-bold ${Rs(t.status)}`,children:[t.status," ",t.statusText]}),e.jsxs("span",{className:"flex items-center gap-1 text-sm text-gray-500",children:[e.jsx(Le,{size:13})," ",t.duration,"ms"]}),e.jsxs("span",{className:"flex items-center gap-1 text-sm text-gray-500",children:[e.jsx(Jt,{size:13})," ",lt(t.size)]}),t.status>0&&e.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[n&&q&&e.jsxs("button",{onClick:()=>u(p==="extract"?"none":"extract"),className:`flex items-center gap-1 px-2 py-1 rounded-lg text-sm transition-colors ${p==="extract"?"bg-amber-500/20 text-amber-300":"bg-amber-500/10 text-amber-400 hover:bg-amber-500/20"}`,children:[e.jsx(Ie,{size:13})," Extract"]}),s&&q&&e.jsxs("button",{onClick:()=>u(p==="validate"?"none":"validate"),className:`flex items-center gap-1 px-2 py-1 rounded-lg text-sm transition-colors ${p==="validate"?"bg-brand-500/20 text-brand-300":"bg-brand-500/10 text-brand-400 hover:bg-brand-500/20"}`,children:[e.jsx(mt,{size:13})," Validate"]})]})]}),e.jsx("div",{className:"flex gap-0.5 px-3 py-1 border-b border-white/5 flex-shrink-0",children:K.map(r=>e.jsxs("button",{onClick:()=>i(r.id),className:`px-2.5 py-1 text-sm rounded transition-colors ${b===r.id?"bg-brand-500/15 text-brand-300":"text-gray-500 hover:text-gray-300"}`,children:[r.label,r.badge&&e.jsxs("span",{className:"ml-1 text-sm opacity-70",children:["(",r.badge,")"]})]},r.id))}),e.jsxs("div",{className:`flex-1 overflow-auto p-3 ${b==="body"?"flex flex-col":""}`,children:[b==="body"&&e.jsx(e.Fragment,{children:p==="validate"&&q&&s?e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 px-2 py-1.5 bg-brand-500/10 border border-brand-500/20 rounded-lg",children:e.jsx("p",{className:"text-sm text-brand-300",children:"Click any value below to create a validation rule for it"})}),e.jsx(_e,{data:t.body,onSelectPath:(r,k)=>{const v=gt(k);s({id:`vr-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"body-json-path",target:r,operator:v,expected:k!=null&&typeof k!="object"?String(k):"",enabled:!0})}})]}):p==="extract"&&q&&n?e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 px-2 py-1.5 bg-amber-500/10 border border-amber-500/20 rounded-lg",children:e.jsx("p",{className:"text-sm text-amber-300",children:"Click any value below to extract it as a variable"})}),e.jsx(_e,{data:t.body,onSelectPath:(r,k)=>{S(r);const L=r.replace(/\$/g,"").replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean).slice(-2).join("_").replace(/[^a-zA-Z0-9_]/g,"");w(L||"myVar")}}),f&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 p-2 bg-surface-2 rounded-lg border border-white/5",children:[e.jsx("span",{className:"text-sm text-gray-500",children:"Save as:"}),e.jsx("input",{value:l,onChange:r=>w(r.target.value),className:"w-28 px-2 py-1 text-sm font-mono bg-surface-1 border border-white/5 rounded text-gray-300 focus:outline-none",placeholder:"Variable name"}),e.jsx("span",{className:"text-sm text-gray-600",children:"="}),e.jsx("code",{className:"text-sm text-brand-300 font-mono flex-1 truncate",children:f}),e.jsx("button",{onClick:()=>{l.trim()&&f&&(n(l.trim(),f),S(""),w(""))},disabled:!l.trim(),className:"px-2.5 py-1 rounded bg-brand-500 text-white text-sm font-medium hover:bg-brand-600 disabled:opacity-40 transition-colors",children:"Add"})]})]}):e.jsxs("div",{className:"flex flex-col h-full relative group/body",children:[e.jsxs("div",{className:"absolute top-2 right-4 z-10 flex items-center gap-1 opacity-0 group-hover/body:opacity-100 transition-opacity",children:[e.jsx(qs,{text:H}),q&&e.jsxs("button",{onClick:()=>{const r=new Blob([H],{type:"application/json"}),k=URL.createObjectURL(r),v=document.createElement("a");v.href=k,v.download=`response-${Date.now()}.json`,document.body.appendChild(v),v.click(),document.body.removeChild(v),URL.revokeObjectURL(k)},className:"flex items-center gap-1 px-2.5 py-1 rounded-lg text-sm text-gray-500 hover:text-cyan-400 bg-surface-1/90 hover:bg-cyan-500/10 backdrop-blur-sm border border-white/10 transition-colors",title:"Download as JSON",children:[e.jsx(Fe,{size:13})," Download"]})]}),e.jsx("div",{className:"flex-1 min-h-[200px]",children:e.jsx(Qe,{value:H,language:F,theme:z,options:{readOnly:!0,minimap:{enabled:!1},fontSize:14,lineHeight:22,scrollBeyondLastLine:!1,wordWrap:"on",padding:{top:8,bottom:8},scrollbar:{verticalScrollbarSize:8,horizontalScrollbarSize:8},lineNumbers:"on",folding:!0,bracketPairColorization:{enabled:!0},renderLineHighlight:"none",automaticLayout:!0}})})]})}),b==="headers"&&e.jsx("table",{className:"w-full text-sm",children:e.jsx("tbody",{children:Object.entries(t.headers).map(([r,k])=>e.jsxs("tr",{className:"border-b border-white/5",children:[e.jsx("td",{className:"py-1.5 pr-3 text-gray-400 font-medium whitespace-nowrap align-top",children:r}),e.jsx("td",{className:"py-1.5 text-gray-300 font-mono break-all",children:k})]},r))})}),b==="validations"&&e.jsx("div",{className:"space-y-2",children:y.length===0?e.jsx("p",{className:"text-sm text-gray-600 italic",children:"No validations configured. Use the Validate button to add rules."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg bg-surface-2 border border-white/5 mb-3",children:[e.jsxs("span",{className:"text-sm text-gray-400",children:["Total: ",y.length]}),e.jsxs("span",{className:"flex items-center gap-1 text-sm text-emerald-400",children:[e.jsx(je,{size:13})," ",P," passed"]}),y.length-P>0&&e.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-400",children:[e.jsx(ve,{size:13})," ",y.length-P," failed"]})]}),y.map((r,k)=>{var L;const v=(L=c==null?void 0:c.validations)==null?void 0:L.find(A=>A.id===r.ruleId);return e.jsxs("div",{className:`rounded-xl border px-4 py-3 ${r.passed?"bg-emerald-500/5 border-emerald-500/10":"bg-red-500/5 border-red-500/10"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r.passed?e.jsx(je,{size:15,className:"text-emerald-400 flex-shrink-0"}):e.jsx(ve,{size:15,className:"text-red-400 flex-shrink-0"}),e.jsx("span",{className:`text-sm font-semibold ${r.passed?"text-emerald-400":"text-red-400"}`,children:r.passed?"Passed":"Failed"}),v&&e.jsxs("span",{className:"text-sm text-gray-500",children:["— ",v.type,v.target?` (${v.target})`:""]})]}),v&&e.jsxs("div",{className:"mt-2 ml-6 space-y-1 text-sm",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-gray-500 w-16 flex-shrink-0",children:"Type:"}),e.jsx("span",{className:"text-gray-300 font-mono",children:v.type})]}),v.target&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-gray-500 w-16 flex-shrink-0",children:"Target:"}),e.jsx("span",{className:"text-gray-300 font-mono break-all",children:v.target})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-gray-500 w-16 flex-shrink-0",children:"Rule:"}),e.jsxs("span",{className:"text-gray-300 font-mono",children:[v.operator," ",v.expected]})]}),r.actual!==void 0&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-gray-500 w-16 flex-shrink-0",children:"Actual:"}),e.jsx("span",{className:`font-mono break-all ${r.passed?"text-emerald-300":"text-red-300"}`,children:r.actual})]}),r.message&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-gray-500 w-16 flex-shrink-0",children:"Info:"}),e.jsx("span",{className:"text-gray-400",children:r.message})]})]}),!v&&r.message&&e.jsx("p",{className:"text-sm text-gray-500 mt-1 ml-6",children:r.message})]},r.ruleId||k)})]})}),b==="variables"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-gray-300 mb-2 flex items-center gap-1.5",children:[e.jsx(Ie,{size:14,className:"text-brand-400"})," Predefined Variables"]}),Object.keys(d).length===0?e.jsx("p",{className:"text-sm text-gray-600 italic",children:"No environment variables set. Select an environment to see variables."}):e.jsx("div",{className:"space-y-1",children:Object.entries(d).map(([r,k])=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-surface-2 border border-white/5 text-sm",children:[e.jsx("span",{className:"text-brand-300 font-mono font-medium",children:`{{${r}}}`}),e.jsx("span",{className:"text-gray-600",children:"="}),e.jsx("span",{className:"text-gray-300 font-mono truncate flex-1",children:k}),e.jsx(it,{text:`{{${r}}}`,title:"Copy reference"})]},r))})]}),Object.keys(m).length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-gray-300 mb-2 flex items-center gap-1.5",children:[e.jsx(Ie,{size:14,className:"text-cyan-400"})," Extracted Variables"]}),e.jsx("div",{className:"space-y-1",children:Object.entries(m).map(([r,k])=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-cyan-500/5 border border-cyan-500/10 text-sm",children:[e.jsx("span",{className:"text-cyan-300 font-mono font-medium",children:`{{${r}}}`}),e.jsx("span",{className:"text-gray-600",children:"="}),e.jsx("span",{className:"text-gray-300 font-mono truncate flex-1",children:k}),e.jsx(it,{text:`{{${r}}}`,title:"Copy reference"})]},r))})]}),e.jsx("div",{className:"px-3 py-2 rounded-lg bg-brand-500/5 border border-brand-500/10",children:e.jsxs("p",{className:"text-sm text-gray-500",children:["Use ",e.jsx("code",{className:"px-1 py-0.5 bg-surface-2 rounded text-cyan-400 font-mono text-sm",children:"{{variableName}}"})," in URLs, headers, body, and auth fields. Variables are resolved at send time."]})})]}),b==="timing"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-surface-1 border border-white/5 rounded-lg",children:[e.jsx("span",{className:"text-sm text-gray-400",children:"Total Duration"}),e.jsxs("span",{className:"text-sm font-bold text-gray-200",children:[t.duration,"ms"]})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-surface-1 border border-white/5 rounded-lg",children:[e.jsx("span",{className:"text-sm text-gray-400",children:"Response Size"}),e.jsx("span",{className:"text-sm font-medium text-gray-200",children:lt(t.size)})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-surface-1 border border-white/5 rounded-lg",children:[e.jsx("span",{className:"text-sm text-gray-400",children:"Timestamp"}),e.jsx("span",{className:"text-sm text-gray-300",children:pt(t.timestamp)})]})]})]})]})}function it({text:t,title:a="Copy"}){const[s,n]=x.useState(!1),d=()=>{try{navigator.clipboard.writeText(t).then(()=>{n(!0),setTimeout(()=>n(!1),1500)}).catch(()=>{const c=document.createElement("textarea");c.value=t,c.style.position="fixed",c.style.opacity="0",document.body.appendChild(c),c.select(),document.execCommand("copy"),document.body.removeChild(c),n(!0),setTimeout(()=>n(!1),1500)})}catch{const c=document.createElement("textarea");c.value=t,c.style.position="fixed",c.style.opacity="0",document.body.appendChild(c),c.select(),document.execCommand("copy"),document.body.removeChild(c),n(!0),setTimeout(()=>n(!1),1500)}};return e.jsx("button",{onClick:d,className:`flex-shrink-0 p-1 rounded transition-colors ${s?"text-emerald-400":"text-gray-600 hover:text-cyan-400"}`,title:s?"Copied!":a,children:s?e.jsx(Je,{size:13}):e.jsx(Ee,{size:13})})}function qs({text:t}){const[a,s]=x.useState(!1);return e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(t).catch(()=>{}),s(!0),setTimeout(()=>s(!1),1500)},className:`flex items-center gap-1 px-2.5 py-1 rounded-lg text-sm backdrop-blur-sm border border-white/10 transition-colors ${a?"text-emerald-400 bg-emerald-500/20":"text-gray-500 hover:text-cyan-400 bg-surface-1/90 hover:bg-cyan-500/10"}`,title:a?"Copied!":"Copy response",children:a?e.jsxs(e.Fragment,{children:[e.jsx(Je,{size:13})," Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ee,{size:13})," Copy"]})})}function Os({environments:t,activeEnvId:a,onSelectEnv:s,onSave:n,onDelete:d,onClose:c}){const[m,b]=x.useState(t.find(r=>r.id===a)||null),[i,p]=x.useState(""),[u,l]=x.useState(null),[w,f]=x.useState(null),S=x.useRef(!1);x.useEffect(()=>{if(!m||S.current)return;const r=t.find(k=>k.id===m.id);r&&b(r)},[t]);const z=r=>{S.current=!0,b(r)},H=()=>{if(!i.trim())return;const r={id:`env-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,name:i.trim(),variables:[]};n(r),b(r),p("")},F=()=>{if(!m)return;const r={id:`env-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,name:`${m.name} (copy)`,variables:m.variables.map(k=>({...k}))};n(r),b(r)},q=(r,k,v)=>{if(!m)return;const L=[...m.variables];L[r]={...L[r],[k]:v},z({...m,variables:L})},y=()=>{m&&z({...m,variables:[...m.variables,{key:"",value:"",enabled:!0,secret:!1}]})},P=r=>{m&&z({...m,variables:m.variables.filter((k,v)=>v!==r)})},M=()=>{m&&(S.current=!1,n(m))},K=r=>{navigator.clipboard.writeText(`{{${r}}}`).catch(()=>{}),l(r),setTimeout(()=>l(null),1500)};return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:c,children:[e.jsxs("div",{className:"w-[860px] max-h-[85vh] bg-surface-1 rounded-2xl border border-white/10 shadow-2xl flex flex-col",onClick:r=>r.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-white/5 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(ze,{size:20,className:"text-emerald-400"}),e.jsx("h2",{className:"text-lg font-semibold text-gray-200",children:"Manage Environments"})]}),e.jsx("button",{onClick:c,className:"p-1.5 rounded-lg text-gray-500 hover:text-gray-300 hover:bg-white/5 transition-colors",children:e.jsx(he,{size:18})})]}),e.jsxs("div",{className:"flex flex-1 overflow-hidden min-h-0",children:[e.jsxs("div",{className:"w-56 border-r border-white/5 flex flex-col bg-black/10",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto py-2",children:[t.length===0&&e.jsx("div",{className:"text-center py-6 text-sm text-gray-600",children:"No environments yet"}),t.map(r=>e.jsxs("div",{className:`flex items-center gap-2.5 px-4 py-2.5 cursor-pointer transition-colors group ${(m==null?void 0:m.id)===r.id?"bg-brand-500/10 border-r-2 border-r-brand-400":"hover:bg-white/[0.03] border-r-2 border-r-transparent"}`,onClick:()=>{S.current=!1,b(r)},children:[e.jsx("input",{type:"radio",name:"activeEnv",checked:a===r.id,onChange:()=>s(a===r.id?null:r.id),onClick:k=>k.stopPropagation(),className:"w-3.5 h-3.5 accent-emerald-500 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:`text-sm truncate block ${(m==null?void 0:m.id)===r.id?"text-gray-200 font-medium":"text-gray-400"}`,children:r.name}),e.jsxs("span",{className:"text-xs text-gray-600",children:[r.variables.length," vars"]})]}),a===r.id&&e.jsx(je,{size:14,className:"text-emerald-400 flex-shrink-0"}),e.jsx("button",{onClick:k=>{k.stopPropagation(),f({id:r.id,name:r.name})},className:"p-1 text-gray-600 hover:text-red-400 opacity-0 group-hover:opacity-100 transition-all flex-shrink-0",children:e.jsx(ie,{size:13})})]},r.id))]}),e.jsx("div",{className:"px-3 py-3 mb-2 border-t border-white/5 flex-shrink-0",children:e.jsx("input",{value:i,onChange:r=>p(r.target.value),onKeyDown:r=>{r.key==="Enter"&&H()},placeholder:"New environment... (Enter to create)",className:"w-full px-2.5 py-2 text-sm bg-surface-2 border border-white/10 rounded-lg text-gray-300 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"})})]}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[m?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-white/5 flex-shrink-0",children:[e.jsx("input",{value:m.name,onChange:r=>z({...m,name:r.target.value}),className:"text-base font-semibold bg-surface-2 border border-white/10 rounded-lg px-3 py-1.5 text-gray-200 focus:outline-none focus:border-brand-500/50 flex-1 max-w-[300px]"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:F,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm rounded-lg bg-surface-2 text-gray-400 hover:text-gray-200 hover:bg-surface-3 border border-white/5 transition-colors",title:"Duplicate environment",children:[e.jsx(Ee,{size:13})," Duplicate"]}),e.jsxs("button",{onClick:M,className:"flex items-center gap-1.5 px-4 py-1.5 text-sm font-medium rounded-lg bg-brand-600 text-white hover:bg-brand-500 transition-colors",children:[e.jsx(we,{size:14})," Save"]})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2 text-xs text-gray-600 uppercase tracking-wider font-medium",children:[e.jsx("span",{className:"w-6"}),e.jsx("span",{className:"flex-1",children:"Variable Name"}),e.jsx("span",{className:"flex-1",children:"Value"}),e.jsx("span",{className:"w-24"})]}),e.jsx("div",{className:"space-y-1.5",children:m.variables.map((r,k)=>e.jsxs("div",{className:"flex items-center gap-2 group",children:[e.jsx("input",{type:"checkbox",checked:r.enabled,onChange:v=>q(k,"enabled",v.target.checked),className:"w-4 h-4 accent-emerald-500 rounded flex-shrink-0"}),e.jsx("input",{value:r.key,onChange:v=>q(k,"key",v.target.value),placeholder:"variable_name",className:"flex-1 px-3 py-2 text-sm font-mono bg-surface-2 border border-white/10 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"}),e.jsx("input",{type:r.secret?"password":"text",value:r.value,onChange:v=>q(k,"value",v.target.value),placeholder:"value",className:"flex-1 px-3 py-2 text-sm font-mono bg-surface-2 border border-white/10 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50"}),e.jsxs("div",{className:"flex items-center gap-0.5 w-24 justify-end flex-shrink-0",children:[e.jsx("button",{onClick:()=>q(k,"secret",!r.secret),className:"p-1.5 rounded-lg text-gray-600 hover:text-gray-300 hover:bg-white/5 transition-colors",title:r.secret?"Show value":"Hide value",children:r.secret?e.jsx(Qt,{size:14}):e.jsx(Gt,{size:14})}),r.key&&e.jsx("button",{onClick:()=>K(r.key),className:`p-1.5 rounded-lg transition-colors ${u===r.key?"text-emerald-400 bg-emerald-500/10":"text-gray-600 hover:text-brand-400 hover:bg-white/5 opacity-0 group-hover:opacity-100"}`,title:u===r.key?"Copied!":`Copy {{${r.key}}}`,children:u===r.key?e.jsx(we,{size:14}):e.jsx(Ee,{size:14})}),e.jsx("button",{onClick:()=>P(k),className:"p-1.5 rounded-lg text-gray-600 hover:text-red-400 hover:bg-red-500/10 opacity-0 group-hover:opacity-100 transition-all",children:e.jsx(ie,{size:14})})]})]},k))}),e.jsxs("button",{onClick:y,className:"flex items-center gap-1.5 text-sm text-brand-400 hover:text-brand-300 mt-3 px-1",children:[e.jsx(pe,{size:14})," Add Variable"]}),m.variables.filter(r=>r.key&&r.enabled).length>0&&e.jsxs("div",{className:"pt-4 mt-4 border-t border-white/5",children:[e.jsx("p",{className:"text-xs text-gray-500 uppercase tracking-wider font-medium mb-2",children:"Available Variables"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:m.variables.filter(r=>r.key&&r.enabled).map(r=>e.jsx("button",{onClick:()=>K(r.key),className:`px-2 py-1 rounded-lg text-sm font-mono transition-colors ${u===r.key?"bg-emerald-500/20 text-emerald-400":"bg-surface-2 text-gray-400 hover:text-gray-200 hover:bg-surface-3 border border-white/5"}`,title:`Click to copy {{${r.key}}}`,children:u===r.key?"Copied!":`{{${r.key}}}`},r.key))})]})]})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ze,{size:28,className:"text-gray-700 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-gray-500",children:"Select or create an environment"})]})}),e.jsx("div",{className:"px-5 py-3 border-t border-white/5 bg-surface-2/20 flex-shrink-0",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(Wt,{size:15,className:"text-brand-400 mt-0.5 flex-shrink-0"}),e.jsxs("p",{className:"text-sm text-gray-500 leading-relaxed",children:["Use ",e.jsx("code",{className:"px-1.5 py-0.5 bg-surface-2 rounded text-cyan-400 font-mono text-sm",children:"{{variableName}}"})," in URLs, headers, body, and auth fields. Example: ",e.jsx("code",{className:"px-1.5 py-0.5 bg-surface-2 rounded text-cyan-400 font-mono text-sm",children:"{{baseUrl}}/api/users"})]})]})})]})]})]}),w&&e.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>f(null),children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-2xl shadow-xl w-full max-w-md p-6",onClick:r=>r.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-red-500/10 flex items-center justify-center flex-shrink-0",children:e.jsx(ie,{size:20,className:"text-red-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-gray-200",children:"Delete Environment"}),e.jsx("p",{className:"text-sm text-gray-500 mt-0.5",children:"This action cannot be undone"})]})]}),e.jsx("p",{className:"text-sm text-gray-400 mb-2",children:"Are you sure you want to delete this environment?"}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 rounded-lg bg-surface-2 border border-white/5 mb-2",children:[e.jsx(ze,{size:14,className:"text-emerald-400 flex-shrink-0"}),e.jsx("span",{className:"text-sm font-medium text-gray-200 truncate",children:w.name})]}),e.jsx("p",{className:"text-sm text-orange-400/80 mb-5",children:"All variables in this environment will be permanently deleted."}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>f(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(w.id),(m==null?void 0:m.id)===w.id&&b(null),f(null)},className:"px-4 py-2 rounded-lg text-sm font-medium text-white bg-red-600 hover:bg-red-500 transition-colors",children:"Delete"})]})]})})]})}const Is={GET:"text-emerald-400",POST:"text-blue-400",PUT:"text-amber-400",PATCH:"text-brand-400",DELETE:"text-red-400",HEAD:"text-purple-400",OPTIONS:"text-gray-400"};function Ts(t){return t>=200&&t<300?"text-emerald-400":t>=300&&t<400?"text-blue-400":t>=400&&t<500?"text-amber-400":t>=500?"text-red-400":"text-gray-500"}function Fs({onSelectRequest:t,onClose:a}){const{data:s}=ms(),n=us(),d=(s==null?void 0:s.history)||[];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-white/5 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Le,{size:13,className:"text-gray-500"}),e.jsx("span",{className:"text-sm font-semibold uppercase text-gray-500 tracking-wider",children:"History"})]}),e.jsxs("div",{className:"flex gap-1",children:[d.length>0&&e.jsx("button",{onClick:()=>n.mutate(),className:"p-1 text-gray-600 hover:text-red-400",title:"Clear history",children:e.jsx(ie,{size:14})}),e.jsx("button",{onClick:a,className:"p-1 text-gray-500 hover:text-gray-300",children:e.jsx(he,{size:14})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:d.length===0?e.jsx("div",{className:"px-3 py-6 text-center text-sm text-gray-600",children:"No history yet"}):d.map(c=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 hover:bg-white/5 cursor-pointer border-b border-white/[0.03]",onClick:()=>t(c.request),children:[e.jsx("span",{className:`text-sm font-bold w-8 flex-shrink-0 ${Is[c.request.method]}`,children:c.request.method.slice(0,3)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm text-gray-300 truncate font-mono",children:c.request.url}),e.jsx("p",{className:"text-sm text-gray-600",children:pt(c.timestamp)})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("span",{className:`text-sm font-medium ${Ts(c.response.status)}`,children:c.response.status}),e.jsxs("span",{className:"text-sm text-gray-600",children:[c.response.duration,"ms"]})]})]},c.id))})]})}function Ae(t){if(typeof t.passed=="boolean")return t.passed;const a=t.response.status;return a>=200&&a<300&&!(t.response.validationResults??[]).some(s=>!s.passed)}const Ue={GET:"text-emerald-400",POST:"text-blue-400",PUT:"text-amber-400",PATCH:"text-brand-400",DELETE:"text-red-400",HEAD:"text-purple-400",OPTIONS:"text-gray-400"};function Ls(t){return t>=200&&t<300?"text-emerald-400 bg-emerald-400/10":t>=300&&t<400?"text-blue-400 bg-blue-400/10":t>=400&&t<500?"text-amber-400 bg-amber-400/10":t>=500?"text-red-400 bg-red-400/10":"text-gray-400 bg-gray-400/10"}function Vs({folder:t,variables:a={},onClose:s}){const{monacoTheme:n}=Ge(),[d,c]=x.useState(!1),[m,b]=x.useState([]),[i,p]=x.useState(null),[u,l]=x.useState(!1),[w,f]=x.useState({}),S=t.requests,z=async()=>{if(S.length!==0){c(!0),b([]),p(null),f({});try{const y=await It(S,a),P=y.steps||(y.responses||[]).map((K,r)=>({index:r,request:S[r],response:K,extractedVars:{}}));b(P);const M={...a};for(const K of P)Object.assign(M,K.extractedVars);f(M)}catch(y){b([{index:0,request:S[0],response:{requestId:S[0].id,status:0,statusText:"Error",headers:{},body:String(y),duration:0,size:0,timestamp:new Date().toISOString()},extractedVars:{},error:String(y)}])}finally{c(!1)}}},H=m.filter(Ae).length,F=m.filter(y=>!Ae(y)&&!y.skipped).length,q=m.reduce((y,P)=>y+P.response.duration,0);return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-xl w-[700px] max-h-[85vh] flex flex-col animate-fade-in",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Be,{size:16,className:"text-brand-400"}),e.jsx("h2",{className:"text-sm font-bold text-gray-100",children:"Chain Runner"}),e.jsxs("span",{className:"text-sm text-gray-500",children:[t.name," (",S.length," request",S.length!==1?"s":"",")"]})]}),e.jsx("button",{onClick:s,className:"p-1 text-gray-500 hover:text-gray-300 transition-colors",children:e.jsx(he,{size:16})})]}),e.jsxs("div",{className:"flex items-center gap-3 px-5 py-3 border-b border-white/5",children:[e.jsx("button",{onClick:z,disabled:d||S.length===0,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-lg bg-brand-500 text-white text-sm font-medium hover:bg-brand-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:d?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14,className:"animate-spin"})," Running..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Be,{size:14})," Run Chain"]})}),m.length>0&&e.jsxs("div",{className:"flex items-center gap-3 text-sm text-gray-400",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(je,{size:14,className:"text-emerald-400"}),H," passed"]}),F>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ve,{size:14,className:"text-red-400"}),F," failed"]}),e.jsx("span",{className:"text-gray-600",children:"|"}),e.jsxs("span",{children:[q,"ms total"]})]}),e.jsx("div",{className:"ml-auto",children:e.jsxs("button",{onClick:()=>l(!u),className:`flex items-center gap-1 px-2 py-1 rounded text-sm transition-colors ${u?"bg-brand-500/15 text-brand-300":"bg-surface-2 text-gray-500 hover:text-gray-300"}`,children:[e.jsx(Ie,{size:13})," Variables"]})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-1.5",children:[m.length===0&&!d&&e.jsx("div",{className:"space-y-1",children:S.map((y,P)=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-surface-2 border border-white/5",children:[e.jsxs("span",{className:"text-sm text-gray-600 w-5 text-right",children:[P+1,"."]}),e.jsx("span",{className:`text-sm font-bold w-12 ${Ue[y.method]||"text-gray-400"}`,children:y.method}),e.jsx("span",{className:"text-sm text-gray-300 truncate flex-1",children:y.name||y.url}),P<S.length-1&&e.jsx(xt,{size:13,className:"text-gray-600 flex-shrink-0"})]},y.id))}),d&&m.length<S.length&&e.jsx("div",{className:"space-y-1",children:S.map((y,P)=>{const M=m[P],K=P===m.length,r=P>m.length;return e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg border ${M?"bg-surface-2 border-white/5":K?"bg-brand-500/5 border-brand-500/20":"bg-surface-2 border-white/5 opacity-50"}`,children:[e.jsxs("span",{className:"text-sm text-gray-600 w-5 text-right",children:[P+1,"."]}),M?Ae(M)?e.jsx(je,{size:13,className:"text-emerald-400 flex-shrink-0"}):e.jsx(ve,{size:13,className:"text-red-400 flex-shrink-0"}):K?e.jsx(Te,{size:13,className:"text-brand-400 animate-spin flex-shrink-0"}):e.jsx("div",{className:"w-3.5 h-3.5 rounded-full border border-gray-600 flex-shrink-0"}),e.jsx("span",{className:`text-sm font-bold w-12 ${Ue[y.method]||"text-gray-400"}`,children:y.method}),e.jsx("span",{className:`text-sm truncate flex-1 ${r?"text-gray-600":"text-gray-300"}`,children:y.name||y.url}),M&&e.jsxs("span",{className:"text-sm text-gray-500",children:[M.response.duration,"ms"]})]},y.id)})}),!d&&m.length>0&&e.jsx("div",{className:"space-y-1",children:m.map(y=>e.jsxs("div",{className:"rounded-lg border border-white/5 overflow-hidden",children:[e.jsxs("button",{onClick:()=>p(i===y.index?null:y.index),className:"w-full flex items-center gap-2 px-3 py-2 bg-surface-2 hover:bg-surface-3 transition-colors text-left",children:[i===y.index?e.jsx(oe,{size:14,className:"text-gray-500 flex-shrink-0"}):e.jsx(xe,{size:14,className:"text-gray-500 flex-shrink-0"}),e.jsxs("span",{className:"text-sm text-gray-600 w-5 text-right",children:[y.index+1,"."]}),Ae(y)?e.jsx(je,{size:13,className:"text-emerald-400 flex-shrink-0"}):e.jsx(ve,{size:13,className:"text-red-400 flex-shrink-0"}),e.jsx("span",{className:`text-sm font-bold w-12 ${Ue[y.request.method]||"text-gray-400"}`,children:y.request.method}),e.jsx("span",{className:"text-sm text-gray-300 truncate flex-1",children:y.request.name||y.request.url}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-sm font-mono ${Ls(y.response.status)}`,children:y.response.status||"ERR"}),e.jsxs("span",{className:"text-sm text-gray-500 w-14 text-right",children:[y.response.duration,"ms"]})]}),i===y.index&&e.jsx(Us,{step:y,monacoTheme:n,variables:w})]},y.index))})]}),u&&e.jsxs("div",{className:"border-t border-white/5 px-5 py-3 max-h-40 overflow-y-auto",children:[e.jsx("h3",{className:"text-sm text-gray-500 uppercase tracking-wider mb-2",children:"Runtime Variables"}),Object.keys(w).length===0&&Object.keys(a).length===0?e.jsx("p",{className:"text-sm text-gray-600 italic",children:"No variables set"}):e.jsx("div",{className:"space-y-0.5",children:Object.entries({...a,...w}).map(([y,P])=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-brand-300 font-mono w-32 truncate",children:`{{${y}}}`}),e.jsx("span",{className:"text-gray-600",children:"="}),e.jsx("span",{className:"text-gray-300 font-mono truncate flex-1",children:P}),w[y]&&!a[y]&&e.jsx("span",{className:"text-sm px-1 py-0.5 rounded bg-amber-500/15 text-amber-400",children:"extracted"})]},y))})]})]})})}function ot({text:t}){const[a,s]=x.useState(!1);return e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(t).catch(()=>{}),s(!0),setTimeout(()=>s(!1),1500)},className:`flex items-center gap-1 px-2 py-0.5 rounded text-sm transition-colors ${a?"text-emerald-400 bg-emerald-500/10":"text-gray-600 hover:text-cyan-400 hover:bg-cyan-500/10"}`,title:a?"Copied!":"Copy",children:a?e.jsxs(e.Fragment,{children:[e.jsx(Je,{size:12})," Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ee,{size:12})," Copy"]})})}function Us({step:t,monacoTheme:a,variables:s}){var K,r,k;const[n,d]=x.useState(!1),[c,m]=x.useState(!1),b=t.request,i=t.response,p=i.status>=200&&i.status<400,u=b.url.replace(/\{\{(\w+)\}\}/g,(v,L)=>s[L]??`{{${L}}}`),l=u!==b.url,w=((K=b.body)==null?void 0:K.type)!=="none"&&((r=b.body)==null?void 0:r.raw),f=w?(()=>{try{return JSON.stringify(JSON.parse(b.body.raw),null,2)}catch{return b.body.raw}})():"",S=w&&(()=>{try{return JSON.parse(b.body.raw),!0}catch{return!1}})(),z=Hs(i.body),H=(()=>{try{return JSON.parse(i.body),!0}catch{return!1}})(),F=z.split(`
16
+ `).length,q=Math.min(Math.max(F*18,50),220),y={GET:"text-emerald-400 bg-emerald-500/15",POST:"text-blue-400 bg-blue-500/15",PUT:"text-amber-400 bg-amber-500/15",PATCH:"text-brand-400 bg-brand-500/15",DELETE:"text-red-400 bg-red-500/15"},P=(v,L)=>{const A=new Blob([v],{type:"application/json"}),Y=URL.createObjectURL(A),O=document.createElement("a");O.href=Y,O.download=L,document.body.appendChild(O),O.click(),document.body.removeChild(O),URL.revokeObjectURL(Y)},M=b.validations||[];return e.jsxs("div",{className:"border-t border-white/5 bg-surface-1",children:[t.error&&e.jsx("div",{className:"mx-4 mt-3 px-3 py-2 rounded-lg bg-red-500/10 border border-red-500/20 text-sm text-red-300",children:t.error}),e.jsxs("div",{className:"px-4 py-3 border-b border-white/[0.03]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(ze,{size:13,className:"text-gray-500"}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-sm font-bold ${y[b.method]||"text-gray-400 bg-gray-500/15"}`,children:b.method}),e.jsx("span",{className:"text-sm font-mono text-gray-300 break-all",children:b.url})]}),b.name&&e.jsx("div",{className:"text-sm text-gray-500 ml-5",children:b.name}),l&&e.jsxs("div",{className:"flex items-center gap-2 mt-1 ml-5",children:[e.jsx("span",{className:"text-sm text-gray-600",children:"Resolved:"}),e.jsx("span",{className:"text-sm font-mono break-all",style:{color:"#d39034cc"},children:u})]})]}),((k=b.headers)==null?void 0:k.filter(v=>v.enabled).length)>0&&e.jsxs("div",{className:"border-b border-white/[0.03]",children:[e.jsxs("button",{onClick:()=>m(!c),className:"w-full flex items-center gap-1.5 px-4 py-2 text-sm text-gray-500 hover:text-gray-300 hover:bg-white/[0.02] transition-colors",children:[c?e.jsx(oe,{size:12}):e.jsx(xe,{size:12}),e.jsx("span",{className:"font-medium",children:"Request Headers"}),e.jsxs("span",{className:"text-gray-600",children:["(",b.headers.filter(v=>v.enabled).length,")"]})]}),c&&e.jsx("div",{className:"px-4 pb-2 space-y-0.5",children:b.headers.filter(v=>v.enabled).map((v,L)=>e.jsxs("div",{className:"flex gap-2 text-sm font-mono",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 font-medium flex-shrink-0",children:[v.key,":"]}),e.jsx("span",{className:"text-gray-400 break-all",children:v.value})]},L))})]}),w&&e.jsxs("div",{className:"border-b border-white/[0.03]",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-1.5",children:[e.jsx("span",{className:"text-sm text-gray-500 font-medium",children:"Request Body"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ot,{text:f}),S&&e.jsxs("button",{onClick:()=>P(f,`step-${t.index+1}-request-${Date.now()}.json`),className:"flex items-center gap-1 px-2 py-0.5 rounded text-sm text-gray-600 hover:text-cyan-400 hover:bg-cyan-500/10 transition-colors",title:"Download as JSON",children:[e.jsx(Fe,{size:12})," Download"]})]})]}),e.jsx("pre",{className:"px-4 pb-2 text-sm font-mono text-orange-700 dark:text-orange-300/70 whitespace-pre-wrap break-words max-h-[150px] overflow-auto",children:f})]}),e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 border-b border-white/[0.03]",children:[e.jsx("span",{className:"text-sm text-gray-500 font-medium",children:"Response"}),e.jsxs("span",{className:`px-2 py-0.5 rounded-lg text-sm font-bold ${p?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,children:[i.status," ",i.statusText]}),e.jsxs("div",{className:"flex items-center gap-3 ml-auto text-sm text-gray-500",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Le,{size:12})," ",i.duration,"ms"]}),e.jsx("span",{children:i.size>0?i.size<1024?`${i.size}B`:`${(i.size/1024).toFixed(1)}KB`:""})]})]}),Object.keys(i.headers).length>0&&e.jsxs("div",{className:"border-b border-white/[0.03]",children:[e.jsxs("button",{onClick:()=>d(!n),className:"w-full flex items-center gap-1.5 px-4 py-2 text-sm text-gray-500 hover:text-gray-300 hover:bg-white/[0.02] transition-colors",children:[n?e.jsx(oe,{size:12}):e.jsx(xe,{size:12}),e.jsx("span",{className:"font-medium",children:"Response Headers"}),e.jsxs("span",{className:"text-gray-600",children:["(",Object.keys(i.headers).length,")"]})]}),n&&e.jsx("div",{className:"px-4 pb-2 space-y-0.5",children:Object.entries(i.headers).map(([v,L])=>e.jsxs("div",{className:"flex gap-2 text-sm font-mono",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 font-medium flex-shrink-0",children:[v,":"]}),e.jsx("span",{className:"text-gray-400 break-all",children:String(L)})]},v))})]}),i.validationResults&&i.validationResults.length>0&&e.jsxs("div",{className:"px-4 py-2 border-b border-white/[0.03]",children:[e.jsx("span",{className:"text-sm text-gray-500 font-medium",children:"Validations"}),e.jsx("div",{className:"mt-1.5 space-y-1.5",children:i.validationResults.map((v,L)=>{const A=M.find(Y=>Y.id===v.ruleId);return e.jsxs("div",{className:"rounded-lg border border-white/[0.03] px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-sm",children:[v.passed?e.jsx(je,{size:14,className:"text-emerald-400 flex-shrink-0"}):e.jsx(ve,{size:14,className:"text-red-400 flex-shrink-0"}),e.jsx("span",{className:`font-medium ${v.passed?"text-emerald-400":"text-red-400"}`,children:v.passed?"Passed":"Failed"}),A&&e.jsxs("span",{className:"text-gray-500 ml-1",children:["— ",A.type,A.target?` (${A.target})`:""]})]}),A&&e.jsxs("div",{className:"mt-1 ml-5 space-y-0.5 text-sm",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-gray-600 w-16 flex-shrink-0",children:"Rule:"}),e.jsxs("span",{className:"text-gray-400 font-mono",children:[A.type," ",A.target||""," ",A.operator," ",A.expected]})]}),v.actual!==void 0&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-gray-600 w-16 flex-shrink-0",children:"Actual:"}),e.jsx("span",{className:`font-mono ${v.passed?"text-gray-300":"text-red-300"}`,children:v.actual})]}),v.message&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-gray-600 w-16 flex-shrink-0",children:"Message:"}),e.jsx("span",{className:"text-gray-400",children:v.message})]})]})]},L)})})]}),Object.keys(t.extractedVars).length>0&&e.jsxs("div",{className:"px-4 py-2 bg-cyan-500/5 border-b border-white/[0.03]",children:[e.jsx("span",{className:"text-sm text-cyan-400 font-medium",children:"Extracted Variables"}),e.jsx("div",{className:"mt-1 space-y-0.5",children:Object.entries(t.extractedVars).map(([v,L])=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-brand-300 font-mono",children:`{{${v}}}`}),e.jsx("span",{className:"text-gray-600",children:"="}),e.jsx("span",{className:"text-gray-300 font-mono truncate",children:L})]},v))})]}),i.body&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-1.5",children:[e.jsx("span",{className:"text-sm text-gray-500 font-medium",children:"Response Body"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ot,{text:z}),H&&e.jsxs("button",{onClick:()=>P(z,`step-${t.index+1}-response-${Date.now()}.json`),className:"flex items-center gap-1 px-2 py-0.5 rounded text-sm text-gray-600 hover:text-cyan-400 hover:bg-cyan-500/10 transition-colors",title:"Download as JSON",children:[e.jsx(Fe,{size:12})," Download"]})]})]}),H?e.jsx("div",{style:{height:`${q}px`},children:e.jsx(Qe,{value:z,language:"json",theme:a,options:{readOnly:!0,minimap:{enabled:!1},fontSize:13,lineHeight:18,scrollBeyondLastLine:!1,wordWrap:"on",padding:{top:4,bottom:4},scrollbar:{verticalScrollbarSize:5,horizontalScrollbarSize:5},lineNumbers:"off",folding:!0,bracketPairColorization:{enabled:!0},renderLineHighlight:"none",automaticLayout:!0}})}):e.jsx("pre",{className:"px-4 pb-3 text-sm text-gray-400 font-mono bg-surface-2 rounded mx-4 mb-3 p-2 max-h-[200px] overflow-auto whitespace-pre-wrap break-all",children:z})]})]})}function Hs(t){try{const a=JSON.parse(t),s=JSON.stringify(a,null,2);return s.length>2e3?s.slice(0,2e3)+`
17
+ ... (truncated)`:s}catch{return t.length>2e3?t.slice(0,2e3)+`
18
+ ... (truncated)`:t}}function Bs({responseBody:t,onAddValidation:a,onClose:s}){const[n,d]=x.useState(null),[c,m]=x.useState(null),[b,i]=x.useState("equals"),[p,u]=x.useState("");let l;try{l=JSON.parse(t)}catch{l=null}const w=(S,z)=>{d(S),m(z);const H=gt(z);i(H),u(z!=null&&typeof z!="object"?String(z):"")},f=()=>{if(!n)return;const S={id:`vr-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,type:"body-json-path",target:n,operator:b,expected:p,enabled:!0};a(S),d(null),m(null),u("")};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-xl w-[600px] max-h-[80vh] flex flex-col animate-fade-in",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(mt,{size:16,className:"text-brand-400"}),e.jsx("h3",{className:"text-sm font-bold text-gray-100",children:"Quick Validate"}),e.jsx("span",{className:"text-sm text-gray-500",children:"Click any value to create a validation"})]}),e.jsx("button",{onClick:s,className:"p-1 text-gray-500 hover:text-gray-300",children:e.jsx(he,{size:16})})]}),e.jsx("div",{className:"flex-1 overflow-auto p-4",children:l?e.jsx(_e,{data:l,onSelectPath:w}):e.jsx("p",{className:"text-sm text-gray-500 italic",children:"Response body is not valid JSON"})}),n&&e.jsxs("div",{className:"border-t border-white/5 px-4 py-3 bg-surface-2 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-gray-500 uppercase tracking-wider w-16",children:"Path"}),e.jsx("code",{className:"text-sm text-brand-300 font-mono bg-surface-1 px-2 py-0.5 rounded flex-1 truncate",children:n})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-gray-500 uppercase tracking-wider w-16",children:"Assert"}),e.jsxs("select",{value:b,onChange:S=>i(S.target.value),className:"px-2 py-1 text-sm bg-surface-1 border border-white/5 rounded text-gray-300 focus:outline-none",children:[e.jsx("option",{value:"equals",children:"equals (=)"}),e.jsx("option",{value:"not-equals",children:"not equals (!=)"}),e.jsx("option",{value:"contains",children:"contains"}),e.jsx("option",{value:"not-contains",children:"not contains"}),e.jsx("option",{value:"greater-than",children:"greater than (>)"}),e.jsx("option",{value:"less-than",children:"less than (<)"}),e.jsx("option",{value:"exists",children:"exists"}),e.jsx("option",{value:"matches-regex",children:"regex match"})]}),b!=="exists"&&e.jsx("input",{value:p,onChange:S=>u(S.target.value),placeholder:"Expected value",className:"flex-1 px-2 py-1 text-sm font-mono bg-surface-1 border border-white/5 rounded text-gray-300 placeholder-gray-600 focus:outline-none"}),e.jsxs("button",{onClick:f,className:"flex items-center gap-1 px-3 py-1 rounded-lg bg-brand-500 text-white text-sm font-medium hover:bg-brand-600 transition-colors",children:[e.jsx(pe,{size:14})," Add"]})]})]})]})})}function _s(t){const a=t.match(/<SCENARIOS_JSON>([\s\S]+)<\/SCENARIOS_JSON>/i);if(a){const c=qe(a[1].trim());if(c!=null&&c.scenarios)return c}const s=t.match(/```(?:json)?\s*\n?([\s\S]*?)```/g);if(s){const c=[...s].sort((m,b)=>b.length-m.length);for(const m of c){const b=m.replace(/```(?:json)?\s*\n?/,"").replace(/\n?```$/,"").trim(),i=qe(b);if(i!=null&&i.scenarios)return i}}const n=Ms(t);if(n){const c=qe(n);if(c!=null&&c.scenarios)return c}const d=qe(t.trim());return d!=null&&d.scenarios?d:null}function qe(t){try{return JSON.parse(t)}catch{try{const a=t.replace(/,\s*([\]}])/g,"$1");return JSON.parse(a)}catch{return null}}}function Ms(t){let a=-1,s=0;for(let n=0;n<t.length;n++)if(t[n]==="{"){let d=0,c=!1,m=!1;for(let b=n;b<t.length;b++){const i=t[b];if(m){m=!1;continue}if(i==="\\"&&c){m=!0;continue}if(i==='"'&&!m){c=!c;continue}if(!c){if(i==="{")d++;else if(i==="}"&&(d--,d===0)){const p=b-n+1;p>s&&(a=n,s=p);break}}}}return s>50?t.slice(a,a+s):null}const Oe={GET:"bg-emerald-500/15 text-emerald-400",POST:"bg-blue-500/15 text-blue-400",PUT:"bg-amber-500/15 text-amber-400",PATCH:"bg-brand-500/15 text-brand-400",DELETE:"bg-red-500/15 text-red-400",HEAD:"bg-purple-500/15 text-purple-400",OPTIONS:"bg-gray-500/15 text-gray-400"};function Ks({onClose:t,existingCollections:a=[]}){const[s,n]=x.useState("upload"),[d,c]=x.useState(""),[m,b]=x.useState(""),[i,p]=x.useState(""),[u,l]=x.useState([]),[w,f]=x.useState(null),[S,z]=x.useState(!1),[H,F]=x.useState(""),[q,y]=x.useState([]),[P,M]=x.useState([]),[K,r]=x.useState(""),[k,v]=x.useState(""),[L,A]=x.useState(!1),[Y,O]=x.useState(""),[re,me]=x.useState(new Set),ue=x.useRef(null),{toast:Ne}=Ke(),be=ae(),Z=o=>{try{const C=JSON.parse(o);return C.openapi?"openapi":C.swagger?"swagger":C.info&&C.item?"postman":C.id&&C.requests?"native":"unknown"}catch{return/^\s*openapi\s*:/m.test(o)?"openapi":/^\s*swagger\s*:/m.test(o)?"swagger":"unknown"}},ce=async o=>{var I;const C=(I=o.target.files)==null?void 0:I[0];if(!C)return;const N=await C.text();c(N);const T=Z(N);b(T),await fe(N,T)},fe=async(o,C)=>{const N=o||d;if(!N.trim()){O("Please provide spec content");return}const T=C||m||Z(N);b(T),A(!0),O("");try{const I=await Tt(N,T!=="unknown"?T:void 0);b(I.format),p(I.specName),r(I.specName),f(I.collection),v(I.collection.baseUrl||""),l(I.endpoints.map(G=>({...G,selected:!0}))),n("endpoints")}catch(I){O(`Failed to parse: ${I}`)}finally{A(!1)}},ne=u.filter(o=>o.selected).length,ee=o=>{l(C=>C.map((N,T)=>T===o?{...N,selected:!N.selected}:N))},B=o=>{l(C=>C.map(N=>({...N,selected:o})))},X=async()=>{n("ai-generating"),F("Analyzing API endpoints...");try{const o=u.filter(W=>W.selected),C=`import-ai-${Date.now()}`,N=await Lt({requestId:C,endpoints:o,selectedEndpoints:o,specSummary:i,existingCollections:a,baseUrl:k});F("AI is generating scenarios...");const T=window.location.protocol==="https:"?"wss:":"ws:",I=localStorage.getItem("testver_token")||"",G=new WebSocket(`${T}//${window.location.host}/ws?token=${encodeURIComponent(I)}`);let _="";G.onmessage=W=>{try{const Q=JSON.parse(W.data);if(Q.requestId!==C)return;if(Q.type==="ai-fix-stream"&&(_+=Q.content||"",F(`AI is generating scenarios... (${_.length} chars)`)),Q.type==="ai-fix-done"){G.close();const h=_s(_);h?(y(h.scenarios||[]),M(h.insights||[])):_.length>0?(console.warn("[ImportDialog] AI response could not be parsed. fullText length:",_.length),console.warn("[ImportDialog] First 500 chars:",_.slice(0,500)),console.warn("[ImportDialog] Last 500 chars:",_.slice(-500)),O("AI generated a response but could not parse scenarios JSON. Proceeding with original endpoints.")):(console.warn("[ImportDialog] AI returned empty response (fullText is empty)"),O("AI returned an empty response. Proceeding with original endpoints.")),n("preview")}Q.type==="ai-fix-error"&&(G.close(),O(`AI generation failed: ${Q.message||Q.error||"Unknown error"}`),n("preview"))}catch{}},G.onerror=()=>{O("WebSocket connection failed. Proceeding with original endpoints."),n("preview")},setTimeout(()=>{G.readyState===WebSocket.OPEN&&(G.close(),s==="ai-generating"&&(O("AI generation timed out. Proceeding with original endpoints."),n("preview")))},12e4)}catch(o){O(`AI generation failed: ${o}`),n("preview")}},te=()=>{S&&ne>0?X():n("preview")},le=()=>{if(!w)throw new Error("No parsed collection");const o={...w};o.name=K||i||"Imported API",o.baseUrl=k;const C=new Set(u.filter(N=>N.selected).map(N=>`${N.method}:${N.path}`));if(o.requests=o.requests.filter(N=>C.has(`${N.method}:${N.url}`)||C.has(`${N.method}:${N.url.replace("{{baseUrl}}","")}`)),o.folders=o.folders.map(N=>({...N,requests:N.requests.filter(T=>C.has(`${T.method}:${T.url}`)||C.has(`${T.method}:${T.url.replace("{{baseUrl}}","")}`))})).filter(N=>N.requests.length>0),q.length>0)for(const N of q){const T={id:`fld-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,name:`[AI] ${N.name}`,requests:N.requests.map((I,G)=>{let _=I.body||{type:"none"};_&&typeof _=="object"&&"content"in _&&!_.raw&&(_={..._,raw:_.content},delete _.content);let W=I.url||"";return W&&!W.startsWith("{{")&&!W.startsWith("http")&&(W=`{{baseUrl}}${W.startsWith("/")?"":"/"}${W}`),{...I,id:I.id||`req-${Date.now()}-${Math.random().toString(36).slice(2,6)}-${G}`,name:I.name||`Step ${G+1}`,url:W,headers:I.headers||[],queryParams:I.queryParams||[],body:_,auth:I.auth||{type:"none"},validations:(I.validations||[]).map((Q,h)=>({...Q,id:Q.id||`vr-${Date.now()}-${h}`,enabled:Q.enabled!==!1})),preRequestScript:I.preRequestScript||void 0,postResponseScript:I.postResponseScript||void 0,followRedirects:I.followRedirects!==!1,sortOrder:G}}),sortOrder:o.folders.length};o.folders.push(T)}return k&&(o.environments=[{id:`env-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,name:"Dev",variables:[{key:"baseUrl",value:k,enabled:!0,secret:!1}]}]),o},ke=async()=>{A(!0);try{const o=le();if(await Ft(o),o.environments.length>0)try{localStorage.setItem(`testver-active-env-${o.id}`,o.environments[0].id)}catch{}be.invalidateQueries({queryKey:["api-collections"]}),Ne("success",`Collection "${o.name}" imported with ${o.folders.length} folders`),t()}catch(o){O(`Import failed: ${o}`)}finally{A(!1)}},ye=o=>{me(C=>{const N=new Set(C);return N.has(o)?N.delete(o):N.add(o),N})},se=u.reduce((o,C,N)=>{var I;const T=C.folder||((I=C.tags)==null?void 0:I[0])||"Ungrouped";return o.has(T)||o.set(T,[]),o.get(T).push({...C,originalIndex:N}),o},new Map);return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-1 border border-white/10 rounded-xl w-[750px] max-h-[85vh] flex flex-col animate-fade-in",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($e,{size:16,className:"text-brand-400"}),e.jsx("h2",{className:"text-sm font-bold text-gray-100",children:"Import API Collection"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex items-center gap-1 text-sm text-gray-500",children:["upload","endpoints","preview","confirm"].map((o,C)=>e.jsxs("span",{className:"flex items-center gap-1",children:[C>0&&e.jsx(xe,{size:13,className:"text-gray-700"}),e.jsx("span",{className:s===o?"text-brand-400 font-bold":["upload","endpoints","ai-generating","preview","confirm"].indexOf(s)>["upload","endpoints","preview","confirm"].indexOf(o)?"text-emerald-400":"",children:o==="upload"?"Upload":o==="endpoints"?"Select":o==="preview"?"Preview":"Import"})]},o))}),e.jsx("button",{onClick:t,className:"p-1 text-gray-500 hover:text-gray-300",children:e.jsx(he,{size:16})})]})]}),Y&&e.jsxs("div",{className:"px-5 py-2 bg-red-500/10 border-b border-red-500/20 flex items-center gap-2",children:[e.jsx(Yt,{size:14,className:"text-red-400 flex-shrink-0"}),e.jsx("p",{className:"text-sm text-red-300 flex-1",children:Y}),e.jsx("button",{onClick:()=>O(""),className:"text-red-400 hover:text-red-300",children:e.jsx(he,{size:14})})]}),e.jsxs("div",{className:"flex-1 overflow-auto p-5",children:[s==="upload"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-400 block mb-2",children:"Upload a file (.json, .yaml)"}),e.jsx("input",{ref:ue,type:"file",accept:".json,.yaml,.yml",onChange:ce,className:"hidden"}),e.jsxs("button",{onClick:()=>{var o;return(o=ue.current)==null?void 0:o.click()},className:"w-full py-8 border-2 border-dashed border-white/10 rounded-xl hover:border-brand-500/30 transition-colors flex flex-col items-center gap-2",children:[e.jsx($e,{size:24,className:"text-gray-600"}),e.jsx("span",{className:"text-sm text-gray-500",children:"Click to upload or drag & drop"}),e.jsx("span",{className:"text-sm text-gray-600",children:"Supports: OpenAPI 3.x and Swagger 2.x (JSON or YAML), Postman Collection v2.1"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex-1 border-t border-white/5"}),e.jsx("span",{className:"text-sm text-gray-600 uppercase",children:"or paste JSON"}),e.jsx("div",{className:"flex-1 border-t border-white/5"})]}),e.jsx("textarea",{value:d,onChange:o=>{c(o.target.value),b(Z(o.target.value))},placeholder:'{"openapi": "3.0.0", ...} or {"info": {"name": "..."}, "item": [...]}',className:"w-full h-40 px-3 py-2 text-sm font-mono bg-surface-2 border border-white/5 rounded-lg text-gray-300 placeholder-gray-600 focus:outline-none focus:border-brand-500/50 resize-y"}),m&&m!=="unknown"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(we,{size:14,className:"text-emerald-400"}),e.jsxs("span",{className:"text-sm text-emerald-400",children:["Detected: ",m==="openapi"?"OpenAPI 3.x":m==="swagger"?"Swagger 2.x":m==="postman"?"Postman Collection":"Native Format"]})]})]}),s==="endpoints"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-gray-200",children:i}),e.jsxs("p",{className:"text-sm text-gray-500 mt-0.5",children:[ne," of ",u.length," endpoints selected"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>B(!0),className:"text-sm text-brand-400 hover:text-brand-300",children:"Select All"}),e.jsx("span",{className:"text-gray-700",children:"|"}),e.jsx("button",{onClick:()=>B(!1),className:"text-sm text-gray-500 hover:text-gray-300",children:"Deselect All"})]})]}),e.jsx("div",{className:"border border-white/5 rounded-lg overflow-hidden max-h-[40vh] overflow-y-auto",children:Array.from(se.entries()).map(([o,C])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-surface-2 border-b border-white/5 cursor-pointer",onClick:()=>ye(o),children:[re.has(o)||!re.size?e.jsx(oe,{size:13,className:"text-gray-500"}):e.jsx(xe,{size:13,className:"text-gray-500"}),e.jsx(He,{size:13,className:"text-amber-500/60"}),e.jsx("span",{className:"text-sm text-gray-400 font-medium",children:o}),e.jsxs("span",{className:"text-sm text-gray-600 ml-auto",children:[C.filter(N=>N.selected).length,"/",C.length]})]}),(re.has(o)||!re.size)&&C.map(N=>e.jsxs("label",{className:"flex items-center gap-2 px-4 py-1.5 hover:bg-white/5 cursor-pointer border-b border-white/[2%]",children:[e.jsx("input",{type:"checkbox",checked:N.selected,onChange:()=>ee(N.originalIndex),className:"w-3.5 h-3.5 rounded border-gray-600 bg-surface-2 accent-brand-500"}),e.jsx("span",{className:`text-sm font-bold px-1.5 py-0.5 rounded ${Oe[N.method]||"bg-gray-500/15 text-gray-400"}`,children:N.method}),e.jsx("span",{className:"text-sm text-gray-300 font-mono flex-1 truncate",children:N.path}),(N.summary||N.name)&&e.jsx("span",{className:"text-sm text-gray-600 truncate max-w-[200px]",children:N.summary||N.name})]},N.originalIndex))]},o))}),e.jsx("div",{className:"flex items-center gap-3 p-3 bg-purple-500/5 border border-purple-500/15 rounded-lg",children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer flex-1",children:[e.jsx("input",{type:"checkbox",checked:S,onChange:o=>z(o.target.checked),className:"w-4 h-4 rounded border-gray-600 bg-surface-2 accent-purple-500"}),e.jsx(tt,{size:14,className:"text-purple-400"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm text-purple-300 font-medium",children:"AI Generate Scenarios"}),e.jsx("p",{className:"text-sm text-gray-500",children:"Let AI analyze endpoints and create meaningful test flows"})]})]})})]}),s==="ai-generating"&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-4",children:[e.jsx("div",{className:"w-12 h-12 border-2 border-purple-500 border-t-transparent rounded-full animate-spin"}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-sm text-gray-200 font-medium",children:"Generating Scenarios"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:H})]})]}),s==="preview"&&e.jsxs("div",{className:"space-y-4",children:[P.length>0&&e.jsxs("div",{className:"p-3 bg-purple-500/5 border border-purple-500/15 rounded-lg",children:[e.jsx("h4",{className:"text-sm text-purple-400 uppercase tracking-wider mb-1.5",children:"AI Insights"}),e.jsx("ul",{className:"space-y-0.5",children:P.map((o,C)=>e.jsxs("li",{className:"text-sm text-gray-400 flex items-start gap-1.5",children:[e.jsx("span",{className:"text-purple-400 mt-0.5",children:"*"}),o]},C))})]}),e.jsxs("div",{className:"border border-white/5 rounded-lg overflow-hidden max-h-[45vh] overflow-y-auto",children:[w==null?void 0:w.folders.filter(o=>o.requests.length>0).map(o=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-surface-2 border-b border-white/5",children:[e.jsx(He,{size:13,className:"text-amber-500/60"}),e.jsx("span",{className:"text-sm text-gray-300 font-medium",children:o.name}),e.jsxs("span",{className:"text-sm text-gray-600 ml-auto",children:[o.requests.length," requests"]})]}),o.requests.map(C=>e.jsxs("div",{className:"flex items-center gap-2 px-6 py-1 border-b border-white/[2%]",children:[e.jsx("span",{className:`text-sm font-bold px-1 py-0.5 rounded ${Oe[C.method]||"bg-gray-500/15 text-gray-400"}`,children:C.method}),e.jsx("span",{className:"text-sm text-gray-400 truncate",children:C.name||C.url})]},C.id))]},o.id)),q.map((o,C)=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-purple-500/5 border-b border-purple-500/10",children:[e.jsx(tt,{size:13,className:"text-purple-400"}),e.jsxs("span",{className:"text-sm text-purple-300 font-medium",children:["[AI] ",o.name]}),e.jsxs("span",{className:"text-sm text-gray-600 ml-auto",children:[o.requests.length," steps"]})]}),e.jsx("p",{className:"px-6 py-1 text-sm text-gray-600 border-b border-white/[2%]",children:o.description}),o.requests.map((N,T)=>e.jsxs("div",{className:"flex items-center gap-2 px-6 py-1 border-b border-white/[2%]",children:[e.jsxs("span",{className:"text-sm text-gray-600 w-4 text-right",children:[T+1,"."]}),e.jsx("span",{className:`text-sm font-bold px-1 py-0.5 rounded ${Oe[N.method]||"bg-gray-500/15 text-gray-400"}`,children:N.method}),e.jsx("span",{className:"text-sm text-gray-400 truncate",children:N.name||N.url})]},T))]},C)),(w==null?void 0:w.requests)&&w.requests.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-surface-2 border-b border-white/5",children:[e.jsx("span",{className:"text-sm text-gray-400 font-medium",children:"Root Requests"}),e.jsx("span",{className:"text-sm text-gray-600 ml-auto",children:w.requests.length})]}),w.requests.map(o=>e.jsxs("div",{className:"flex items-center gap-2 px-6 py-1 border-b border-white/[2%]",children:[e.jsx("span",{className:`text-sm font-bold px-1 py-0.5 rounded ${Oe[o.method]||"bg-gray-500/15 text-gray-400"}`,children:o.method}),e.jsx("span",{className:"text-sm text-gray-400 truncate",children:o.name||o.url})]},o.id))]})]})]}),s==="confirm"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-500 uppercase tracking-wider",children:"Collection Name"}),e.jsx("input",{value:K,onChange:o=>r(o.target.value),className:"w-full mt-1 px-3 py-2 text-sm bg-surface-2 border border-white/5 rounded-lg text-gray-200 focus:outline-none focus:border-brand-500/50"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-500 uppercase tracking-wider",children:"Base URL"}),e.jsx("input",{value:k,onChange:o=>v(o.target.value),placeholder:"https://api.example.com",className:`w-full mt-1 px-3 py-2 text-sm font-mono bg-surface-2 border rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50 ${k&&!k.startsWith("http")?"border-amber-500/40":"border-white/5"}`}),k&&!k.startsWith("http")&&e.jsxs("p",{className:"text-sm text-amber-400 mt-1",children:["Base URL appears to be a relative path. Add the full hostname (e.g., https://petstore.swagger.io",k,")"]})]}),e.jsxs("div",{className:"p-3 bg-surface-2 rounded-lg border border-white/5 space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-gray-500",children:"Endpoints"}),e.jsx("span",{className:"text-gray-300",children:ne})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-gray-500",children:"Folders"}),e.jsx("span",{className:"text-gray-300",children:w?w.folders.length+q.length:0})]}),q.length>0&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-gray-500",children:"AI Scenarios"}),e.jsx("span",{className:"text-purple-300",children:q.length})]})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-t border-white/5",children:[e.jsx("button",{onClick:()=>{s==="upload"?t():s==="endpoints"?n("upload"):s==="preview"?n("endpoints"):s==="confirm"&&n("preview")},className:"px-4 py-1.5 rounded-lg text-sm text-gray-400 hover:text-gray-200 transition-colors",children:s==="upload"?"Cancel":"Back"}),e.jsxs("button",{onClick:()=>{s==="upload"?fe():s==="endpoints"?te():s==="preview"?n("confirm"):s==="confirm"&&ke()},disabled:L||s==="upload"&&!d.trim()||s==="endpoints"&&ne===0,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-lg bg-brand-500 text-white text-sm font-medium hover:bg-brand-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[L&&e.jsx(Te,{size:14,className:"animate-spin"}),s==="upload"?"Parse":s==="endpoints"?S?"Generate & Preview":"Preview":s==="preview"?"Continue":"Import Collection"]})]})]})})}function Js(t){if(!t)return null;try{return localStorage.getItem(`testver-active-env-${t}`)}catch{return null}}function Qs(t,a){if(t)try{a?localStorage.setItem(`testver-active-env-${t}`,a):localStorage.removeItem(`testver-active-env-${t}`)}catch{}}function Gs(){return{id:`req-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,name:"New Request",method:"GET",url:"",headers:[],queryParams:[],body:{type:"none"},auth:{type:"none"},validations:[],followRedirects:!0,sortOrder:0}}function na(){var Ve;const{data:t}=ss(),a=(t==null?void 0:t.collections)||[],[s,n]=x.useState(null),{data:d}=as(s),[c]=jt(),m=x.useRef(null),b=c.get("collection"),i=c.get("folder"),p=c.get("request"),u=c.toString();x.useEffect(()=>{if(c.get("import")==="1"&&m.current!==u){m.current=u,re(!0);return}if(!b||!a.length)return;const j=(U,D)=>U.toLowerCase()===D.toLowerCase(),$=a.find(U=>U.id===b)??a.find(U=>j(U.name,b));$&&$.id!==s&&m.current!==u&&n($.id)},[u,a,b,s,c]),x.useEffect(()=>{if(!d||m.current===u||!b)return;const j=(D,J)=>D.toLowerCase()===J.toLowerCase();if(d.id!==b&&!j(d.name,b))return;if(m.current=u,!p){const D=i?d.folders.find(J=>J.id===i||j(J.name,i)):void 0;D&&Y(D.id);return}const $=D=>D.find(J=>J.id===p)??D.find(J=>j(J.name,p)||j(`${J.method} ${J.name}`,p));for(const D of d.folders){if(i&&D.id!==i&&!j(D.name,i))continue;const J=$(D.requests);if(J){Q(J,D.id);return}}const U=$(d.requests)??d.folders.map(D=>$(D.requests)).find(Boolean);if(U){const D=d.folders.find(J=>J.requests.some(Se=>Se.id===U.id));Q(U,D==null?void 0:D.id)}},[d,u]);const[l,w]=x.useState(Gs),[f,S]=x.useState(null),[z,H]=x.useState(null),[F,q]=x.useState({}),[y,P]=x.useState(null),[M,K]=x.useState(!1),[r,k]=x.useState(!1),[v,L]=x.useState(null),[A,Y]=x.useState(null),[O,re]=x.useState(!1),[me,ue]=x.useState(!1),Ne=x.useRef(null),[be,Z]=x.useState(!1),ce=x.useRef(null),[fe,ne]=x.useState(280),[ee,B]=x.useState(50),[X,te]=x.useState(!1),[le,ke]=x.useState(!1),ye=x.useRef(null),{toast:se}=Ke(),o=ae(),C=is(),N=xs();x.useEffect(()=>{if(!s){P(null);return}const j=Js(s);j&&(d!=null&&d.environments.some($=>$.id===j))?P(j):P(null)},[s,d==null?void 0:d.environments]);const T=x.useCallback(j=>{P(j),Qs(s,j)},[s]);x.useEffect(()=>{const j=$=>{ce.current&&!ce.current.contains($.target)&&Z(!1)};return be&&document.addEventListener("mousedown",j),()=>document.removeEventListener("mousedown",j)},[be]),x.useEffect(()=>{const j=$=>{Ne.current&&!Ne.current.contains($.target)&&ue(!1)};return me&&document.addEventListener("mousedown",j),()=>document.removeEventListener("mousedown",j)},[me]);const I=x.useCallback(j=>{j.preventDefault(),te(!0);const $=j.clientX,U=fe,D=Se=>{const De=Math.max(180,Math.min(450,U+Se.clientX-$));ne(De)},J=()=>{te(!1),document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",J)};document.addEventListener("mousemove",D),document.addEventListener("mouseup",J)},[fe]),G=x.useCallback(j=>{var De;j.preventDefault();const $=j.clientY,U=ee,D=((De=ye.current)==null?void 0:De.offsetHeight)||600,J=ft=>{const yt=(ft.clientY-$)/D*100;B(Math.max(20,Math.min(80,U+yt)))},Se=()=>{document.removeEventListener("mousemove",J),document.removeEventListener("mouseup",Se)};document.addEventListener("mousemove",J),document.addEventListener("mouseup",Se)},[ee]),_=x.useMemo(()=>{if(!d)return{};const j={};if(d.baseUrl&&(j.baseUrl=d.baseUrl),y){const $=d.environments.find(U=>U.id===y);if($)for(const U of $.variables)U.enabled&&U.key&&(j[U.key]=U.value)}return j},[d,y]),W=x.useCallback(()=>_,[_]),Q=(j,$)=>{w(j),S(j.id),Y($||null),H(null)},h=()=>{s&&C.mutate({collectionId:s,request:l,folderId:A||void 0})},R=async()=>{if(!l.url){se("error","Please enter a URL");return}const j=W();N.mutate({request:l,variables:j,collectionId:s||void 0,environmentId:y||void 0},{onSuccess:$=>{const{extractedVars:U,...D}=$;H(D),q(U||{}),s&&C.mutate({collectionId:s,request:l,folderId:A||void 0})},onError:$=>{se("error",`Request failed: ${$}`)}})},[V,g]=x.useState(!1),de=j=>{w($=>({...$,validations:[...$.validations,j]})),se("success","Validation added")},E=(j,$)=>{const U=`set("${j}", jsonpath(response.body, "${$}"))`;w(D=>({...D,postResponseScript:D.postResponseScript?`${D.postResponseScript}
19
+ ${U}`:U})),se("success",`Variable "${j}" extraction added to post-response script`)},Ce=async j=>{if(s)try{(d==null?void 0:d.environments.some(U=>U.id===j.id))?await Bt(s,j.id,j):await _t(s,j),o.invalidateQueries({queryKey:["api-collection",s]}),se("success","Environment saved")}catch($){se("error",String($))}},Re=async j=>{if(s)try{await Ht(s,j),y===j&&T(null),o.invalidateQueries({queryKey:["api-collection",s]})}catch($){se("error",String($))}};return e.jsxs("div",{className:"h-full flex flex-col animate-fade-in",children:[e.jsxs("div",{className:"px-6 py-2 border-b border-white/5 bg-surface-1 flex flex-wrap items-center gap-3 flex-shrink-0","data-testid":"api-workspace-bar",children:[e.jsxs(vt,{to:"/ai",className:"inline-flex items-center gap-1.5 rounded-lg border border-white/10 px-3 py-1.5 text-sm font-medium text-gray-200 hover:bg-white/5",children:[e.jsx(Xt,{size:14})," Back to AI Assistant"]}),e.jsxs("nav",{"aria-label":"Breadcrumb",className:"text-[13px] text-gray-500",children:["AI Assistant ",e.jsx("span",{"aria-hidden":!0,children:"›"})," API mode ",e.jsx("span",{"aria-hidden":!0,children:"›"})," ",e.jsx("span",{className:"font-semibold text-gray-200",children:"API workspace"})]}),e.jsxs("span",{className:"ml-auto text-[12.5px] text-gray-500",children:["The same collections API mode uses · ",e.jsx("span",{className:"font-mono",children:".testver/api-collections.json"})]})]}),e.jsx("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",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>ke(!le),className:"p-1.5 rounded-lg text-gray-500 hover:text-gray-300 hover:bg-white/5 transition-colors",title:le?"Show sidebar":"Hide sidebar",children:le?e.jsx(Zt,{size:18}):e.jsx(es,{size:18})}),e.jsx(dt,{size:22,className:"text-brand-400"}),e.jsx("h1",{className:"text-2xl font-bold text-gray-100",children:"API workspace"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>re(!0),className:"flex items-center gap-1.5 px-3.5 py-1.5 rounded-xl text-sm bg-blue-500/15 text-blue-300 hover:bg-blue-500/25 transition-colors",children:[e.jsx($e,{size:14})," Import"]}),e.jsxs("div",{className:"relative",ref:Ne,children:[e.jsxs("button",{onClick:()=>ue(!me),className:"flex items-center gap-1.5 px-3.5 py-1.5 rounded-xl text-sm bg-cyan-500/15 text-cyan-300 hover:bg-cyan-500/25 transition-colors",children:[e.jsx(st,{size:14})," Export ",e.jsx(oe,{size:12,className:`transition-transform ${me?"rotate-180":""}`})]}),me&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-56 bg-surface-1 border border-white/10 rounded-lg z-50 py-1",style:{animation:"slideInRight 0.15s ease-out"},children:[s&&d&&e.jsxs("button",{onClick:async()=>{ue(!1);try{await Vt(s,d.name)}catch{}},className:"w-full flex items-center gap-2.5 px-3 py-2 text-sm text-gray-300 hover:bg-white/5 transition-colors text-left",children:[e.jsx(Fe,{size:14,className:"text-cyan-400"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:"Export Collection"}),e.jsx("div",{className:"text-sm text-gray-500",children:d.name})]})]}),e.jsxs("button",{onClick:async()=>{ue(!1);try{await Ut()}catch{}},className:"w-full flex items-center gap-2.5 px-3 py-2 text-sm text-gray-300 hover:bg-white/5 transition-colors text-left",children:[e.jsx(st,{size:14,className:"text-brand-400"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:"Export All Collections"}),e.jsx("div",{className:"text-sm text-gray-500",children:"Backup everything"})]})]})]})]}),s&&d&&e.jsxs("div",{className:"relative",ref:ce,children:[e.jsxs("button",{onClick:()=>Z(j=>!j),className:`flex items-center gap-1.5 px-3.5 py-1.5 rounded-xl text-sm transition-colors ${y?"bg-emerald-500/15 text-emerald-400 hover:bg-emerald-500/25":"bg-surface-2 text-gray-400 hover:bg-surface-3 hover:text-gray-300"}`,children:[e.jsx(ze,{size:14}),y?((Ve=d.environments.find(j=>j.id===y))==null?void 0:Ve.name)||"Environment":"No Environment",e.jsx(oe,{size:13,className:`transition-transform ${be?"rotate-180":""}`})]}),be&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-64 bg-surface-1 border border-white/10 rounded-lg z-50 py-1 animate-fade-in",children:[e.jsxs("button",{onClick:()=>{T(null),Z(!1)},className:`w-full flex items-center gap-2 px-3 py-1.5 text-sm hover:bg-white/5 transition-colors ${y?"text-gray-500":"text-gray-200"}`,children:[e.jsx("span",{className:"w-3.5 flex items-center justify-center",children:!y&&e.jsx(we,{size:13,className:"text-emerald-400"})}),e.jsx(ve,{size:13,className:"text-gray-600"}),"No Environment"]}),d.environments.length>0&&e.jsx("div",{className:"border-t border-white/5 my-1"}),d.environments.map(j=>e.jsxs("button",{onClick:()=>{T(j.id),Z(!1)},className:`w-full flex items-center gap-2 px-3 py-1.5 text-sm hover:bg-white/5 transition-colors ${y===j.id?"text-emerald-400":"text-gray-300"}`,children:[e.jsx("span",{className:"w-3.5 flex items-center justify-center",children:y===j.id&&e.jsx(we,{size:13,className:"text-emerald-400"})}),e.jsx(ze,{size:13,className:y===j.id?"text-emerald-400":"text-gray-600"}),e.jsx("span",{className:"truncate",children:j.name}),e.jsxs("span",{className:"ml-auto text-sm text-gray-600",children:[j.variables.filter($=>$.enabled).length," vars"]})]},j.id)),e.jsx("div",{className:"border-t border-white/5 mt-1 pt-1",children:e.jsxs("button",{onClick:()=>{K(!0),Z(!1)},className:"w-full flex items-center gap-2 px-3 py-1.5 text-sm text-gray-400 hover:text-gray-200 hover:bg-white/5 transition-colors",children:[e.jsx("span",{className:"w-3.5"}),e.jsx(ts,{size:13}),"Manage Environments..."]})})]})]}),e.jsxs("button",{onClick:()=>k(!r),className:`flex items-center gap-1.5 px-3.5 py-1.5 rounded-xl text-sm transition-colors ${r?"bg-brand-500/15 text-brand-300":"bg-surface-2 text-gray-400 hover:bg-surface-3 hover:text-gray-300"}`,children:[e.jsx(Le,{size:14})," History"]})]})]})}),e.jsxs("div",{className:"flex-1 flex overflow-hidden relative",children:[e.jsx("div",{className:`flex-shrink-0 overflow-hidden bg-surface-1 border-r border-white/5 transition-all duration-200 ${le?"w-0":""}`,style:le?{width:0}:{width:`${fe}px`},children:e.jsx(hs,{collections:a,selectedCollection:d||null,selectedRequestId:f,onSelectCollection:n,onSelectRequest:Q,onImport:()=>re(!0),onRunChain:j=>L(j)})}),!le&&e.jsx("div",{className:`w-1 cursor-col-resize hover:bg-brand-500/30 transition-colors flex-shrink-0 ${X?"bg-brand-500/40":""}`,onMouseDown:I}),e.jsxs("div",{ref:ye,className:"flex-1 flex flex-col overflow-hidden bg-white dark:bg-surface-0",children:[e.jsx("div",{className:"overflow-hidden flex flex-col",style:{height:`${ee}%`},children:e.jsx($s,{request:l,onChange:w,onSend:R,onSave:h,onQuickValidate:z?()=>g(!0):void 0,sending:N.isPending,validationResults:z==null?void 0:z.validationResults,variables:_})}),e.jsx("div",{className:"h-1.5 cursor-row-resize hover:bg-brand-500/30 bg-white/[0.02] transition-colors flex-shrink-0 flex items-center justify-center group",onMouseDown:G,children:e.jsx("div",{className:"w-10 h-0.5 rounded-full bg-white/10 group-hover:bg-brand-500/50 transition-colors"})}),e.jsx("div",{className:"overflow-hidden flex flex-col",style:{height:`${100-ee}%`},children:e.jsx(As,{response:z,loading:N.isPending,onAddValidation:de,onExtractVariable:E,variables:_,request:l,extractedVars:F})})]}),r&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute inset-0 bg-[rgba(0,0,0,0.3)] z-40",onClick:()=>k(!1)}),e.jsx("div",{className:"absolute right-0 top-0 bottom-0 w-[400px] bg-surface-1 border-l border-white/10 z-50 shadow-2xl",style:{animation:"slideInRight 0.2s ease-out"},children:e.jsx(Fs,{onSelectRequest:j=>{Q(j),k(!1)},onClose:()=>k(!1)})})]})]}),M&&d&&e.jsx(Os,{environments:d.environments,activeEnvId:y,onSelectEnv:T,onSave:Ce,onDelete:Re,onClose:()=>K(!1)}),v&&e.jsx(Vs,{folder:v,variables:W(),onClose:()=>L(null)}),V&&z&&e.jsx(Bs,{responseBody:z.body,onAddValidation:j=>{de(j)},onClose:()=>g(!1)}),O&&e.jsx(Ks,{onClose:()=>re(!1),existingCollections:a.map(j=>({name:j.name,requestCount:j.requestCount}))})]})}export{na as APITestingPage};
@@ -0,0 +1 @@
1
+ import{r as k,j as e,L as je,b as ke,u as we}from"./vendor-react-DOVfxdUy.js";import{a as Ne,u as Ce}from"./vendor-query-DkZSMtfn.js";import{e2 as ge,iM as Te,b as ze,iN as Ae,dV as Se,iO as Ie,iP as Be,iQ as Le,iR as $e,eu as Me}from"./index-BlA8ntjb.js";import{u as Pe,b as se}from"./TestverCreditsRing-CoDk5eAS.js";import{t as De,T as Re}from"./TestverCreditsDetail-BKpt4oLW.js";import{C as Ee}from"./ConfirmDialog-D_N9188T.js";import{a1 as T,p as re,Z as ue,cT as W,s as _e,R as Ge,D as Fe,S as H,a0 as pe,ba as qe,bD as Oe,ad as ye,am as Ye,$ as z,P as We,m as He,I as Ue,dq as ae,O as ne,V as ie,ds as Qe,Y as oe,K as Ke,bE as Ze,bQ as Ve,d as Je,bA as le,G as Xe,b as ce,e as de,a8 as et,dt as tt,du as xe,g as st,cu as rt,Q as at,dv as nt,j as it,bx as ot,_ as lt,dw as ct}from"./vendor-icons-Cm92aSc5.js";import"./formatDate-T65-Y6Mi.js";function dt(t){if(!t)return"";const a=Math.max(0,Math.round((Date.now()-Date.parse(t))/6e4));return a<1?"just now":a<60?`${a} min ago`:`${Math.floor(a/60)} h ago`}function me(t){return t?new Date(t).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"}):""}function o({tone:t,children:a}){const r={ok:"bg-emerald-50 text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-400",off:"bg-gray-100 text-gray-600 dark:bg-white/5 dark:text-gray-400",sys:"bg-amber-50 text-amber-700 dark:bg-amber-500/10 dark:text-amber-300",team:"bg-violet-50 text-violet-700 dark:bg-violet-500/15 dark:text-violet-300",info:"bg-sky-50 text-sky-700 dark:bg-sky-500/10 dark:text-sky-300",warn:"bg-amber-50 text-amber-700 dark:bg-amber-500/10 dark:text-amber-300"}[t];return e.jsx("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-[11px] font-semibold whitespace-nowrap ${r}`,children:a})}function P({on:t,disabled:a,busy:r,onChange:i,label:n}){return e.jsxs("button",{type:"button",role:"switch","aria-checked":t,"aria-label":n,disabled:a||r,onClick:()=>i(!t),className:`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors ${t?"bg-sky-500":"bg-gray-300 dark:bg-zinc-600"} ${a?"opacity-40 cursor-not-allowed":""}`,children:[e.jsx("span",{className:`inline-block h-4 w-4 rounded-full bg-white shadow transition-transform ${t?"translate-x-[18px]":"translate-x-0.5"}`}),r&&e.jsx(T,{size:10,className:"absolute -right-4 animate-spin text-gray-500 dark:text-gray-400"})]})}function D({tone:t,children:a}){const r={sky:"border-sky-200 bg-sky-50 text-sky-600 dark:border-sky-400/30 dark:bg-sky-500/10 dark:text-sky-300",violet:"border-violet-200 bg-violet-50 text-violet-600 dark:border-violet-400/30 dark:bg-violet-500/10 dark:text-violet-300",emerald:"border-emerald-200 bg-emerald-50 text-emerald-600 dark:border-emerald-400/30 dark:bg-emerald-500/10 dark:text-emerald-300"}[t];return e.jsx("span",{className:`inline-flex h-10 w-10 items-center justify-center rounded-xl border ${r}`,children:a})}function R({children:t,dashed:a,dim:r,footer:i}){return e.jsxs("div",{className:`flex flex-col rounded-2xl border ${a?"border-dashed":""} border-black/[0.06] dark:border-white/5 bg-surface-1 p-6 ${r?"opacity-60":""}`,children:[t,i&&e.jsx("div",{className:"mt-auto flex justify-end pt-4 text-sm",children:i})]})}const he="text-sky-600 dark:text-sky-300 hover:text-sky-700 dark:hover:text-sky-200 font-medium inline-flex items-center gap-1 whitespace-nowrap";function B({to:t,href:a,children:r}){return t?e.jsxs(je,{to:t,className:he,children:[r," ",e.jsx(Ye,{size:12})]}):e.jsxs("a",{href:a,target:"_blank",rel:"noopener noreferrer",className:he,children:[r," ",e.jsx(z,{size:12})]})}const L=({k:t,v:a,tone:r})=>e.jsxs("div",{className:"flex justify-between gap-3 text-sm",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:t}),e.jsx("span",{className:r??"text-gray-800 dark:text-gray-200",children:a})]});function xt(t){const[a,r]=k.useState("idle"),[i,n]=k.useState(null),l=k.useRef(null);return k.useEffect(()=>()=>{l.current&&window.clearInterval(l.current)},[]),{state:a,error:i,start:async()=>{n(null),r("waiting");const f=window.open("about:blank","_blank");try{const m=await Be();if(!f){n("Your browser blocked the popup — allow popups for this site and retry."),r("error");return}f.location.href=m.approveUrl;const p=Math.max(1500,Number(m.pollIntervalMs)||2500),j=Date.now()+5*6e4;l.current=window.setInterval(async()=>{if(Date.now()>j){l.current&&window.clearInterval(l.current),r("error"),n("The connection request expired — click Connect to try again.");return}try{const w=await Le(m.code);w.status==="connected"?(l.current&&window.clearInterval(l.current),r("idle"),t()):(w.status==="denied"||w.status==="expired"||w.status==="invalid")&&(l.current&&window.clearInterval(l.current),r("error"),n(w.status==="denied"?"The request was denied on testver.com.":"The connection request expired — click Connect to try again."))}catch{}},p)}catch(m){f==null||f.close(),r("error"),n(m instanceof Error?m.message:"Could not start the connection")}},cancel:()=>{l.current&&window.clearInterval(l.current),r("idle")}}}function mt(){var Z,V,J,X,ee,te;const{data:t,isLoading:a,refetch:r,isFetching:i}=ge(),n=Te(),l=Ne(),v=!!(t!=null&&t.connected),{data:h,isError:f}=Pe({enabled:v});k.useEffect(()=>{v&&se(l)},[v,l]);const{toast:m}=ze(),[p,j]=k.useState(null),[w,E]=k.useState(!1),[S,$]=k.useState(null),I=xt(()=>{n(),r(),m("success","Connected to Testver — services are being set up.")}),U=async(x,M)=>{j(x),$(null);try{const F=(await Ae(x,M)).result;x==="grid"&&M&&F&&!F.connected&&$(F),n(),await r()}catch(G){m("error",G instanceof Error?G.message:"Could not update the service")}finally{j(null)}},Q=async()=>{j("takeover");try{await Se({takeover:!0}),$(null),n(),await r(),m("success","Testver Grid is now connected on this device.")}catch(x){m("error",x instanceof Error?x.message:"Take-over failed")}finally{j(null)}},be=async()=>{j("disconnect");try{await Ie(),n(),await r(),m("success","Disconnected from Testver.")}catch(x){m("error",x instanceof Error?x.message:"Disconnect failed")}finally{j(null)}};if(a||!t)return e.jsxs("div",{className:"max-w-[1100px] mx-auto px-6 py-16 text-sm text-gray-500 dark:text-gray-400 flex items-center gap-2",children:[e.jsx(T,{size:14,className:"animate-spin"})," Loading your Testver connections…"]});const{services:s,isSystem:u,memberOnly:c}=t,ve=!u&&(s.grid.providedBy==="system"||s.mail.providedBy==="system"),y=t.own.account,d=t.own.subject,fe=s.ai.entitled&&s.ai.credits?{connected:!0,active:s.ai.active,plan:s.ai.plan??null,paidThrough:s.ai.paidThrough,totalCredits:s.ai.credits.total,usedCredits:s.ai.credits.used,remainingCredits:s.ai.credits.remaining,cycleUsedCredits:s.ai.credits.cycleUsed,cycleAllowanceCredits:s.ai.credits.cycleAllowance}:null,N=h!=null&&h.connected&&(h.totalCredits??0)>0?h:f||h&&!h.connected?fe:null,K=t.connected&&!h&&!f,_=t.connected&&!K&&!N&&((h==null?void 0:h.active)===!1||!s.ai.entitled),b=N?De(N):null;return e.jsxs("div",{className:"max-w-[1100px] mx-auto px-6 py-10 space-y-5",children:[!t.connected&&e.jsxs("div",{className:"rounded-2xl border border-sky-200 dark:border-sky-500/20 bg-sky-50 dark:bg-sky-500/5 p-6",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:u?"Connect this Testver to your account":"Connect your Testver account"}),e.jsxs("p",{className:"mt-2 text-base text-gray-500 dark:text-gray-400 leading-relaxed",children:["One click on testver.com. Everything your plan includes and every add-on you hold switches on automatically — AI credits, Testver mail and Grid browsers — and you can turn any of them off here later. Your custom SMTP or vendor grids keep working as they are.",u&&" This becomes the system connection: schedules, CI gates and healing use it too."]}),t.own.invalid&&e.jsxs("p",{className:"mt-2 text-sm text-amber-300 flex items-center gap-1.5",children:[e.jsx(re,{size:14})," Your previous connection was rejected — connect again."]})]}),I.state==="waiting"?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300",children:[e.jsx(T,{size:16,className:"animate-spin text-sky-400"}),"Approve in the tab we opened… waiting.",e.jsx("button",{onClick:I.cancel,className:"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:text-gray-300 underline underline-offset-2",children:"Cancel"})]}):e.jsxs("button",{onClick:()=>void I.start(),className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-lg text-sm font-semibold text-white bg-gradient-to-r from-sky-500 to-indigo-500 hover:from-sky-400 hover:to-indigo-400 transition-colors",children:[e.jsx(ue,{size:15})," Connect to Testver"]})]}),I.error&&e.jsx("p",{className:"mt-3 text-xs text-red-400",children:I.error}),e.jsx("ol",{className:"mt-5 grid gap-3 sm:grid-cols-3 text-[13px] text-gray-700 dark:text-gray-300",children:["A testver.com tab opens — sign in if you are not already.","Approve the connection for this installation.","Come back here — the services below light up on their own."].map((x,M)=>e.jsxs("li",{className:"flex items-start gap-2.5",children:[e.jsx("span",{className:"mt-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-sky-500/15 text-[11px] font-bold text-sky-300",children:M+1}),e.jsx("span",{children:x})]},x))})]}),ve&&e.jsxs("div",{className:"flex items-start gap-2.5 rounded-xl border border-amber-200 dark:border-amber-500/25 bg-amber-50 dark:bg-amber-500/[0.07] px-4 py-3 text-sm text-amber-800 dark:text-amber-200",children:[e.jsx(W,{size:15,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:["This is a shared Testver server. The super admin's ",e.jsx("span",{className:"font-semibold",children:"system connection"})," provides"," ",[s.grid.providedBy==="system"&&"Testver Grid",s.mail.providedBy==="system"&&"Testver Mail"].filter(Boolean).join(" and ")," to everyone here — you cannot change ",s.grid.providedBy==="system"&&s.mail.providedBy==="system"?"them":"it",". Your AI credits come from your own account."]})]}),t.connected&&y&&d&&e.jsxs("div",{className:"rounded-2xl border border-sky-200 dark:border-sky-500/20 bg-sky-50 dark:bg-sky-500/5 p-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3.5",children:[e.jsx("span",{className:"inline-flex h-10 w-10 items-center justify-center rounded-full bg-gradient-to-br from-sky-500 to-indigo-500 text-sm font-bold text-white",children:(y.name??y.email??"?").split(/\s+/).map(x=>x[0]).join("").slice(0,2).toUpperCase()}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:["Connected as ",y.name??y.email]}),e.jsxs(o,{tone:"ok",children:[e.jsx(_e,{size:11})," ",u?"System connection":"Your account"]}),d.type==="team"&&e.jsxs(o,{tone:"team",children:[d.name??"Team"," · ",d.role]})]}),e.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400 mt-0.5",children:[y.email,y.plan?` · ${y.plan.name} plan${y.paidThrough?`, paid through ${me(y.paidThrough)}`:""}`:" · no plan",d.type==="team"&&((Z=d.owner)!=null&&Z.email)&&d.role!=="owner"?` · owner: ${d.owner.name??d.owner.email}`:"",d.type==="user"?" · individual":""]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>{r(),se(l)},disabled:i,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-gray-800 dark:text-gray-200 bg-surface-2 border border-black/10 dark:border-white/10 hover:bg-surface-3 disabled:opacity-50",children:[e.jsx(Ge,{size:12,className:i?"animate-spin":""})," Check all services"]}),e.jsxs("button",{onClick:()=>E(!0),disabled:p!==null,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-red-300 bg-red-500/10 border border-red-500/20 hover:bg-red-500/20 disabled:opacity-50",children:[p==="disconnect"?e.jsx(T,{size:12,className:"animate-spin"}):e.jsx(Fe,{size:12})," Disconnect"]})]})]}),e.jsx("p",{className:"mt-3 text-sm text-gray-500 dark:text-gray-400 leading-relaxed",children:c?"As a team member you get the team's AI credits here. Grid, Cloud and Mail are set up once for the whole team by the owner or the platform manager, on their own Testver installation.":u?"Everything your plan includes is connected below. Switch a service off here at any time; automation (schedules, CI gates, healing) uses this connection too.":"Everything your plan includes is connected below for your own account. Switch a service off here at any time."})]}),e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsxs(R,{dim:!t.connected,footer:t.connected&&N?e.jsx(B,{to:"/settings?tab=llm",children:"AI settings"}):_?e.jsx(B,{href:"https://testver.com/pricing",children:"See plans"}):null,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(D,{tone:"sky",children:e.jsx(H,{size:15})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[15px] font-semibold text-gray-900 dark:text-gray-100",children:"Testver AI"}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:t.connected?(d==null?void 0:d.type)==="team"?"Team credits · your share":"Your account · frontier models, managed":"Frontier models, managed — no API keys"})]})]}),t.connected?b!=null&&b.suspended?e.jsx(o,{tone:"warn",children:"Suspended"}):b!=null&&b.seatPaused?e.jsx(o,{tone:"warn",children:"Seat paused"}):b!=null&&b.planExpired?e.jsx(o,{tone:"warn",children:"Plan expired"}):N||s.ai.entitled&&!_?e.jsx(o,{tone:"ok",children:"Active"}):e.jsx(o,{tone:"off",children:"No plan"}):e.jsx(o,{tone:"off",children:"Connects automatically"})]}),K&&e.jsxs("p",{className:"mt-3.5 text-sm text-gray-500 dark:text-gray-400 flex items-center gap-2",children:[e.jsx(T,{size:13,className:"animate-spin"})," Loading credits…"]}),t.connected&&N&&e.jsx(Re,{data:N,formatDay:me,className:"mt-3.5"}),_&&e.jsx("p",{className:"mt-3 text-sm text-gray-500 dark:text-gray-400",children:"No Testver plan on this account."}),!t.connected&&e.jsx("p",{className:"mt-3 text-sm text-gray-500 dark:text-gray-400",children:"Your plan's credits power every AI feature the moment you connect."})]}),e.jsxs(R,{dim:!t.connected,dashed:c,footer:t.connected&&!c&&(s.grid.on||s.grid.providedBy)&&e.jsx(B,{to:"/settings?tab=connectors",children:"Grid settings"}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(D,{tone:"violet",children:e.jsx(pe,{size:15})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[15px] font-semibold text-gray-900 dark:text-gray-100",children:"Testver Grid"}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:s.grid.entitled||s.grid.providedBy?`Cloud browsers · ${s.grid.limit} at once${(d==null?void 0:d.type)==="team"||s.grid.providedBy==="system"?", one pool":""}`:"Chromium, Firefox and WebKit in the cloud"})]})]}),t.connected?c?e.jsx(o,{tone:"team",children:"Managed by your team owner"}):s.grid.providedBy==="system"&&!u?e.jsx(P,{on:!0,disabled:!0,label:"Testver Grid (system)",onChange:()=>{}}):s.grid.entitled?e.jsx(P,{on:s.grid.on,busy:p==="grid",disabled:!s.grid.manageable,label:"Testver Grid",onChange:x=>void U("grid",x)}):e.jsx(o,{tone:"off",children:"Not in your plan"}):e.jsx(o,{tone:"off",children:"Add-on"})]}),t.connected&&s.grid.providedBy==="system"&&!u&&e.jsx("div",{className:"mt-3",children:e.jsx(o,{tone:"sys",children:"Provided by the system connection"})}),t.connected&&(s.grid.on||s.grid.providedBy)&&!c&&e.jsxs("div",{className:"mt-3.5 space-y-1.5",children:[e.jsx(L,{k:"Connection",v:s.grid.thisDevice?`This device · ${t.installation.deviceName}`:s.grid.connection?`${s.grid.connection.deviceName??"another device"} · ${dt(s.grid.connection.lastSeenAt)}`:"Not connected yet",tone:s.grid.thisDevice?"text-emerald-400":s.grid.connection?"text-amber-300":"text-gray-700 dark:text-gray-300"}),s.grid.providedBy==="system"&&!u&&e.jsx(L,{k:"Managed by",v:`super admin${(J=(V=t.system)==null?void 0:V.account)!=null&&J.email?` · ${t.system.account.email}`:""}`})]}),t.connected&&c&&e.jsxs("div",{className:"mt-3 text-sm text-gray-500 dark:text-gray-400 leading-relaxed",children:[s.grid.connection?e.jsxs("span",{className:"flex items-center gap-1.5 text-gray-700 dark:text-gray-300",children:[e.jsx(qe,{size:12})," ",((X=d==null?void 0:d.owner)==null?void 0:X.name)??"The owner"," holds the team's connection on ",s.grid.connection.deviceName??"their device","."]}):null,e.jsx("span",{className:"block mt-1",children:"Only the owner or the platform manager can connect or move it. Runs started from that installation use the team pool."})]}),S&&e.jsxs("div",{className:"mt-3 rounded-xl border border-amber-200 dark:border-amber-500/25 bg-amber-50 dark:bg-amber-500/[0.07] px-3 py-2.5 text-sm text-amber-800 dark:text-amber-200 space-y-2",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(re,{size:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:S.message})]}),S.code==="GRID_IN_USE"&&((ee=S.holder)==null?void 0:ee.canTakeOver)!==!1&&e.jsxs("div",{className:"flex gap-2 pl-5",children:[e.jsx("button",{onClick:()=>void Q(),disabled:p!==null,className:"px-2.5 py-1 rounded-md bg-amber-600 hover:bg-amber-500 text-white text-[11px] font-medium disabled:opacity-50",children:p==="takeover"?e.jsx(T,{size:11,className:"animate-spin"}):"Take over on this device"}),e.jsx("button",{onClick:()=>$(null),className:"px-2.5 py-1 rounded-md text-[11px] text-amber-200 hover:bg-amber-500/20",children:"Not now"})]})]}),t.connected&&!S&&s.grid.on&&s.grid.manageable&&s.grid.connection&&!s.grid.thisDevice&&!c&&e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("button",{onClick:()=>void Q(),disabled:p!==null,className:"px-2.5 py-1 rounded-md bg-amber-600 hover:bg-amber-500 text-white text-[11px] font-medium disabled:opacity-50",children:p==="takeover"?e.jsx(T,{size:11,className:"animate-spin"}):"Take over on this device"}),e.jsx("span",{className:"text-[11px] text-gray-500 dark:text-gray-400",children:"allowed once that device has been idle for a few minutes"})]}),t.connected&&!s.grid.entitled&&!s.grid.providedBy&&!c&&s.grid.reason&&e.jsx("p",{className:"mt-3 text-sm text-gray-500 dark:text-gray-400",children:s.grid.reason.message}),!t.connected&&e.jsx("p",{className:"mt-3 text-sm text-gray-500 dark:text-gray-400",children:"A prepaid add-on to a paid plan: buy parallel browsers on testver.com. Connects here unless another installation already holds your connection — then you choose whether to take it over."}),t.connected&&!c&&(s.grid.on||s.grid.providedBy)&&e.jsx("p",{className:"mt-4 text-sm text-gray-500 dark:text-gray-400",children:"Only one installation holds the connection at a time."})]}),e.jsxs(R,{dim:!t.connected,dashed:c,footer:t.connected&&!c&&(s.mail.on||s.mail.providedBy)&&e.jsx(B,{to:"/settings?tab=connectors",children:"Manage connectors"}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(D,{tone:"emerald",children:e.jsx(Oe,{size:15})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[15px] font-semibold text-gray-900 dark:text-gray-100",children:"Testver Mail"}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Reports & notifications through Testver's mail server · no SMTP setup"})]})]}),t.connected?c?e.jsx(o,{tone:"team",children:"Managed by your team owner"}):s.mail.providedBy==="system"&&!u?e.jsx(P,{on:!0,disabled:!0,label:"Testver Mail (system)",onChange:()=>{}}):s.mail.entitled?e.jsx(P,{on:s.mail.on,busy:p==="mail",disabled:!s.mail.manageable,label:"Testver Mail",onChange:x=>void U("mail",x)}):e.jsx(o,{tone:"off",children:"Not in your plan"}):e.jsx(o,{tone:"off",children:"Connects automatically"})]}),t.connected&&s.mail.providedBy==="system"&&!u&&e.jsx("div",{className:"mt-3",children:e.jsx(o,{tone:"sys",children:"Provided by the system connection"})}),t.connected&&(s.mail.on||s.mail.providedBy)&&!c&&e.jsxs("div",{className:"mt-3.5 space-y-1.5",children:[e.jsx(L,{k:"Sends as",v:e.jsx("span",{className:"font-mono text-[12px]",children:s.mail.from??s.mail.fromAddress})}),e.jsx(L,{k:"Replies go to",v:e.jsx("span",{className:"font-mono text-[12px]",children:s.mail.replyTo??"—"})})]}),t.connected&&c&&e.jsxs("p",{className:"mt-3 text-sm text-gray-500 dark:text-gray-400 leading-relaxed",children:["Enabled on the team's Testver installation and sends as ",e.jsx("span",{className:"font-mono",children:s.mail.fromAddress??"tool@testver.com"}),". Your own SMTP connectors keep working here."]}),t.connected&&!s.mail.entitled&&!s.mail.providedBy&&!c&&s.mail.reason&&e.jsx("p",{className:"mt-3 text-sm text-gray-500 dark:text-gray-400",children:s.mail.reason.message}),!t.connected&&e.jsx("p",{className:"mt-3 text-sm text-gray-500 dark:text-gray-400",children:"Included with paid plans. Becomes the default sender; no SMTP host, port or password to enter."}),t.connected&&!c&&(s.mail.on||s.mail.providedBy)&&e.jsx("div",{className:"mt-4 text-sm",children:s.mail.connectorConnected?e.jsxs(o,{tone:"info",children:[e.jsx(ye,{size:11})," Default sender for notifications & reports"]}):e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Connector is off"})})]}),e.jsxs(R,{dim:!t.connected,dashed:c,footer:e.jsx(B,{href:((te=s.cloud.workspace)==null?void 0:te.url)??(s.cloud.entitled?"https://testver.com/dashboard/cloud":"https://testver.com/pricing"),children:s.cloud.workspace?"Open workspace":s.cloud.entitled?"Manage on testver.com":"See plans"}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(D,{tone:"sky",children:e.jsx(W,{size:15})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[15px] font-semibold text-gray-900 dark:text-gray-100",children:"Testver Cloud"}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Your always-on Testver · managed on testver.com"})]})]}),t.connected?c?e.jsx(o,{tone:"team",children:"Managed by your team owner"}):s.cloud.workspace?e.jsx(o,{tone:s.cloud.workspace.status==="active"?"ok":"warn",children:s.cloud.workspace.status==="active"?"Healthy":s.cloud.workspace.status}):s.cloud.entitled?e.jsx(o,{tone:"info",children:"Not created yet"}):e.jsx(o,{tone:"off",children:"Not in your plan"}):e.jsx(o,{tone:"off",children:"Shown after connecting"})]}),t.connected&&s.cloud.workspace&&e.jsx("div",{className:"mt-3.5 space-y-1.5",children:e.jsx(L,{k:"Workspace",v:e.jsxs("span",{className:"font-mono text-[12px]",children:[s.cloud.workspace.subdomain,".cloud.testver.com"]})})}),e.jsx("p",{className:"mt-4 text-sm text-gray-500 dark:text-gray-400",children:t.connected?c?"Sign in there with the workspace login.":s.cloud.workspace?"Restart, repository and backups live in your dashboard.":s.cloud.entitled?"Create it from your dashboard in about a minute.":"Testver Cloud is a prepaid add-on to a paid plan — add it from Billing → Add-ons on testver.com.":"A prepaid add-on to your plan, bought on testver.com. This page shows your workspace's health and links to the dashboard."})]})]}),e.jsx(Ee,{open:w,title:"Disconnect from Testver?",description:u?"AI requests, Testver Grid and Testver mail will stop for everyone on this server until you reconnect. The connection is revoked on testver.com too.":"AI requests on your account will stop here until you reconnect, and your connection is revoked on testver.com.",confirmLabel:"Disconnect",onConfirm:()=>{E(!1),be()},onCancel:()=>E(!1)})]})}function ht({size:t=18}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 1200 1227",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M714.163 519.284 1160.89 0h-105.86L667.137 450.887 357.328 0H0l468.492 681.821L0 1226.37h105.866l409.625-476.152 327.181 476.152H1200L714.137 519.284h.026Zm-145.087 168.62-47.469-67.894L144.011 79.694h162.683l304.797 435.991 47.468 67.894 396.2 566.721h-162.68L569.076 687.929v-.025Z"})})}function gt(){const{data:t}=Ce({queryKey:["server-health-version"],queryFn:$e,staleTime:3e5,retry:1}),a=t!=null&&t.version&&t.version!=="0.0.0"?t.version:null;return e.jsxs("div",{className:"bg-surface-0 text-gray-200 animate-fade-in",children:[e.jsxs("div",{className:"relative overflow-hidden border-b border-white/5",children:[e.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute -top-40 -right-40 w-[28rem] h-[28rem] rounded-full bg-blue-500/15 blur-3xl"}),e.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute -bottom-40 -left-40 w-[28rem] h-[28rem] rounded-full bg-cyan-500/10 blur-3xl"}),e.jsxs("div",{className:"relative max-w-[1100px] mx-auto px-6 py-20 text-center",children:[e.jsxs("div",{className:"inline-flex items-center gap-3 mb-8",children:[e.jsx(Me,{className:"w-14 h-14 object-contain drop-shadow-[0_8px_20px_rgba(99,102,241,0.30)]"}),e.jsx("span",{className:"text-3xl font-bold bg-gradient-to-r from-blue-500 via-purple-500 to-emerald-500 bg-clip-text text-transparent",children:"Testver"})]}),a&&e.jsxs("div",{className:"-mt-3 mb-8 flex flex-wrap items-center justify-center gap-x-3 gap-y-2 text-sm",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full bg-surface-2 px-3.5 py-1.5 ring-1 ring-white/10",title:"The Testver version installed on this server",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Version"}),e.jsxs("span",{className:"font-mono font-semibold text-gray-900 dark:text-gray-100","data-testid":"about-version",children:["v",a]})]}),e.jsxs("a",{href:"https://docs.testver.com/release-notes",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 font-medium text-blue-600 dark:text-blue-400 hover:underline",children:["What's new",e.jsx(ae,{size:14})]})]}),e.jsx("h1",{className:"text-4xl sm:text-5xl font-bold text-gray-100 leading-tight max-w-3xl mx-auto",children:"AI-powered test management & automation, in one workspace."}),e.jsx("p",{className:"mt-5 text-lg text-gray-500 dark:text-gray-400 max-w-2xl mx-auto leading-relaxed",children:"Plan, automate, execute, and report — across web, mobile, and API — without switching between half a dozen tools."}),e.jsxs("div",{className:"mt-9 flex flex-wrap items-center justify-center gap-3",children:[e.jsxs("a",{href:"https://testver.com",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-xl bg-brand-500 hover:bg-brand-700 text-white text-sm font-semibold transition-colors shadow-lg shadow-brand-500/20",children:[e.jsx(ne,{size:16}),"Visit testver.com",e.jsx(z,{size:14,className:"opacity-80"})]}),e.jsxs("a",{href:"https://docs.testver.com",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-xl bg-surface-2 hover:bg-surface-3 text-gray-700 dark:text-gray-200 text-sm font-medium transition-colors ring-1 ring-white/10",children:[e.jsx(ie,{size:16}),"Documentation",e.jsx(z,{size:14,className:"opacity-60"})]}),e.jsxs("a",{href:"https://docs.testver.com/video-tutorials",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-xl bg-surface-2 hover:bg-surface-3 text-gray-700 dark:text-gray-200 text-sm font-medium transition-colors ring-1 ring-white/10",children:[e.jsx(Qe,{size:16}),"Video tutorials",e.jsx(z,{size:14,className:"opacity-60"})]}),e.jsxs("a",{href:"https://support.testver.com",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-xl bg-surface-2 hover:bg-surface-3 text-gray-700 dark:text-gray-200 text-sm font-medium transition-colors ring-1 ring-white/10",children:[e.jsx(oe,{size:16}),"Support",e.jsx(z,{size:14,className:"opacity-60"})]})]})]})]}),e.jsx("div",{className:"border-b border-white/5 bg-surface-1/40",children:e.jsxs("div",{className:"max-w-[1100px] mx-auto px-6 py-14",children:[e.jsxs("div",{className:"text-center mb-9",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:"One engine. Three surfaces."}),e.jsx("p",{className:"text-base text-gray-500 dark:text-gray-400 mt-2.5 max-w-2xl mx-auto leading-relaxed",children:"The same suites, runs, reporting, and AI work whether you're testing a browser, a device, or an endpoint."})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(q,{icon:e.jsx(ne,{size:22}),title:"Web Automation",desc:"Playwright, Selenium, Cypress, and more — run locally or on a cloud grid, with screenshots, video, and traces captured per test.",tint:"sky"}),e.jsx(q,{icon:e.jsx(Ke,{size:22}),title:"Mobile Automation",desc:"Appium on real devices and emulators, with live device mirroring while the test runs and native-locator recording.",tint:"emerald"}),e.jsx(q,{icon:e.jsx(Ze,{size:22}),title:"API Automation",desc:"A full REST/GraphQL workspace — collections, environments, auth profiles, schema validation, and chained requests.",tint:"violet"})]})]})}),e.jsxs("div",{className:"max-w-[1100px] mx-auto px-6 py-16",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:"What's inside"}),e.jsx("p",{className:"text-base text-gray-500 dark:text-gray-400 mt-2.5 max-w-2xl mx-auto leading-relaxed",children:"The pillars covering the full QA lifecycle — from authoring a case to gating a production deploy."})]}),e.jsxs("div",{className:"flex flex-wrap justify-center gap-4",children:[e.jsx(g,{icon:e.jsx(H,{size:20}),title:"AI Assistant",desc:"Conversational AI that writes, refactors, and explains tests — and can drive a real browser to investigate a failure.",tint:"purple"}),e.jsx(g,{icon:e.jsx(Ve,{size:20}),title:"AI Record",desc:"Click through your app once, on web or a device; Testver generates a clean, locator-stable test script.",tint:"cyan"}),e.jsx(g,{icon:e.jsx(ue,{size:20}),title:"AI Test Gen",desc:"Turn requirements, documents, JIRA tickets, or OpenAPI specs into traceable test cases in seconds.",tint:"amber"}),e.jsx(g,{icon:e.jsx(Je,{size:20}),title:"Test Cases, Plans & Cycles",desc:"A first-class test management system — cases, plans, execution cycles, and a built-in defect tracker.",tint:"emerald"}),e.jsx(g,{icon:e.jsx(le,{size:20}),title:"Test Suites",desc:"Group any tests into a reusable suite in Test Explorer, then run them together with your own browser matrix, concurrency, and retries.",tint:"sky"}),e.jsx(g,{icon:e.jsx(Xe,{size:20}),title:"CI/CD Pipelines",desc:"GitHub Actions, GitLab, Jenkins, Azure, Bitbucket, and CircleCI trigger runs that execute here — and gate the build on the verdict.",tint:"indigo"}),e.jsx(g,{icon:e.jsx(ce,{size:20}),title:"Runs, Reports & AI Fix",desc:"Live execution, per-run artifacts, baselines and comparisons, AI failure analysis, and self-healing that repairs and re-runs a broken test.",tint:"rose"}),e.jsx(g,{icon:e.jsx(de,{size:20}),title:"Coverage & Traceability",desc:"See exactly which requirements are covered, by which cases, executed by which scripts, with which results.",tint:"blue"}),e.jsx(g,{icon:e.jsx(et,{size:20}),title:"Connectors",desc:"JIRA, Slack, MS Teams, Email, BrowserStack, LambdaTest, Sauce Labs — wired into the toolchain you already use.",tint:"teal"}),e.jsx(g,{icon:e.jsx(tt,{size:20}),title:"Agent Skills",desc:"Teach the AI your team's conventions with reusable skills — the assistant applies them whenever it writes or fixes your tests.",tint:"fuchsia"}),e.jsx(g,{icon:e.jsx(pe,{size:20}),title:"Testver Grid",desc:"Testver's own cloud browsers — Chromium, Firefox and WebKit on machines that are not yours, with no vendor account, no keys and no test-code changes. A prepaid add-on to a paid plan; connect once on Testver → Connections.",tint:"violet"}),e.jsx(g,{icon:e.jsx(W,{size:20}),title:"Testver Cloud",desc:"Your own always-on Testver at your-team.cloud.testver.com — built, patched, backed up and repaired for you, so schedules fire and the whole team shares one workspace without anyone's laptop.",tint:"sky"})]})]}),e.jsx("div",{className:"border-y border-white/5 bg-surface-1/40",children:e.jsx("div",{className:"max-w-[1100px] mx-auto px-6 py-14",children:e.jsx("div",{className:"rounded-2xl border border-violet-500/20 bg-gradient-to-br from-violet-500/[0.08] via-transparent to-cyan-500/[0.06] p-8 sm:p-10",children:e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center gap-8",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 px-2.5 py-1 rounded-full bg-violet-500/12 ring-1 ring-violet-500/30 text-violet-700 dark:text-violet-300 text-xs font-semibold mb-4",children:[e.jsx(xe,{size:13}),"Testver AI Credits"]}),e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:"AI that works out of the box — no API keys to manage."}),e.jsxs("p",{className:"mt-3 text-base text-gray-500 dark:text-gray-400 leading-relaxed max-w-2xl",children:["Connect your Testver account and every AI feature is ready immediately. Usage draws from a shared pool of ",e.jsx("strong",{className:"text-gray-700 dark:text-gray-200",children:"credits"})," on your plan — visible live in the header ring, so you always know what's left before a long run starts."]}),e.jsxs("div",{className:"mt-6 grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(C,{icon:e.jsx(H,{size:15}),title:"Zero setup",desc:"No provider accounts, no keys, no billing plumbing."}),e.jsx(C,{icon:e.jsx(ce,{size:15}),title:"Transparent usage",desc:"A live ring shows credits used and remaining at a glance."}),e.jsx(C,{icon:e.jsx(ye,{size:15}),title:"Managed by Testver",desc:"Models are chosen, tuned and kept current by Testver — nothing to pick, upgrade or maintain."})]})]}),e.jsxs("a",{href:"https://testver.com/pricing",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center justify-center gap-2 px-5 py-3 rounded-xl bg-brand-500 hover:bg-brand-700 text-white text-sm font-semibold transition-colors shadow-lg shadow-brand-500/20 flex-shrink-0 self-start lg:self-center",children:[e.jsx(xe,{size:16}),"View plans",e.jsx(z,{size:14,className:"opacity-80"})]})]})})})}),e.jsxs("div",{className:"max-w-[1100px] mx-auto px-6 py-16",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-widest text-gray-500 mb-3",children:[e.jsx(oe,{size:14,className:"text-emerald-500 dark:text-emerald-400"}),"Feedback & report issues"]}),e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:"Found a bug or have an idea? Tell us on the Support portal."}),e.jsxs("p",{className:"mt-3 text-base text-gray-500 dark:text-gray-400 leading-relaxed max-w-3xl",children:["Sign in to ",e.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:"support.testver.com"})," with the same Testver account you use here and open a ticket. Every report gets a tracked ticket with its own history, so you can follow progress, add details and get a reply from the team in one place — no email threads to chase."]}),e.jsxs("div",{className:"mt-8 grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(O,{icon:e.jsx(st,{size:18}),tint:"rose",title:"Report an issue",desc:"Something failed, crashed or behaved unexpectedly — in the tool, the Grid, Cloud runs or Testver Mail."}),e.jsx(O,{icon:e.jsx(rt,{size:18}),tint:"amber",title:"Suggest a feature",desc:"A framework, integration or workflow you wish Testver supported. Ideas with a clear use case go to the top of the list."}),e.jsx(O,{icon:e.jsx(at,{size:18}),tint:"sky",title:"Ask a question",desc:"Not sure how something is meant to work? Ask — and check the docs first, most setup questions are answered there."})]}),e.jsxs("div",{className:"mt-6 rounded-2xl bg-surface-1 ring-1 ring-white/10 p-6 sm:p-7",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center gap-6",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-gray-800 dark:text-gray-200",children:"What to include in a bug report"}),e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:"The more of this you attach, the faster we can reproduce and fix it."}),e.jsxs("div",{className:"mt-4 grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-3",children:[e.jsx(C,{icon:e.jsx(le,{size:15}),title:"Steps to reproduce",desc:"What you did, what you expected and what actually happened."}),e.jsx(C,{icon:e.jsx(de,{size:15}),title:"Framework and target",desc:"Playwright, Cypress, Appium… and whether it ran locally, on the Grid or in the cloud."}),e.jsx(C,{icon:e.jsx(nt,{size:15}),title:"Screenshots or a recording",desc:"A picture of the error or a short screen recording of the failure."}),e.jsx(C,{icon:e.jsx(it,{size:15}),title:"Logs and version",desc:"The run log or error text, and which Testver version and operating system you are on."})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row lg:flex-col gap-3 flex-shrink-0",children:[e.jsxs("a",{href:"https://support.testver.com",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center justify-center gap-2 px-5 py-3 rounded-xl bg-brand-500 hover:bg-brand-700 text-white text-sm font-semibold transition-colors shadow-lg shadow-brand-500/20",children:[e.jsx(ot,{size:16}),"Open the Support portal",e.jsx(z,{size:14,className:"opacity-80"})]}),e.jsxs("a",{href:"https://docs.testver.com",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center justify-center gap-2 px-5 py-3 rounded-xl bg-surface-2 hover:bg-surface-3 ring-1 ring-white/10 text-gray-800 dark:text-gray-200 text-sm font-semibold transition-colors",children:[e.jsx(ie,{size:16}),"Check the docs first",e.jsx(ae,{size:14,className:"opacity-70"})]})]})]}),e.jsx("p",{className:"mt-5 text-xs text-gray-500 dark:text-gray-500",children:"One account for Testver, the dashboard and the Support portal — if you can sign in here, you can sign in there. Please don't paste passwords, API keys or tokens into a ticket; mask them before attaching logs."})]})]}),e.jsx("div",{children:e.jsxs("div",{className:"max-w-[1100px] mx-auto px-6 py-12",children:[e.jsxs("div",{className:"flex flex-col items-center gap-5",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h3",{className:"text-base font-semibold text-gray-800 dark:text-gray-200",children:"Follow us"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1.5",children:"News, releases, and behind-the-scenes from the Testver team."})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Y,{href:"https://www.youtube.com/@TestverAI",label:"YouTube",icon:e.jsx(lt,{size:18}),hoverIcon:"hover:text-[#FF0000]",hoverBg:"hover:bg-[#FF0000]/10",hoverRing:"hover:ring-[#FF0000]/40"}),e.jsx(Y,{href:"https://www.linkedin.com/company/testver-ai",label:"LinkedIn",icon:e.jsx(ct,{size:18}),hoverIcon:"hover:text-[#0A66C2]",hoverBg:"hover:bg-[#0A66C2]/10",hoverRing:"hover:ring-[#0A66C2]/40"}),e.jsx(Y,{href:"https://x.com/testverai",label:"X",icon:e.jsx(ht,{size:16}),hoverIcon:"hover:text-gray-900 dark:hover:text-white",hoverBg:"hover:bg-gray-900/10 dark:hover:bg-white/10",hoverRing:"hover:ring-gray-900/30 dark:hover:ring-white/40"})]})]}),e.jsx("div",{className:"mt-10 text-center text-xs text-gray-500",children:"© Venomva. All rights reserved."})]})})]})}const A={blue:{iconBg:"bg-blue-500/15",iconColor:"text-blue-600 dark:text-blue-400",ring:"ring-blue-500/20"},purple:{iconBg:"bg-purple-500/15",iconColor:"text-purple-600 dark:text-purple-400",ring:"ring-purple-500/20"},cyan:{iconBg:"bg-cyan-500/15",iconColor:"text-cyan-600 dark:text-cyan-400",ring:"ring-cyan-500/20"},emerald:{iconBg:"bg-emerald-500/15",iconColor:"text-emerald-600 dark:text-emerald-400",ring:"ring-emerald-500/20"},amber:{iconBg:"bg-amber-500/15",iconColor:"text-amber-600 dark:text-amber-400",ring:"ring-amber-500/20"},violet:{iconBg:"bg-violet-500/15",iconColor:"text-violet-600 dark:text-violet-400",ring:"ring-violet-500/20"},rose:{iconBg:"bg-rose-500/15",iconColor:"text-rose-600 dark:text-rose-400",ring:"ring-rose-500/20"},sky:{iconBg:"bg-sky-500/15",iconColor:"text-sky-600 dark:text-sky-400",ring:"ring-sky-500/20"},indigo:{iconBg:"bg-indigo-500/15",iconColor:"text-indigo-600 dark:text-indigo-400",ring:"ring-indigo-500/20"},teal:{iconBg:"bg-teal-500/15",iconColor:"text-teal-600 dark:text-teal-400",ring:"ring-teal-500/20"},fuchsia:{iconBg:"bg-fuchsia-500/15",iconColor:"text-fuchsia-600 dark:text-fuchsia-400",ring:"ring-fuchsia-500/20"}};function q({icon:t,title:a,desc:r,tint:i}){const n=A[i]??A.brand;return e.jsxs("div",{className:"group bg-surface-1 rounded-2xl border border-white/5 p-6 hover:border-white/15 transition-colors",children:[e.jsx("div",{className:`w-12 h-12 rounded-xl ${n.iconBg} ${n.iconColor} ring-1 ${n.ring} flex items-center justify-center mb-4`,children:t}),e.jsx("h3",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:a}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-2 leading-relaxed",children:r})]})}function g({icon:t,title:a,desc:r,tint:i}){const n=A[i]??A.brand;return e.jsxs("div",{className:"group bg-surface-1 rounded-2xl border border-white/5 p-6 hover:border-white/15 hover:bg-white/[0.02] transition-colors w-full sm:w-[calc(50%-0.5rem)] lg:w-[calc(33.333%-0.667rem)]",children:[e.jsx("div",{className:`w-11 h-11 rounded-xl ${n.iconBg} ${n.iconColor} ring-1 ${n.ring} flex items-center justify-center mb-4`,children:t}),e.jsx("h3",{className:"text-[15px] font-semibold text-gray-900 dark:text-gray-100",children:a}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-2 leading-relaxed",children:r})]})}function O({icon:t,title:a,desc:r,tint:i}){const n=A[i]??A.blue;return e.jsxs("div",{className:"rounded-2xl bg-surface-1 ring-1 ring-white/10 p-5",children:[e.jsx("span",{className:`w-10 h-10 rounded-xl flex items-center justify-center ring-1 ${n.iconBg} ${n.iconColor} ${n.ring}`,children:t}),e.jsx("div",{className:"mt-3 text-sm font-semibold text-gray-800 dark:text-gray-200",children:a}),e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400 leading-relaxed",children:r})]})}function C({icon:t,title:a,desc:r}){return e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("span",{className:"mt-0.5 w-7 h-7 rounded-lg bg-surface-2 ring-1 ring-white/10 text-violet-600 dark:text-violet-300 flex items-center justify-center flex-shrink-0",children:t}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-gray-800 dark:text-gray-200",children:a}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-0.5 leading-relaxed",children:r})]})]})}function Y({icon:t,label:a,href:r,hoverIcon:i,hoverBg:n,hoverRing:l}){return e.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer","aria-label":a,title:a,className:["w-10 h-10 rounded-full bg-surface-1 ring-1 ring-white/10 text-gray-500 dark:text-gray-400","flex items-center justify-center transition-colors",i??"hover:text-brand-300",n??"hover:bg-white/5",l??"hover:ring-white/20"].join(" "),children:t})}function wt(){const t=ke(),a=we(),r=/\/about\/?$/.test(t.pathname)?"about":"connections",{data:i}=ge(),n=v=>{a(v==="about"?"/testver/about":"/testver",{replace:!0})},l=v=>`inline-flex items-center gap-2 px-3.5 py-3 text-sm font-medium border-b-2 transition-colors ${v?"text-gray-900 dark:text-gray-100 border-sky-400":"text-gray-500 dark:text-gray-400 border-transparent hover:text-gray-800 dark:hover:text-gray-200"}`;return e.jsxs("div",{className:"min-h-screen bg-surface-0 text-gray-200",children:[e.jsx("div",{className:"sticky top-0 z-10 bg-surface-1 border-b border-black/5 dark:border-white/5",children:e.jsxs("div",{className:"max-w-[1100px] mx-auto px-6 flex items-center gap-1",children:[e.jsxs("button",{type:"button",onClick:()=>n("connections"),className:l(r==="connections"),children:[i!=null&&i.connected?e.jsx(We,{size:15,className:"text-emerald-500"}):e.jsx(He,{size:15}),"Connections",(i==null?void 0:i.connected)&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-400 shadow-[0_0_0_3px_rgba(52,211,153,0.15)]"})]}),e.jsxs("button",{type:"button",onClick:()=>n("about"),className:l(r==="about"),children:[e.jsx(Ue,{size:15}),"About"]})]})}),r==="about"?e.jsx(gt,{}):e.jsx(mt,{})]})}export{wt as AboutPage};
@@ -0,0 +1 @@
1
+ import{r as c,j as e}from"./vendor-react-DOVfxdUy.js";import{a as H,u as q}from"./vendor-query-DkZSMtfn.js";import{bQ as V,ev as W,ew as X,ex as J,ey as Z,ez as ee}from"./index-BlA8ntjb.js";import{C as B}from"./ConfirmDialog-D_N9188T.js";import{c as se}from"./clipboard-BIEd7Ccc.js";import{a as te}from"./formatDate-T65-Y6Mi.js";import{a1 as $,b5 as ae,z as re,u as ne,a9 as oe,U as ie,p as le,R as ce,cQ as F,ao as de,cI as xe,ah as Q,ai as me}from"./vendor-icons-Cm92aSc5.js";function ue(s){if(!s)return"never";const a=Math.floor((Date.now()-s)/6e4);if(a<1)return"just now";if(a<60)return`${a}m ago`;const t=Math.floor(a/60);return t<24?`${t}h ago`:`${Math.floor(t/24)}d ago`}function _(s){const a=s-Date.now();if(a<=0)return"expired";const t=a/864e5;return t>=1?`expires in ${Math.round(t)}d`:`expires in ${Math.max(1,Math.floor(a/36e5))}h`}function he(s){const a=c.useRef(s);a.current=s,c.useEffect(()=>{const t=i=>{i.key==="Escape"&&a.current()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[])}const D=["perMinute","runsAtOnce","aiPerDay","aiCreditsPerDay"],pe=["aiPerDay","aiCreditsPerDay"],I={perMinute:"Requests a minute",runsAtOnce:"Runs at once",aiPerDay:"AI requests a day",aiCreditsPerDay:"AI credits a day"};function ye(s){if(!s)return"";const a=[];return s.perMinute!==void 0&&a.push(`${s.perMinute} ${s.perMinute===1?"request":"requests"} a minute`),s.runsAtOnce!==void 0&&a.push(`${s.runsAtOnce} ${s.runsAtOnce===1?"run":"runs"} at once`),s.aiPerDay!==void 0&&a.push(`${s.aiPerDay} AI ${s.aiPerDay===1?"request":"requests"} a day`),s.aiCreditsPerDay!==void 0&&a.push(`${s.aiCreditsPerDay} AI credits a day`),a.join(" · ")}function fe({scopes:s}){return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-white/5 text-gray-400",children:"reads"}),s.includes("run")&&e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-300",title:"Runs tests on this server",children:"runs tests"}),s.includes("ai")&&e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-violet-500/10 text-violet-300",title:"Testver's AI writes and repairs tests, with your AI and credits",children:"uses AI"})]})}function O({token:s,owner:a,onRenew:t,onRevoke:i}){return e.jsxs("div",{className:`flex items-center gap-3 px-4 py-2.5 rounded-xl bg-surface-1 border border-white/5 text-sm ${s.expired?"opacity-70":""}`,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-gray-200",children:s.name}),e.jsxs("code",{className:"text-xs text-gray-500",children:[s.prefix,"…"]}),a&&e.jsx("span",{className:"text-xs text-gray-400",children:a}),e.jsx(fe,{scopes:s.scopes}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${s.expired?"bg-red-500/10 text-red-300":"bg-white/5 text-gray-400"}`,children:_(s.expiresAt)})]}),s.limits&&e.jsxs("div",{className:"mt-0.5 text-xs text-gray-500 flex items-center gap-1",title:"This token's own limits; the server's limits still apply",children:[e.jsx(F,{size:12,className:"flex-shrink-0"})," At most ",ye(s.limits)]})]}),e.jsxs("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:["created ",te(s.createdAt)," · last used ",ue(s.lastUsedAt),s.lastUsedAt&&s.lastUsedIp?` from ${s.lastUsedIp}`:""]}),t&&!s.expired&&e.jsx("button",{onClick:t,title:"Renew: the same token, for another period from today","aria-label":`Renew ${s.name}`,className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-200 hover:bg-white/5 transition-colors",children:e.jsx(de,{size:15})}),i&&e.jsx("button",{onClick:i,title:"Revoke","aria-label":`Revoke ${s.name}`,className:"p-1.5 rounded-lg text-red-400 hover:text-red-600 dark:hover:text-red-500 hover:bg-red-500/10 transition-colors",children:e.jsx(xe,{size:15})})]})}function ge({days:s,defaultDays:a,canRun:t,canUseAi:i,aiOff:x,aiLimits:m,serverLimits:l,onCreated:p,defaultName:v}){const[y,f]=c.useState(v??""),[j,w]=c.useState(!1),[N,g]=c.useState(!1),[k,n]=c.useState(a),[u,r]=c.useState(!1),[d,b]=c.useState({}),[A,C]=c.useState(!1),[P,R]=c.useState(null),M=!!y.trim()&&!A,z=D.filter(o=>N||!pe.includes(o)),U=()=>{const o={};for(const h of z){const S=(d[h]??"").trim();if(!S)continue;const T=Number(S),E=l==null?void 0:l[h];if(!Number.isInteger(T)||T<1)return{error:`${I[h]}: a whole number, at least 1.`};if(E!==void 0&&T>E)return{error:`${I[h]}: at most ${E}, this server's limit. Leave it empty to use the server's.`};o[h]=T}return{limits:o}},L=async()=>{if(!M)return;R(null);const o=U();if("error"in o){R(o.error);return}C(!0);try{const h=["read",...j&&t?["run"]:[],...N&&i?["ai"]:[]],S=await X({name:y.trim(),scopes:h,days:k,...Object.keys(o.limits).length?{limits:o.limits}:{}});f(v??""),w(!1),g(!1),b({}),r(!1),p(S)}catch(h){R((h==null?void 0:h.message)||String(h))}finally{C(!1)}},G=Number(d.aiPerDay)||(m==null?void 0:m.perDay),Y=Number(d.aiCreditsPerDay)||(m==null?void 0:m.creditsPerDay);return e.jsxs("div",{className:"mb-4 p-4 rounded-xl bg-surface-1 border border-white/5 space-y-3",children:[e.jsxs("div",{className:"flex items-end gap-2 flex-wrap",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-gray-500",children:"Name"}),e.jsx("input",{value:y,onChange:o=>f(o.target.value),maxLength:60,onKeyDown:o=>{o.key==="Enter"&&L()},placeholder:"e.g. change checks on my laptop",className:"px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50 w-64"})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-gray-500",children:"Expires"}),e.jsx("select",{value:k,onChange:o=>n(Number(o.target.value)),className:"px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm text-gray-900 dark:text-gray-200 focus:outline-none focus:border-brand-500/50",children:s.map(o=>e.jsx("option",{value:o,children:o===365?"in 1 year":`in ${o} days`},o))})]}),e.jsxs("button",{disabled:!M,onClick:()=>void L(),className:"flex items-center gap-1.5 px-3.5 py-2 rounded-xl text-sm font-medium bg-brand-600 hover:bg-brand-500 text-white transition-colors disabled:opacity-50",children:[A?e.jsx($,{size:14,className:"animate-spin"}):e.jsx(ae,{size:14})," Create Token"]})]}),e.jsxs("fieldset",{children:[e.jsx("legend",{className:"text-xs text-gray-500 mb-1",children:"It may"}),e.jsxs("div",{className:"flex flex-col gap-1.5 text-sm text-gray-300",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:"pat-scope",checked:!j,onChange:()=>w(!1),className:"accent-brand-500"}),"Read the tests, the tests a change affects, and past runs"]}),e.jsxs("label",{className:`flex items-center gap-2 ${t?"":"opacity-60"}`,children:[e.jsx("input",{type:"radio",name:"pat-scope",checked:j,disabled:!t,onChange:()=>w(!0),className:"accent-brand-500"}),"Read, and run tests on this server"]}),!t&&e.jsx("span",{className:"ml-6 text-xs text-gray-500",children:"Your role cannot run tests, so your tokens can only read."}),e.jsxs("label",{className:`flex items-center gap-2 mt-1 ${i?"":"opacity-60"}`,children:[e.jsx("input",{type:"checkbox",checked:N,disabled:!i,onChange:o=>g(o.target.checked),className:"accent-brand-500"}),"Also have Testver's AI write and repair tests, with your AI and your credits"]}),i&&m&&e.jsxs("span",{className:"ml-6 text-xs text-gray-500",children:["At most ",G," AI requests and ",Y," credits a day for this token.",!j&&" The tests it writes or repairs are not run unless the token may also run tests."]}),!i&&e.jsx("span",{className:"ml-6 text-xs text-gray-500",children:x?"An administrator has turned off Testver's AI for tokens on this server.":"Your role cannot change tests, so your tokens cannot use Testver's AI."})]})]}),l&&e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>r(o=>!o),"aria-expanded":u,className:"flex items-center gap-1 text-xs text-gray-500 hover:text-gray-300",children:[u?e.jsx(re,{size:13}):e.jsx(ne,{size:13})," Limits (optional)"]}),u&&e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsx("p",{className:"text-xs text-gray-500",children:"Lower limits for this token only. Leave a box empty to use this server's limit, shown in it."}),e.jsx("div",{className:"flex gap-3 flex-wrap",children:z.map(o=>e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-gray-500",children:I[o]}),e.jsx("input",{type:"number",min:1,max:l[o],step:1,inputMode:"numeric",value:d[o]??"",placeholder:String(l[o]),onChange:h=>b(S=>({...S,[o]:h.target.value})),className:"px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50 w-36"})]},o))})]})]}),P&&e.jsx("p",{role:"alert",className:"text-sm text-red-300",children:P})]})}function be({raw:s,token:a,onClose:t}){const[i,x]=c.useState(null),[m,l]=c.useState(!1),p=()=>{i==="ok"?t():l(!0)};he(p);const v=window.location.origin;return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",children:[e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"new-pat-title",className:"w-full max-w-xl rounded-2xl bg-surface-1 border border-white/10 p-6",children:[e.jsxs("h3",{id:"new-pat-title",className:"text-base font-semibold text-gray-100 mb-2",children:['Access token "',a.name,'" created']}),e.jsx("p",{className:"text-xs text-amber-300 mb-3",children:"Copy it now — this is the only time it will be shown."}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 rounded-xl bg-surface-2 border border-white/10",children:[e.jsx("code",{className:"text-xs text-gray-200 break-all flex-1 select-all",children:s}),e.jsx("button",{onClick:async()=>{x(await se(s)?"ok":"fail")},"aria-label":"Copy the token",className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-200",children:i==="ok"?e.jsx(Q,{size:14,className:"text-emerald-400"}):e.jsx(me,{size:14})})]}),i==="fail"&&e.jsx("p",{role:"alert",className:"text-xs text-red-300 mt-1.5",children:"Copying isn't available here — select the token above and copy it by hand."}),e.jsxs("div",{className:"mt-4 text-sm text-gray-400 space-y-1.5",children:[e.jsx("p",{className:"font-medium text-gray-300",children:"Next:"}),e.jsxs("ol",{className:"list-decimal ml-5 space-y-1",children:[e.jsxs("li",{children:["Give it to the tool or script that connects to this server, with this server's address: ",e.jsx("code",{children:v})," (or the address others reach it at, if that is a local one)."]}),e.jsx("li",{children:"Keep it out of your project's files: tools keep it for your user, or read it from an environment variable."})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["It ",a.scopes.includes("run")?"reads and runs tests":"reads",a.scopes.includes("ai")?", and uses Testver's AI":""," · ",_(a.expiresAt),"."]})]}),e.jsx("div",{className:"mt-4 text-right",children:e.jsx("button",{onClick:p,className:"px-4 py-2 rounded-xl text-sm font-medium bg-brand-600 hover:bg-brand-500 text-white",children:"Done"})})]}),m&&e.jsx(B,{open:!0,title:"Close without copying the token?",description:"It cannot be shown again — you would have to create a new token.",confirmLabel:"Close",variant:"danger",onCancel:()=>l(!1),onConfirm:t})]})}function ve({data:s,onSaved:a}){const t=s.limits,i=s.defaultLimits??t,x=s.limitBounds,m=r=>({perMinute:String(r.perMinute),runsAtOnce:String(r.runsAtOnce),aiPerDay:String(r.aiPerDay),aiCreditsPerDay:String(r.aiCreditsPerDay)}),[l,p]=c.useState(()=>m(t)),v=D.map(r=>t[r]).join("-");c.useEffect(()=>{p(m(t))},[v]);const[y,f]=c.useState(!1),[j,w]=c.useState(null),[N,g]=c.useState(!1),k=D.some(r=>l[r].trim()!==String(t[r])),n=async()=>{w(null),g(!1);const r={};for(const d of D){const b=Number(l[d].trim()),[A,C]=(x==null?void 0:x[d])??[0,Number.MAX_SAFE_INTEGER];if(!l[d].trim()||!Number.isInteger(b)||b<A||b>C){w(`${I[d]}: a whole number from ${A} to ${C}.`);return}r[d]=b}f(!0);try{await ee(r),g(!0),a()}catch(d){w((d==null?void 0:d.message)||String(d))}finally{f(!1)}},u=D.every(r=>l[r].trim()===String(i[r]));return e.jsxs("div",{className:"mb-4 p-4 rounded-xl bg-surface-1 border border-white/5 space-y-3",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium text-gray-200 flex items-center gap-1.5",children:[e.jsx(F,{size:14,className:"text-brand-300"})," Limits for every token on this server"]}),e.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:"How much one token may ask of this server. A person may give a token lower limits, never higher. A change applies at once, to tokens made before too. Set a day's AI to 0 to turn off Testver's AI for every token."})]}),e.jsxs("div",{className:"flex items-end gap-3 flex-wrap",children:[D.map(r=>{var d,b;return e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-gray-500",children:I[r]}),e.jsx("input",{type:"number",step:1,inputMode:"numeric",min:(d=x==null?void 0:x[r])==null?void 0:d[0],max:(b=x==null?void 0:x[r])==null?void 0:b[1],value:l[r],onChange:A=>{g(!1),p(C=>({...C,[r]:A.target.value}))},className:"px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm text-gray-200 focus:outline-none focus:border-brand-500/50 w-36"})]},r)}),e.jsxs("button",{disabled:!k||y,onClick:()=>void n(),className:"flex items-center gap-1.5 px-3.5 py-2 rounded-xl text-sm font-medium bg-brand-600 hover:bg-brand-500 text-white transition-colors disabled:opacity-50",children:[y?e.jsx($,{size:14,className:"animate-spin"}):e.jsx(Q,{size:14})," Save"]}),!u&&e.jsx("button",{type:"button",onClick:()=>{g(!1),p(m(i))},className:"px-3 py-2 rounded-xl text-sm text-gray-400 hover:text-gray-200 hover:bg-white/5",children:"Back to the defaults"})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["Defaults: ",i.perMinute," requests a minute, ",i.runsAtOnce," runs at once, ",i.aiPerDay," AI requests and ",i.aiCreditsPerDay," AI credits a day."]}),N&&e.jsx("p",{className:"text-sm text-emerald-300",children:"Saved. Every token's limits are these now."}),j&&e.jsx("p",{role:"alert",className:"text-sm text-red-300",children:j})]})}function K({what:s,error:a,onRetry:t}){return e.jsxs("div",{role:"alert",className:"px-4 py-3 rounded-xl bg-red-500/10 border border-red-500/30 text-sm text-red-300 flex items-center gap-3",children:[e.jsx(le,{size:15,className:"flex-shrink-0"}),e.jsxs("span",{className:"flex-1",children:["Could not load ",s,": ",(a==null?void 0:a.message)||String(a)]}),e.jsxs("button",{onClick:t,className:"flex items-center gap-1 px-2.5 py-1 rounded-lg border border-red-500/30 hover:bg-red-500/10 text-xs font-medium",children:[e.jsx(ce,{size:12})," Retry"]})]})}function Ie({isAdmin:s}){var g,k;const a=H(),t=q({queryKey:["access-tokens"],queryFn:V}),i=q({queryKey:["access-tokens","all"],queryFn:W,enabled:s}),[x,m]=c.useState(null),[l,p]=c.useState(null),[v,y]=c.useState(null),f=()=>{a.invalidateQueries({queryKey:["access-tokens"]})},j=async n=>{var u;y(null);try{await J(n.id,((u=t.data)==null?void 0:u.defaultDays)??90),f()}catch(r){y((r==null?void 0:r.message)||String(r))}},w=async()=>{if(l){y(null);try{await Z(l.id),f()}catch(n){y((n==null?void 0:n.message)||String(n))}finally{p(null)}}},N=(((g=i.data)==null?void 0:g.tokens)??[]).filter(n=>{var u;return!((u=t.data)!=null&&u.tokens.some(r=>r.id===n.id))});return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-100 flex items-center gap-2 mb-1",children:[e.jsx(oe,{size:17,className:"text-amber-300"})," Access Tokens"]}),e.jsxs("p",{className:"text-sm text-gray-400 mb-3",children:["A tool or a script of yours reaches this Testver server with a token, as you: it reads the tests, the tests a change affects and past runs, and, if you allow it, runs tests on this server. The value is shown ",e.jsx("b",{children:"once"}),". A token stops working when it expires, when you revoke it, or when your account is disabled; renew it before it expires to keep it. Every use is in the audit log. A token reaches Testver's AI only if you allow it, with your AI and credits, within a daily allowance."]}),t.isError?e.jsx(K,{what:"your access tokens",error:t.error,onRetry:()=>t.refetch()}):t.isLoading||!t.data?e.jsxs("div",{className:"py-6 text-center text-gray-500 text-sm",children:[e.jsx($,{size:16,className:"animate-spin inline mr-2"}),"Loading…"]}):e.jsxs(e.Fragment,{children:[e.jsx(ge,{days:t.data.days,defaultDays:t.data.defaultDays,canRun:t.data.canRun,canUseAi:t.data.canUseAi===!0,aiOff:t.data.aiOff===!0,aiLimits:t.data.aiLimits,serverLimits:t.data.limits,onCreated:n=>{m(n),f()}}),v&&e.jsx("p",{role:"alert",className:"mb-3 text-sm text-red-300",children:v}),t.data.tokens.length===0?e.jsx("div",{className:"py-8 text-center rounded-xl border border-dashed border-white/10 text-sm text-gray-500",children:"You have no access tokens. Create one above for the tool or script that connects to this server."}):e.jsx("div",{className:"space-y-1.5",children:t.data.tokens.map(n=>e.jsx(O,{token:n,onRenew:()=>void j(n),onRevoke:()=>p({id:n.id,name:n.name})},n.id))})]})]}),s&&e.jsxs("section",{children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-100 flex items-center gap-2 mb-1",children:[e.jsx(ie,{size:17,className:"text-brand-300"})," Everyone's Tokens"]}),e.jsx("p",{className:"text-sm text-gray-400 mb-3",children:"The tokens other people on this server made. Revoke one that should no longer reach it; the super admin's and admins' tokens only the super admin can revoke."}),((k=t.data)==null?void 0:k.canEditLimits)&&t.data.limits&&e.jsx(ve,{data:t.data,onSaved:f}),i.isError?e.jsx(K,{what:"everyone's tokens",error:i.error,onRetry:()=>i.refetch()}):i.isLoading?e.jsxs("div",{className:"py-6 text-center text-gray-500 text-sm",children:[e.jsx($,{size:16,className:"animate-spin inline mr-2"}),"Loading…"]}):N.length===0?e.jsx("div",{className:"py-8 text-center rounded-xl border border-dashed border-white/10 text-sm text-gray-500",children:"No one else has an access token."}):e.jsx("div",{className:"space-y-1.5",children:N.map(n=>{const u=n.owner?`${n.owner.displayName||n.owner.username} (${n.owner.role}${n.owner.active?"":", disabled"})`:"a removed account";return e.jsx(O,{token:n,owner:u,onRevoke:n.canRevoke?()=>p({id:n.id,name:n.name,owner:u}):void 0},n.id)})})]}),x&&e.jsx(be,{raw:x.token,token:x.accessToken,onClose:()=>m(null)}),l&&e.jsx(B,{open:!0,title:`Revoke "${l.name}"?`,description:`${l.owner?`${l.owner}'s`:"What uses this"} token stops working at once. This cannot be undone: a new token would be needed.`,confirmLabel:"Revoke",variant:"danger",onCancel:()=>p(null),onConfirm:()=>void w()})]})}export{Ie as A,ge as C};