@testver/testver 1.4.3 → 1.5.1
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.
- package/LICENSE +88 -69
- package/README.md +6 -2
- package/bin/testver.js +9 -1
- package/dist/index.js +38415 -21751
- package/package.json +179 -178
- package/src/ui/static/agents/antigravity.svg +76 -0
- package/src/ui/static/agents/codex.svg +3 -0
- package/src/ui/static/agents/gemini.svg +1 -0
- package/src/ui/static/agents/opencode.svg +4 -0
- package/src/ui/static/agents/vscode.svg +17 -0
- package/src/ui/static/assets/{AIPanel-KQFq4c0Q.js → AIPanel-RWO8Cd9w.js} +32 -32
- package/src/ui/static/assets/{AIRecordPanel-CAs8fXyS.js → AIRecordPanel-DnreS585.js} +40 -40
- package/src/ui/static/assets/{AIStreamUI-p_sMTEDQ.js → AIStreamUI-C1gHJtlF.js} +9 -9
- package/src/ui/static/assets/{AITestGenPage-CHaHfmu4.js → AITestGenPage-C8bWUelu.js} +5 -5
- package/src/ui/static/assets/{APITestingPage-BSGJY_hd.js → APITestingPage-DwL67hqL.js} +19 -19
- package/src/ui/static/assets/AboutPage-CynLB95E.js +1 -0
- package/src/ui/static/assets/AccessTokensTab-BdevOmpE.js +1 -0
- package/src/ui/static/assets/AdvancedPage-BeM7aB8b.js +3 -0
- package/src/ui/static/assets/{AnalyticsPage-Lm8noJqC.js → AnalyticsPage-C5ddYfRk.js} +1 -1
- package/src/ui/static/assets/AuditLogPage-DYcUdJoj.js +1 -0
- package/src/ui/static/assets/{ChangesSummary-Cu0_4Ucf.js → ChangesSummary-BjNMwGIZ.js} +3 -3
- package/src/ui/static/assets/{CodeMapPage-uEjuo3fk.js → CodeMapPage-BQOEtv-R.js} +3 -3
- package/src/ui/static/assets/{ConfirmDialog-DtotgVmI.js → ConfirmDialog-D_N9188T.js} +1 -1
- package/src/ui/static/assets/{CoveragePage-jNkQJA1P.js → CoveragePage-8bDSphY1.js} +2 -2
- package/src/ui/static/assets/{CronBuilder-D2fERHt9.js → CronBuilder-C7_JADb7.js} +1 -1
- package/src/ui/static/assets/{Dashboard-BaIj_IdQ.js → Dashboard-B22yRPyV.js} +1 -1
- package/src/ui/static/assets/{DefectsPage-DH0njYFG.js → DefectsPage-Arv4Ac-b.js} +72 -72
- package/src/ui/static/assets/{EmptyState-utxlJ0fu.js → EmptyState-BShNSbLf.js} +1 -1
- package/src/ui/static/assets/{ExportButton-ouKqn9CU.js → ExportButton-xrS_AnfS.js} +1 -1
- package/src/ui/static/assets/{FileViewer-mU3JloJ6.js → FileViewer-Bcr9T1jW.js} +18 -18
- package/src/ui/static/assets/{GitPage-TrX-RqNC.js → GitPage-DXL2Sv40.js} +12 -12
- package/src/ui/static/assets/{ImportExportPage-CIhK_raX.js → ImportExportPage-BcjzRd7T.js} +36 -36
- package/src/ui/static/assets/{JiraPushDialog-DgEZS-0u.js → JiraPushDialog-DNYU9Ce0.js} +1 -1
- package/src/ui/static/assets/{KpiTile-BHLE3HVj.js → KpiTile-BKlWqjgN.js} +1 -1
- package/src/ui/static/assets/{LiveExecutionView-CaIf7Jux.js → LiveExecutionView-1LlyEDEe.js} +1 -1
- package/src/ui/static/assets/{MediaModal-DNM45Uz2.js → MediaModal-Dyy_iHl9.js} +1 -1
- package/src/ui/static/assets/MobileRunPicker-Cf5rm469.js +1 -0
- package/src/ui/static/assets/MobileRunTarget-C4M4YJJh.js +6 -0
- package/src/ui/static/assets/{ModuleExplorer-rni7JbsL.js → ModuleExplorer-BKVbxFZK.js} +1 -1
- package/src/ui/static/assets/{OutputPage-Cn2WCpJ6.js → OutputPage-Bi-28tJi.js} +1 -1
- package/src/ui/static/assets/PipelinesPanel-BtO3iSJ4.js +1 -0
- package/src/ui/static/assets/{ProfilePage-BKNdkSnx.js → ProfilePage-BgZ4VDC-.js} +1 -1
- package/src/ui/static/assets/{ProjectExplorer-5e7J8t-o.js → ProjectExplorer-BVGbmVP7.js} +1 -1
- package/src/ui/static/assets/{RemoteFileStrip-C1S2aclP.js → RemoteFileStrip-dzPInzgb.js} +1 -1
- package/src/ui/static/assets/{ReportCard-D4EElEe9.js → ReportCard-LOf1PXlb.js} +2 -2
- package/src/ui/static/assets/{ReportFullView-2w2ysKRg.js → ReportFullView-Ce4OI8lf.js} +1 -1
- package/src/ui/static/assets/{ReportsPage-9Fx-IEwV.js → ReportsPage-DFxCQ8cY.js} +48 -48
- package/src/ui/static/assets/{ResultsPage-DPkfGh-K.js → ResultsPage-DD-uj8gk.js} +115 -115
- package/src/ui/static/assets/{RunState-CRuS_bC2.js → RunState-DDwFB4tA.js} +1 -1
- package/src/ui/static/assets/{RunTargets-CPKBrefj.js → RunTargets-CkIpY3v3.js} +1 -1
- package/src/ui/static/assets/ScriptMappingPage-DQQoR6sR.js +1 -0
- package/src/ui/static/assets/{SearchableDevicePicker-DubIldKj.js → SearchableDevicePicker-CenIxD7b.js} +1 -1
- package/src/ui/static/assets/{SettingsPage-BuZrrlW2.js → SettingsPage-DAV_0y0m.js} +83 -83
- package/src/ui/static/assets/{SharedReportView-ig5hECRk.js → SharedReportView-CqSLFKT1.js} +1 -1
- package/src/ui/static/assets/{SourcesPage-BPkqRqkC.js → SourcesPage-BvqC9oKw.js} +14 -14
- package/src/ui/static/assets/TestExplorerPage-Bdnll77k.js +7 -0
- package/src/ui/static/assets/{TestManagementPage-DJiWpCne.js → TestManagementPage-CCNE688A.js} +10 -10
- package/src/ui/static/assets/{TestPlansPage-G1lvK1C0.js → TestPlansPage-T6D25i6-.js} +5 -5
- package/src/ui/static/assets/{TestverCreditsRing-CEBSy3w3.js → TestverCreditsRing-CoDk5eAS.js} +1 -1
- package/src/ui/static/assets/TestverMcpPage-Dte0qSXp.js +34 -0
- package/src/ui/static/assets/{UncommittedDiffViewer-FKvUZcRi.js → UncommittedDiffViewer-BNroxCoo.js} +2 -2
- package/src/ui/static/assets/{UserManagementPage-gDGhaHE4.js → UserManagementPage-BU4MuDJZ.js} +10 -10
- package/src/ui/static/assets/{WorkflowsPage-BACdnU-1.js → WorkflowsPage-BP5k7AqE.js} +83 -83
- package/src/ui/static/assets/clipboard-BIEd7Ccc.js +1 -0
- package/src/ui/static/assets/{hiddenLlmProviders-DzwaR-b9.js → hiddenLlmProviders-BPORgy-e.js} +1 -1
- package/src/ui/static/assets/index-BlA8ntjb.js +47 -0
- package/src/ui/static/assets/index-Co4_SlGD.css +1 -0
- package/src/ui/static/assets/{reportMeta-3kxT7BIT.js → reportMeta-B9ZRW6ts.js} +1 -1
- package/src/ui/static/assets/runSelected-BoPm1sz-.js +1 -0
- package/src/ui/static/assets/{useFeatureFlags-DrhvBp0C.js → useFeatureFlags-B4Otsv-N.js} +1 -1
- package/src/ui/static/assets/{useJiraConnector-Dwj69Rfh.js → useJiraConnector--JZhbYrT.js} +1 -1
- package/src/ui/static/assets/{useOwnership-C1CmzcvJ.js → useOwnership-BhPOiYzy.js} +1 -1
- package/src/ui/static/assets/useSuites-GN_K2mHc.js +1 -0
- package/src/ui/static/assets/{useTestExplorer-CUqC18DV.js → useTestExplorer-BGhkGHKy.js} +1 -1
- package/src/ui/static/assets/{useTestLifecycle-C2S_vaX2.js → useTestLifecycle-DX5ES6x8.js} +1 -1
- package/src/ui/static/assets/{useTestManagement-DW6AW2mt.js → useTestManagement-ommXjx0q.js} +2 -2
- package/src/ui/static/assets/{useTestResults-yjH1aUy-.js → useTestResults-DWjvm8gm.js} +1 -1
- package/src/ui/static/assets/{vendor-icons-D_Dmmj8d.js → vendor-icons-Cm92aSc5.js} +1426 -1416
- package/src/ui/static/index.html +479 -479
- package/src/ui/static/assets/AboutPage-CDa24SCJ.js +0 -1
- package/src/ui/static/assets/AdvancedPage-BqXP0FLg.js +0 -3
- package/src/ui/static/assets/AuditLogPage-BvldSIik.js +0 -1
- package/src/ui/static/assets/MobileRunPicker-DFKm6_nU.js +0 -1
- package/src/ui/static/assets/MobileRunTarget-DHDoDZ_F.js +0 -6
- package/src/ui/static/assets/PipelinesPanel-D6zWcLtD.js +0 -1
- package/src/ui/static/assets/ScriptMappingPage-C3K_uyf0.js +0 -1
- package/src/ui/static/assets/TestExplorerPage-C_jl93GR.js +0 -7
- package/src/ui/static/assets/index-D6sQYc_0.js +0 -47
- package/src/ui/static/assets/index-aInN0yoR.css +0 -1
- package/src/ui/static/assets/runSelected-WlgnZcSF.js +0 -1
- package/src/ui/static/assets/useSuites-V0AxZYex.js +0 -1
|
@@ -1,19 +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,ey as ct,ez as kt,eA as Ct,eB as St,eC as zt,eD as $t,eE as Et,eF as Pt,a1 as Rt,eG as Dt,b as Ke,eH as At,eI as qt,eJ as Ot,eK as We,eL as It,eM as Tt,eN as Ft,eO as Lt,eP as Vt,a3 as Ut,eQ as Ht,eR as Bt,eS as _t}from"./index-D6sQYc_0.js";import{cY as $e,b4 as pe,ag as we,X as he,y as oe,t as xe,F as He,cZ as Ye,b6 as Xe,b7 as ie,a2 as Be,bI as Mt,ah as Ee,aL as Ze,bs as et,r as je,ap as ve,O as Kt,a0 as Te,a6 as dt,al as xt,u as Le,au as Jt,cW as Ie,ac as mt,a5 as Fe,bm as Je,K as ze,a9 as Qt,aa as Gt,I as Wt,a as Yt,cn as tt,aj as Xt,D as Zt,E as es,cz as st,c_ as ts}from"./vendor-icons-D_Dmmj8d.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};
|
|
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};
|