1import{j as e}from"./vendor-radix-BDJ1G1Rz.js";import{o as ne,_ as qt,$ as Ie,a8 as Ye,aP as J,q as P,ar as oe,I as F,C as Y,S as W,V as K,t as B,c as gt,B as M,ah as Se,av as bt,aa as le,a_ as X,cy as zn,cC as mt,aL as Fn,a$ as Kn,az as Vn,bO as Bn,cD as Hn,cE as $n,cF as qn,Z as Wn,aA as Vs,cG as Yn,cH as Gn,e as Xn,aq as Jn,aS as Zn,aT as Qn,aU as eo,a6 as to,aH as so,y as no,a9 as oo,g as ao,N as Wt,am as ro}from"./index-DU-Mv_L_.js";import{u as pe,j as yt,r as a,b as jt}from"./vendor-query-jnzAvHUk.js";import{l as io,q as co}from"./vendor-date-CemE0fj8.js";import{_ as H}from"./vendor-datadog-D3gwQpHA.js";import{a as me,u as A}from"./vendor-i18n-B-AdlurK.js";import{u as lo,a as uo,b as mo,c as po}from"./audit.query-BG663ew3.js";import{u as be}from"./use-scoped-accounts-Ba5MYjm9.js";import{a as vt,s as wt}from"./scoped-account-codes-KbsFcii_.js";import{a as Nt}from"./accounts-scope-badge-vUO7X5KH.js";import{F as De}from"./filter-dropdown-zQz1F6iG.js";import{R as kt,r as ho,C as Ct,X as Et,Y as Tt,T as Bs,A as xo,p as fo,m as go,L as bo,j as yo}from"./vendor-charts-CslQ3qEM.js";import{P as _t}from"./pagination-BAI12sQe.js";import{S as St}from"./sheet-DygMutiI.js";import{N as Le}from"./nav-tabs-CxWO2knQ.js";import{u as Re}from"./use-on-test-mode-change-BqeumQut.js";import{u as At}from"./use-scope-account-codes-Bsf6m7bQ.js";import{u as Ve}from"./use-verify-permission.hook-z68Q1APH.js";import{b as jo,c as vo,d as wo,e as No,f as ko,g as Co,h as Eo,i as To,j as _o,k as So}from"./developers.mutation-BYeNWvhb.js";import{D as It}from"./dots-menu-B4PDMxRW.js";import{F as ae}from"./field-kJ7JUfRc.js";import{A as Ge}from"./alert-CXODG9VH.js";import{M as Ao}from"./multi-values-field-_FpTTf0O.js";import{S as ze}from"./select-DpDnkHhK.js";import{u as Hs}from"./use-account-filter-tree-CAjveGQx.js";import{u as Io}from"./use-step-up-BLURD1B5.js";import{A as $s}from"./access-denied-alert-BIofsjaN.js";import{i as qs,j as Do,k as Lo}from"./accounts.mutation-Bq4pc72c.js";import{u as Ws,C as Ro,d as Be,b as Po,F as Oo}from"./index.esm-DLMWj2gi.js";import{P as Ys}from"./password-field-wGwVZk6Q.js";import{R as Mo}from"./radio-group-DUUjR6D6.js";import{u as Uo}from"./use-timezone-yGLKUF7V.js";import{u as zo,a as Fo}from"./audit-api.mutation-BWwqUcJ9.js";import{e as Ko,f as Vo}from"./smart-routing.query-lAHy4Y6X.js";
1import"./vendor-shared-D7qeTqf-.js";import"./filter-date-range-DiKef5xl.js";import"./date-picker-DDyGAMtD.js";import"./field-B3A1usSq.js";import"./field-label-row-DncCxLr_.js";import"./time-picker-xf1StE2V.js";import"./nav-link-CxyWzSoe.js";import"./dropdown-menu-CYoEklaj.js";import"./textarea-5Xv9XPyh.js";import"./intl-DBWlphZd.js";function Bo(){return pe({queryKey:["fetch-customized-api-keys-members"],queryFn:()=>ne.getInstance().getCustomizedApiKeysMembers().then(s=>s?.data||null).catch(s=>s),keepPreviousData:!0})}function Ho(){return pe({queryKey:["developers-get-allowed-ips"],queryFn:()=>ne.getInstance().getAllowedIps().then(s=>s?.data?{...s?.data,isError:!1}:null).catch(s=>({...s,isError:!0})),enabled:!1,cacheTime:0})}function $o(){return pe({queryKey:["fetch-customized-api-keys-accounts"],queryFn:()=>ne.getInstance().getCustomizedApiKeysAccounts().then(s=>s?.data||null).catch(s=>s),keepPreviousData:!0})}function qo(t){return pe({queryKey:["fetch-customized-api-keys",t],queryFn:()=>ne.getInstance().postCustomizedApiKeys(t).then(n=>n?.data||null).catch(n=>n),cacheTime:0,enabled:!!t?.length})}function Wo(){return pe({queryKey:["fetch-customized-api-keys-products"],queryFn:()=>ne.getInstance().getCustomizedApiKeysProducts().then(s=>s?.data||null).catch(s=>s),cacheTime:0})}function Yo(){return yt(["developers-patch-allowed-ips"],t=>ne.getInstance().patchAllowedIps(t).then(n=>n?.data?{...n?.data,isError:!1}:null).catch(n=>({...n,isError:!0})),{cacheTime:0})}function Go(){return yt(({payload:t})=>ne.getInstance().postPlaygroundExecuteFlow(t).then(n=>n?.data))}const Yt="en",Gt=["en","es","pt","fr","ja","tr","zh","ru","ar","de"];function Xt(t){const s=(t??"").trim();if(!s)return Yt;if(Gt.includes(s))return s;const n=s.split("-")[0];return n&&Gt.includes(n)?n:Yt}function Xo({children:t}){const[s,n]=a.useState(()=>me.exists("inspector.tabs.health"));return a.useEffect(()=>{const o=Xt(me.language||localStorage.getItem("lang")),r=i=>qt(Object.assign({
1"./lang/ar.json":()=>H(()=>import("./ar-CsjumALP.js"),[]),
1"./lang/de.json":()=>H(()=>import("./de-Bl9eJNum.js"),[]),
1"./lang/en.json":()=>H(()=>import("./en-DNbN_hR7.js"),[]),
1"./lang/es.json":()=>H(()=>import("./es-Dhahzkhx.js"),[]),
1"./lang/fr.json":()=>H(()=>import("./fr-o84H2aLU.js"),[]),
1"./lang/ja.json":()=>H(()=>import("./ja-DW0Au9U4.js"),[]),
1"./lang/pt.json":()=>H(()=>import("./pt-bmA6k8gv.js"),[]),
1"./lang/ru.json":()=>H(()=>import("./ru-C_BEHOMw.js"),[]),
1"./lang/tr.json":()=>H(()=>import("./tr-SmZl4iP1.js"),[]),
1"./lang/zh.json":()=>H(()=>import("./zh-BgnbFaX7.js"),[])}),`./lang/${i}.json`,3).then(l=>{me.addResourceBundle(i,"translation",l.default??l,!0,!0)});r(o).catch(()=>r("en")).catch(()=>{}).finally(()=>n(!0))},[]),a.useEffect(()=>{const o=()=>{const r=Xt(me.language);qt(Object.assign({
1"./lang/ar.json":()=>H(()=>import("./ar-CsjumALP.js"),[]),
1"./lang/de.json":()=>H(()=>import("./de-Bl9eJNum.js"),[]),
1"./lang/en.json":()=>H(()=>import("./en-DNbN_hR7.js"),[]),
1"./lang/es.json":()=>H(()=>import("./es-Dhahzkhx.js"),[]),
1"./lang/fr.json":()=>H(()=>import("./fr-o84H2aLU.js"),[]),
1"./lang/ja.json":()=>H(()=>import("./ja-DW0Au9U4.js"),[]),
1"./lang/pt.json":()=>H(()=>import("./pt-bmA6k8gv.js"),[]),
1"./lang/ru.json":()=>H(()=>import("./ru-C_BEHOMw.js"),[]),
1"./lang/tr.json":()=>H(()=>import("./tr-SmZl4iP1.js"),[]),
1"./lang/zh.json":()=>H(()=>import("./zh-BgnbFaX7.js"),[])
1}),`./lang/${r}.json`,3).then(i=>{me.addResourceBundle(r,"translation",i.default??i,!0,!0)}).catch(()=>{})};return me.on("languageChanged",o),()=>{me.off("languageChanged",o)}},[]),s?e.jsx(e.Fragment,{children:t}):null}function Gs(t){return pe({queryKey:["devx-api-logs",t],queryFn:async()=>(await ne.getInstance().postApiLogsListV2(t))?.data,enabled:!!t.start_date,cacheTime:0,useErrorBoundary:!1})}const Jt={TODAY:"inspector.health.filters.today",LAST_3_DAYS:"inspector.health.filters.last3Days",LAST_7_DAYS:"inspector.health.filters.last7Days",LAST_30_DAYS:"inspector.health.filters.last30Days",THIS_MONTH:"inspector.health.filters.thisMonth",CUSTOM:"inspector.health.filters.custom"},Jo={hour:"inspector.health.filters.hourly",day:"inspector.health.filters.daily",week:"inspector.health.filters.weekly",month:"inspector.health.filters.monthly"};function Zo({filters:t,onFiltersChange:s}){const{t:n}=A(),{accounts:o}=be({roles:[]}),{isTesting:r}=Ie(),i=a.useCallback(y=>{s(y==="CUSTOM"?E=>({...E,dateValue:y}):E=>({...E,dateValue:y,dateInit:void 0,dateEnd:void 0}))},[s]),l=a.useCallback(y=>{s(E=>({...E,dateInit:y}))},[s]),c=a.useCallback(y=>{s(E=>({...E,dateEnd:y}))},[s]),d=a.useCallback(y=>{s(E=>({...E,granularity:y}))},[s]),u=a.useMemo(()=>(o??[]).filter(y=>!!y).map(y=>({label:y.name||y.code||"",value:Ye(y,r)})),[o,r]),m=a.useCallback(y=>{const E=u.map(N=>N.value),f=J()&&E.length>0&&E.every(N=>y.includes(N))?[]:y;s(N=>({...N,accounts:f}))},[u,s]),p=a.useMemo(()=>[{label:n("inspector.health.filters.hourly"),value:"hour"},{label:n("inspector.health.filters.daily"),value:"day"},{label:n("inspector.health.filters.weekly"),value:"week"},{label:n("inspector.health.filters.monthly"),value:"month"}],[n]),h=a.useMemo(()=>{const y=[{id:"date",icon:"CalendarBlank",label:n("inspector.health.filters.dateRange"),type:"date",dateValue:t.dateValue,dateInit:t.dateInit,dateEnd:t.dateEnd,onDateValueChange:i,onDateInitChange:l,onDateEndChange:c,dateMode:"range",showAllTime:!1,clearable:!1},{id:"granularity",icon:"ChartPieSlice",label:n("inspector.health.filters.periodicity"),type:"radio",items:p,selectedValue:t.granularity,onValueChange:d,clearable:!1}];return u.length>0&&y.push({id:"accounts",icon:"Buildings",label:n("inspector.health.filters.accounts"),type:"checkbox",items:u,selectedValues:vt(t.accounts,u.map(E=>E.value),J()),onChange:m,searchable:!0,clearable:!0}),y},[n,t.dateValue,t.dateInit,t.dateEnd,t.granularity,t.accounts,i,l,c,p,d,u,m]),x=a.useMemo(()=>{const y=[{id:"date",label:Jt[t.dateValue]?n(Jt[t.dateValue]):t.dateValue},{id:"granularity",label:n(Jo[t.granularity])}];return u.length>0&&y.push({id:"accounts",label:Nt(n,t.accounts.length,u.length),...J()&&{icon:"User"}}),y},[t.dateValue,t.granularity,t.accounts,n]),w=a.useCallback(y=>{y==="accounts"&&s(E=>({...E,accounts:[]}))},[s]),b=a.useCallback(()=>{s(y=>({...y,accounts:[]}))},[t,s]);return e.jsx("div",{"data-testid":"devx-filter-bar",children:e.jsx(De,{filters:h,appliedFilters:x,onRemoveFilter:w,onClearAllFilters:b})})}function Xs({active:t,payload:s,label:n,formatValue:o,formatDate:r}){if(!t||!s?.length)return null;const i=c=>r?r(c):c,l=n==null?"":i(String(n));return e.jsxs("div",{className:"min-w-[10rem] rounded-md border border-border bg-background text-foreground shadow-md",children:[l&&e.jsx("div",{className:"border-b border-border px-3 py-2 text-sm font-bold text-foreground",children:l}),e.jsx("div",{className:"flex flex-col gap-2 px-3 py-2",children:s.map(c=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{"aria-hidden":!0,className:"size-2 shrink-0 rounded-full",style:{backgroundColor:c.color}}),e.jsx("span",{className:"flex-1 text-foreground",children:c.name}),e.jsx("span",{className:"font-medium tabular-nums text-foreground",children:o?o(c.value):c.value})]},c.dataKey))})]})}function Qo({x:t,y:s,payload:n,index:o,visibleTicksCount:r,formatDate:i}){const l=o===0,d=o===r-1?"end":"middle",u=l?"start":d;return e.jsx("g",{transform:`translate(${t},${s})`,children:e.jsx("text",{x:0,y:0,dy:16,textAnchor:u,fill:"var(--muted-foreground)",fontSize:12,children:i?i(n.value):n.value})})}function ea({x:t,y:s,payload:n,formatValue:o}){return e.jsx("g",{transform:`translate(${t},${s})`,children:e.jsx("text",{x:0,y:0,dy:4,textAnchor:"end",fill:"var(--muted-foreground)",fontSize:12,children:o?o(n.value):n.value})})}function ta({data:t,height:s=256,formatValue:n,formatDate:o,showXAxis:r=!1,showYAxis:i=!1,showGrid:l=!1,tooltipValueLabel:c="Value",className:d}){const u=`devx-area-fill-${a.useId().replace(/:/g,"")}`,m=t.length>1?[t[0].date,t[t.length-1].date]:[];return e.jsx("div",{className:P("w-full",d),style:{height:s},"data-testid":"devx-area-chart",children:e.jsx(kt,{width:"100%",height:"100%",children:e.jsxs(ho,{data:t,margin:{top:12,right:12,bottom:r?20:4,left:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:u,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"var(--primary)",stopOpacity:.28}),e.jsx("stop",{offset:"100%",stopColor:"var(--primary)",stopOpacity:0})]})}),l&&e.jsx(Ct,{strokeDasharray:"4 4",stroke:"var(--border)",vertical:!1}),r&&e.jsx(Et,{dataKey:"date",ticks:m,tick:e.jsx(Qo,{visibleTicksCount:m.length,formatDate:o}
1),tickLine:!1,axisLine:!1,interval:0}),i&&e.jsx(Tt,{tick:e.jsx(ea,{formatValue:n}),tickLine:!1,axisLine:!1,width:40,orientation:"left"}),e.jsx(Bs,{cursor:{stroke:"var(--primary)",strokeDasharray:"4 4"},content:e.jsx(Xs,{formatValue:n,formatDate:o})}),e.jsx(xo,{type:"monotone",dataKey:"value",name:c,stroke:"var(--primary)",fill:`url(#${u})`,strokeWidth:2})]})})})}function Js({title:t,info:s,children:n,className:o,testId:r}){const{t:i}=A();return e.jsxs("div",{"data-testid":r,className:P("flex flex-col overflow-hidden rounded-xl border border-border bg-card",o),children:[e.jsx("div",{className:"flex items-center justify-between gap-4 p-6",children:e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-4",children:[s?e.jsx(oe,{content:s,contentProps:{className:"max-w-xs"},children:e.jsx("button",{type:"button","aria-label":i("inspector.a11y.moreInfo","More info"),className:"shrink-0 text-muted-foreground transition-colors hover:text-foreground",children:e.jsx(F,{name:"Info",weight:"light",className:"size-4"})})}):null,e.jsx("h3",{className:"min-w-0 flex-1 truncate text-base font-semibold leading-6 text-card-foreground",children:t})]})}),e.jsx("div",{className:"flex flex-col gap-4 p-6",children:n})]})}function Zs({children:t,testId:s}){return e.jsx("p",{"data-testid":s,className:"text-3xl font-bold leading-none tracking-tight text-foreground",children:t})}const Zt=5;function Qs({height:t=292}){const s="bg-accent",n="border-border";return e.jsxs("div",{"data-testid":"devx-chart-skeleton",style:{height:t+30},children:[e.jsxs("div",{className:"flex",style:{height:t},children:[e.jsx("div",{className:"flex shrink-0 flex-col justify-between py-1 pr-3",children:Array.from({length:Zt},(l,c)=>`y-label-${c}`).map(l=>e.jsx("div",{className:P("h-3 w-7 rounded-sm",s)},l))}),e.jsxs("div",{className:"relative flex-1 overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 flex flex-col justify-between",children:Array.from({length:Zt},(l,c)=>`grid-line-${c}`).map(l=>e.jsx("div",{className:P("w-full border-b border-dashed",n)},l))}),e.jsxs("svg",{className:"absolute inset-0 h-full w-full",viewBox:"0 0 400 200",preserveAspectRatio:"none",children:[e.jsx("path",{d:"M0,180 C30,170 60,160 100,140 C140,120 160,130 200,100 C240,70 280,80 320,50 C350,30 380,20 400,10 L400,200 L0,200 Z",fill:"var(--accent)"}),e.jsx("path",{d:"M0,180 C30,170 60,160 100,140 C140,120 160,130 200,100 C240,70 280,80 320,50 C350,30 380,20 400,10",fill:"none",stroke:"var(--border)",strokeWidth:"2"})]}),e.jsx("div",{className:"absolute inset-0 overflow-hidden",children:e.jsx("div",{className:P("animate-shimmer absolute inset-0 bg-gradient-to-r","from-transparent via-border to-transparent")})})]})]}),e.jsxs("div",{className:"mt-3 flex justify-between pl-10",children:[e.jsx("div",{className:P("h-3 w-14 rounded-sm",s)}),e.jsx("div",{className:P("h-3 w-14 rounded-sm",s)})]})]})}const sa=[22,44,34,72,18,26,46].map((t,s)=>({day:`${s+1}`,ghost:t}));function en({height:t=256}){const{t:s}=A();return e.jsxs("div",{className:"relative","data-testid":"devx-empty-chart",children:[e.jsx("div",{className:"w-full opacity-40",style:{height:t},children:e.jsx(kt,{width:"100%",height:"100%",children:e.jsxs(fo,{data:sa,children:[e.jsx(Ct,{vertical:!1,stroke:"var(--border)",strokeDasharray:"3 3"}),e.jsx(Et,{dataKey:"day",tickLine:!1,axisLine:!1,tick:!1}),e.jsx(Tt,{domain:[0,100],ticks:[0,25,50,75,100],tickLine:!1,axisLine:!1,tick:!1,width:0}
1),e.jsx(go,{dataKey:"ghost",fill:"var(--muted-foreground)",fillOpacity:.3,barSize:12,isAnimationActive:!1})]})})}),e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:e.jsx(Y,{variant:"secondary",startIcon:"Clock",startIconProps:{weight:"light"},className:"rounded-md font-semibold",children:s("inspector.health.noData","No data available")})})]})}function tn(t,s,n="en-US"){const o=new Date(t);switch(s){case"hour":return o.toLocaleString(n,{hour:"numeric",minute:"2-digit",timeZone:"UTC"});case"day":case"week":return o.toLocaleDateString(n,{month:"short",day:"numeric",timeZone:"UTC"});case"month":return o.toLocaleDateString(n,{month:"short",year:"numeric",timeZone:"UTC"})}}function sn(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString()}function nn(t,s="en-US"){return t?new Date(t).toLocaleDateString(s,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit",hour12:!0}):""}const na={400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",408:"Request Timeout",409:"Conflict",410:"Gone",415:"Unsupported Media Type",422:"Unprocessable Entity",429:"Too Many Requests",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout"};function oa(t){return na[t]??"Error"}const Dt=90,Qt="DATE_RANGE_TOO_LARGE";function on(t,s,n=Dt){if(!t||!s)return!1;const o=s.getTime()-t.getTime();return o<0?!1:o/864e5>n}function _e(t){if(!t||typeof t!="object")return!1;const s=t,n=s.response?.data?.data?.code,o=s.response?.data?.code??s.data?.code??s.code;return n===Qt||o===Qt}const nt=256;function es({title:t,info:s,value:n,data:o,granularity:r,isLoading:i=!1,tooltipValueLabel:l,className:c}){const{i18n:d}=A(),u=o.length===0,m=()=>i?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-9 w-20 animate-pulse rounded bg-accent"}),e.jsx(Qs,{height:nt})]}):u?e.jsx(en,{height:nt}):e.jsxs(e.Fragment,{children:[e.jsx(Zs,{testId:"devx-stat-card-value",children:n.toLocaleString(d.language)}),e.jsx(ta,{data:o,height:nt,showXAxis:!0,showYAxis:!0,showGrid:!0,formatValue:sn,formatDate:p=>tn(p,r,d.language),tooltipValueLabel:l})]});return e.jsx(Js,{testId:"devx-stat-card",title:t,info:s,className:c,children:m()})}const aa=8;function an(t){return`var(--devx-chart-${t%aa+1})`}function ra({x:t,y:s,payload:n,index:o,visibleTicksCount:r,formatDate:i}){const l=o===0,d=o===r-1?"end":"middle",u=l?"start":d;return e.jsx("g",{transform:`translate(${t},${s})`,children:e.jsx("text",{x:0,y:0,dy:16,textAnchor:u,fill:"var(--muted-foreground)",fontSize:12,children:i?i(n.value):n.value})})}function ia({x:t,y:s,payload:n,formatValue:o}){return e.jsx("g",{transform:`translate(${t},${s})`,children:e.jsx("text",{x:0,y:0,dy:4,textAnchor:"end",fill:"var(--muted-foreground)",fontSize:12,children:o?o(n.value):n.value})})}function ca({data:t,lines:s,height:n=200,formatValue:o,formatDate:r,showXAxis:i=!0,showYAxis:l=!0,showGrid:c=!0,className:d}){const u=t.length>1?[t[0].date,t[t.length-1].date]:[];return e.jsx("div",{className:P("w-full",d),style:{height:n},"data-testid":"devx-multi-line-chart",children:e.jsx(kt,{width:"100%",height:"100%",children:e.jsxs(bo,{data:t,margin:{top:12,right:12,bottom:i?20:4,left:0},children:[c&&e.jsx(Ct,{strokeDasharray:"4 4",stroke:"var(--border)",vertical:!1}),i&&e.jsx(Et,{dataKey:"date",ticks:u,tick:e.jsx(ra,{visibleTicksCount:u.length,formatDate:r}),tickLine:!1,axisLine:!1,interval:0}),l&&e.jsx(Tt,{tick:e.jsx(ia,{formatValue:o}),tickLine:!1,axisLine:!1,width:40,orientation:"left"}),e.jsx(Bs,{cursor:{stroke:"var(--primary)",strokeDasharray:"4 4"},content:e.jsx(Xs,{formatValue:o,formatDate:r})}),s.map((m,p)=>e.jsx(yo,{type:"monotone",dataKey:m.key,name:m.label,stroke:m.color||an(p),strokeWidth:2,dot:!1,activeDot:{r:4}},m.key))]})})})}function la(t){const s=a.useRef(null),[n,o]=a.useState(!1);return a.useEffect(()=>{const r=s.current;if(!r)return;const i=()=>{o(r.scrollWidth>r.clientWidth)};if(i(),typeof ResizeObserver>"u")return;const l=new ResizeObserver(i);return l.observe(r),()=>l.disconnect()},[t]),{ref:s,isTruncated:n}}const da=2000012,Te=3;function ua({lines:t,className:s,values:n}){const{t:o}=A(),[r,i]=a.useState(!1),l=t.length>Te,c=t.length-Te;return e.jsxs("div",{className:P("flex flex-col gap-3",s),children:[e.jsx("div",{className:"flex flex-wrap gap-x-10 gap-y-3",children:t.slice(0,Te).map((d,u)=>e.jsx(ts,{line:d,index:u,value:n?.[d.key]},d.key))}),l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:P("grid transition-[grid-template-rows,opacity] duration-300 ease-in-out",r?"grid-rows-[1fr] opacity-100":"grid-rows-[0fr] opacity-0"),children:e.jsx("div",{className:"overflow-hidden",children:e.jsx("div",{className:"flex flex-wrap gap-x-10 gap-y-3",children:t.slice(Te).map((d,u)=>e.jsx(ts,{line:d,index:u+Te,value:n?.[d.key]},d.key))})})}),e.jsx("button",{type:"button",onClick:()=>i(d=>!d),className:"self-start text-sm font-medium transition-colors text-muted-foreground hover:text-foreground",children:r?o("inspector.health.showLess"):o("inspector.health.showMore",{count:c}
1)})]})]})}function ts({line:t,index:s,value:n}){const{i18n:o}=A(),{ref:r,isTruncated:i}=la(t.label);return e.jsxs("div",{className:"flex min-w-0 max-w-72 flex-col gap-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{"aria-hidden":!0,className:"size-2.5 shrink-0 rounded-full",style:{backgroundColor:t.color||an(s)}}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(oe,{content:t.label,show:i,triggerProps:{className:"block w-full"},contentProps:{style:{zIndex:da}},children:e.jsx("span",{ref:r,className:"block truncate text-sm text-muted-foreground",children:t.label})})})]}),n!==void 0&&e.jsx("p",{className:"text-xl font-semibold tracking-tight text-foreground",children:n.toLocaleString(o.language)})]})}const ot=320;function ma({total:t,data:s,lines:n,lineTotals:o,granularity:r,isLoading:i=!1,className:l}){const{t:c,i18n:d}=A(),u=s.length===0||n.length===0,m=()=>i?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-9 w-20 animate-pulse rounded bg-accent"}),e.jsx("div",{className:"flex gap-6",children:Array.from({length:3},(p,h)=>`legend-${h}`).map(p=>e.jsxs("div",{className:"flex flex-col gap-2 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-3 w-3 animate-pulse rounded-full bg-accent"}),e.jsx("div",{className:"h-3 w-24 animate-pulse rounded bg-accent"})]}),e.jsx("div",{className:"h-6 w-10 animate-pulse rounded bg-accent"})]},p))}),e.jsx(Qs,{height:ot})]}):u?e.jsx(en,{height:ot}):e.jsxs(e.Fragment,{children:[e.jsx(Zs,{testId:"devx-endpoints-total",children:t.toLocaleString(d.language)}),e.jsx(ua,{lines:n,values:o}),e.jsx(ca,{data:s,lines:n,height:ot,showXAxis:!0,showYAxis:!0,showGrid:!0,formatValue:sn,formatDate:p=>tn(p,r,d.language)})]});return e.jsx(Js,{testId:"devx-endpoints-chart",title:c("inspector.health.apiErrorsByEndpoint"),info:c("inspector.health.apiErrorsByEndpointInfo","Errors grouped by endpoint over the last 30 days."),className:l,children:m()})}function he({icon:t,title:s,description:n,action:o,className:r}){return e.jsxs("div",{className:P("flex flex-1 flex-col items-center justify-center gap-4 roun
1ded-lg bg-muted px-6 py-10 text-center",r),children:[e.jsx("div",{className:"flex size-10 items-center justify-center rounded-md bg-background",children:e.jsx(F,{name:t,className:"size-5 text-foreground"})}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:s}),n?e.jsx("p",{className:"text-xs text-muted-foreground",children:n}):null]}),o]})}function pa({error:t,isSelected:s,onSelect:n}){const{t:o,i18n:r}=A();return e.jsxs("li",{className:"relative",children:[e.jsxs("button",{type:"button","data-testid":"devx-error-item",onClick:()=>n?.(t.id),"aria-current":s?"true":void 0,"aria-label":o("inspector.health.errorDetail.open","{{type}} - {{detail}}, open details",{type:t.type,detail:t.detail}),className:P("block w-full cursor-pointer px-6 py-4 text-left transition-colors",s?"bg-accent":"hover:bg-accent/60"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-muted",children:e.jsx(F,{name:"XCircle",weight:"fill",className:"size-4 text-destructive"})}),e.jsxs("span",{className:"min-w-0 truncate text-sm font-medium text-foreground",children:[t.type," - ",t.detail]})]}),e.jsxs("div",{className:"mt-2 text-sm text-muted-foreground",children:[t.method," ",t.endpoint]}),e.jsx("div",{className:"mt-4 text-xs text-muted-foreground",children:nn(t.timestamp,r.language)})]}),s&&e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-y-0 right-0 w-1 bg-primary"})]})}function ha({currentPage:t,totalPages:s,onPrevious:n,onNext:o,onPageClick:r}){return e.jsx("div",{children:e.jsx(_t,{currentPage:t,totalPages:s,onPageClick:r,onClickNext:o,onClickPrev:n,maxVisiblePages:7})})}function xa({errors:t,className:s,selectedErrorId:n,onSelectError:o,totalPages:r=1,currentPage:i=1,onPageChange:l,isLoading:c=!1}){const{t:d}=A(),u=()=>{l?.(Math.max(i-1,1))},m=()=>{l?.(Math.min(i+1,r))},p=x=>{l?.(x)},h=()=>c?e.jsx("div",{className:"flex flex-col divide-y divide-border",children:Array.from({length:3},(x,w)=>`error-${w}`).map(x=>e.jsxs("div",{className:"flex items-start gap-3 px-6 py-4",children:[e.jsx(K,{className:"size-8 shrink-0 rounded-md"}),e.jsxs("div",{className:"flex flex-1 flex-col gap-2",children:[e.jsx(K,{className:"h-4 w-3/4 rounded"}),e.jsx(K,{className:"h-3 w-1/2 rounded"}),e.jsx(K,{className:"h-3 w-1/3 rounded"})]})]},x))}):t.length>0?e.jsx("ul",{className:"divide-y divide-border",children:t.map(x=>e.jsx(pa,{error:x,isSelected:n===x.id,onSelect:o},x.id))}):e.jsx("div",{"data-testid":"devx-error-list-empty",className:"p-4",children:e.jsx(he,{icon:"Heartbeat",title:d("inspector.health.noErrorsDetected","No errors detected"),description:d("inspector.health.noErrorsDetectedDescription","Your API requests are running smoothly. Any new errors will appear here.")})});return e.jsxs("div",{"data-testid":"devx-error-list",className:P("flex h-fit flex-col overflow-hidden rounded-xl border","border-border bg-card",s),children:[e.jsx("div",{className:"flex items-center justify-between px-6 py-5",children:e.jsx("h3",{className:"text-base font-semibold text-foreground",children:d("inspector.health.errors")})}),e.jsx(W,{}),h(),r>1&&e.jsxs(e.Fragment,{children:[e.jsx(W,{}),e.jsx("div",{className:"flex items-center justify-center px-6 py-3",children:e.jsx(ha,{currentPage:i,totalPages:r,onPrevious:u,onNext:m,onPageClick:p})})]})]})}const Lt="min(100%, 48rem)";function Xe({open:t,onClose:s,title:n,children:o,contentClassName:r,testId:i,buttons:l}){return e.jsx(St,{open:t,onClose:s,width:Lt,showFooter:!!l?.length,buttons:l,footerClassName:"min-h-16 gap-2 px-6 py-3",headerClassName:"min-h-16 gap-4 px-6 py-3",title:e.jsx("span",{className:"block truncate text-base font-semibold tracking-normal",children:n}),contentClassName:r,"data-testid":i,children:o})}const fa={200:"OK",201:"Created",202:"Accepted",204:"No content",400:"Bad request",401:"Unauthorized",402:"Declined",403:"Forbidden",404:"Not found",409:"Conflict",422:"Unprocessable entity",429:"Too many requests",500:"Server error",502:"Bad gateway",503:"Service unavailable",504:"Gateway t
1imeout"};function ga(t){return fa[t]}function ba(t){return t>=200&&t<300}function ye({code:t,className:s}){const{t:n}=A(),o=ba(t),r=ga(t),i=o?n("inspector.common.httpReason.ok","OK"):n("inspector.common.httpReason.error","Error"),l=r?n(`inspector.common.httpReason.${t}`,r):i;return e.jsxs("span",{className:P("inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-xs font-semibold",o?"bg-success/15 text-success":"bg-destructive/15 text-destructive",s),children:[e.jsx(F,{name:o?"CheckCircle":"Prohibit",weight:"fill",className:"size-4"}),t," ",l]})}function Je(){const{t}=A();return a.useCallback(async(s,n)=>{try{await navigator.clipboard.writeText(n),B.success(t("inspector.common.copySuccess","{{label}} copied successfully.",{label:s}))}catch{B.error(t("inspector.common.copyError","Could not copy {{label}}.",{label:s}))}},[t])}function Rt({label:t,value:s,className:n,testId:o,onCopy:r}){const{t:i}=A(),l=Je();return s?e.jsx("button",{type:"button",title:s,"data-testid":o,"aria-label":i("inspector.a11y.copyValueLabel","Copy {{label}} value",{label:t}),onClick:c=>{c.stopPropagation(),l(t,s),r?.()},className:P("min-w-0 truncate rounded-sm text-left text-sm text-foreground","hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",n),children:s}):e.jsx("span",{className:P("text-sm text-muted-foreground",n),"data-testid":o,children:"â"})}function Pe({label:t,value:s,className:n}){const{t:o}=A(),r=Je();return e.jsx("button",{type:"button","aria-label":o("inspector.a11y.copyLabel","Copy {{label}}",{label:t}),onClick:()=>r(t,s),className:P("text-muted-foreground transition-colors hover:text-foreground",n),children:e.jsx(F,{name:"CopySimple",className:"size-4"})})}function He({children:t,className:s}){return e.jsx("div",{className:P("grid grid-cols-2 gap-6",s),children:t})}function Q({label:t,copyValue:s,className:n,children:o}){return e.jsxs("div",{className:P("flex min-w-0 flex-col gap-2",n),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:t}),s!=null&&e.jsx(Pe,{label:t,value:s})]}),e.jsx("div",{className:"min-w-0 truncate text-sm text-muted-foreground",children:o})]})}const ya={GET:"bg-blue-600/15 text-blue-600",POST:"bg-yellow-600/15 text-yellow-600",PUT:"bg-orange-600/15 text-orange-600",PATCH:"bg-purple-600/15 text-purple-600",DELETE:"bg-destructive/15 text-destructive"};function ja(t){return ya[t?.toUpperCase()]??"bg-secondary text-secondary-foreground"}function ge({method:t,className:s}){return e.jsx("span",{className:P("inline-flex items-center rounded-md px-2 py-0.5 text-xs font-semibold",ja(t),s),children:t?.toUpperCase()})}function va({error:t}){const{t:s,i18n:n}=A(),o=t.endpoint.replace(/^\//,"");return e.jsxs("div",{className:"flex flex-col gap-6 rounded-lg border border-border p-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ge,{method:t.method}),e.jsx("span",{className:"min-w-0 truncate text-sm text-foreground",children:o})]}),e.jsx(W,{}),e.jsxs(He,{children:[e.jsx(Q,{label:s("inspector.health.errorDetail.creationDate","Creation date"),children:nn(t.timestamp,n.language)}),e.jsx(Q,{label:s("inspector.health.errorDetail.httpStatus","HTTP status"),children:e.jsx(ye,{code:t.httpStatus})})]}),e.jsxs(He,{children:[e.jsx(Q,{label:s("inspector.health.errorDetail.method","Method"),children:e.jsx(ge,{method:t.method})}),e.jsx(Q,{label:s("inspector.health.errorDetail.endpoint","Endpoint"),copyValue:o,children:o})]}),t.traceId&&e.jsx(Q,{label:s("inspector.health.errorDetail.xTraceId","X-Trace-Id"),copyValue:t.traceId,children:t.traceId})]})}function rn(t){return typeof t=="string"?JSON.stringify(t):t==null?"null":String(t)}function cn(t){return t!==null&&typeof t=="object"}function ln(t){return Array.isArray(t)?t.map(s=>[void 0,s]):Object.entries(t)}function dn({jsonKey:t,value:s,trailingComma:n}){if(!cn(s))return e.jsxs("div",{className:"flex gap-2 pl-4",children:[t!==void 0&&e.jsxs("span",{className:"shrink-0 text-blue-600",children:['"',t,'":']}),e.jsxs("span",{className:"break-all text-foreground",children:[rn(s),n?",":""]})]});const o=Array.isArray(s),r=ln(s);return e.jsxs("div",{className:"flex flex-col pl-4",children:[e.jsxs("div",{className:"flex gap-2",children:[t!==void 0&&e.jsxs("span",{className:"shrink-0 text-blue-600",children:['"',t,'":']}),e.jsx("span",{className:"text-foreground",children:o?"[":"{"})]}),r.map(([i,l],c)=>e.jsx(dn,{jsonKey:i,value:l,trailingComma:c<r.length-1},i??c)),e.jsxs("span",{className:"text-foreground",children:[o?"]":"}",n?",":""]})]})}function wa({data:t}){if(!cn(t))return e.jsx("div",{className:"text-sm leading-5 text-foreground",children:rn(t)});const s=Array.isArray(t),n=ln(t);return e.jsxs("div",{className:"flex flex-col text-sm leading-5",children:[e.jsx("span",{className:"text-foreground",children:s?"[":"{"}),n.map(([o,r],i)=>e.jsx(dn,{jsonKey:o,value:r,trailingComma:i<n.length-1},o??i)),e.jsx("span",{className:"text-foreground",children:s?"]":"}"})]})}function $e({title:t,data:s,testId:n}
1){return e.jsxs("div",{className:"flex flex-col gap-4 rounded-lg border border-border p-6","data-testid":n,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-sm font-semibold text-foreground",children:t}),e.jsx(Pe,{label:t,value:JSON.stringify(s,null,2)})]}),e.jsx(wa,{data:s})]})}function Na({requestBody:t,responseBody:s}){const{t:n}=A(),o=[{id:"response",label:e.jsx("span",{"data-testid":"devx-tab-response",children:n("inspector.health.errorDetail.responseBody","Response body")}),content:e.jsx($e,{title:n("inspector.health.errorDetail.responseBody","Response body"),data:s,testId:"devx-json-block"})},{id:"request",label:e.jsx("span",{"data-testid":"devx-tab-request",children:n("inspector.health.errorDetail.requestBody","Request body")}),content:e.jsx($e,{title:n("inspector.health.errorDetail.requestBody","Request body"),data:t,testId:"devx-json-block"})}];return e.jsx(Le,{tabs:o,defaultTab:0,navTabsClassName:"gap-2",contentClassName:"mt-4"})}function ka(t){const s=t.split("_").filter(Boolean);return s.length===0?t:s.map((n,o)=>o===0?n.charAt(0).toUpperCase()+n.slice(1):n).join(" ")}function Ca({error:t,onClose:s}){const{t:n}=A(),o=gt();return e.jsx(Xe,{open:t!==null,onClose:s,title:t?ka(t.type):"",testId:"devx-error-detail-panel",children:t&&e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(va,{error:t}),e.jsx(M,{variant:"outline",className:"w-full",onClick:()=>o("/developers/api-logs",{state:{apiLogsSearch:t.traceId}}),children:n("inspector.health.errorDetail.openRequestLogs","Open request logs")}),e.jsx(Na,{requestBody:t.requestBody,responseBody:t.responseBody})]})})}const Ea=[400,401,403,404,409,422,429,500,502,503,504],Ta=5,at=864e5,ss={dateValue:"TODAY",accounts:[],granularity:"hour"};function _a(t,s){const n=wt(t.accounts,s),o=new Date,r=t.dateEnd??o;let i;if(t.dateInit)i=t.dateInit;else switch(t.dateValue){case"LAST_3_DAYS":i=new Date(o.getTime()-3*at);break;case"LAST_7_DAYS":i=new Date(o.getTime()-7*at);break;case"LAST_30_DAYS":i=new Date(o.getTime()-30*at);break;case"THIS_MONTH":i=new Date(o.getFullYear(),o.getMonth(),1);break;default:i=new Date(o.getFullYear(),o.getMonth(),o.getDate());break}return{start_date:i.toISOString(),end_date:r.toISOString(),timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,accounts:n.length>0?n:void 0,granularity:t.granularity}}function ns(t){return t?.map(s=>({date:s.timestamp,value:s.count}))??[]}function Sa(t){if(!t||t.length===0)return{chartData:[],lines:[],totals:{}};const s=t.map((i,l)=>({key:`ep${l}`,label:i.url})),n={};t.forEach((i,l)=>{n[`ep${l}`]=i.count});const o=new Map;return t.forEach((i,l)=>{for(const c of i.time_series){const d=o.get(c.timestamp),u=d??{date:c.timestamp};d||(t.forEach((m,p)=>{u[`ep${p}`]=0}),o.set(c.timestamp,u)),u[`ep${l}`]=c.count}}),{chartData:Array.from(o.values()).sort((i,l)=>new Date(i.date).getTime()-new Date(l.date).getTime()),lines:s,totals:n}}function os(t){if(t==null)return{};if(typeof t!="string")return t??{};try{return JSON.parse(t||"{}")}catch{return{}}}function Aa(t,s){const n=t.error;return{type:n?.type??`${s}`,detail:n?.message??n?.code??oa(s)}}function Ia(t,s){const n=os(t.response_body),o=os(t.request_body),r=t.status_code??0,{type:i,detail:l}=Aa(n,r);return{id:`${t.trace_id??"log"}-${s}`,type:i,detail:l,method:t.method??"GET",endpoint:t.request_uri??"",timestamp:t.created_at??"",httpStatus:r,traceId:t.trace_id??"",requestBody:o,responseBody:n}}function Da(){const{t}=A(),[s,n]=a.useState(ss),[o,r]=a.useState(0),[i,l]=a.useState(null);Re(()=>n(S=>({...S,accounts:ss.accounts})));const c=At({roles:[],environmentCodes:!0}),d=a.useMemo(()=>_a(s,c),[s,c]);a.useEffect(()=>{r(0),l(null)},[d]);const u=lo(d),m=uo(d),p=mo(d),h=Gs({...d,status_codes:Ea,page:o,size:Ta}),x=a.useMemo(()=>ns(u.data?.time_series),[u.data]),w=a.useMemo(()=>ns(m.data?.time_series),[m.data]),b=a.useMemo(()=>Sa(p.data?.endpoints),[p.data]),y=a.useMemo(()=>(h.data?.data??[]).map(Ia),[h.data]),E=a.useMemo(()=>y.map(({id:S,type:z,detail:k,method:j,endpoint:_,timestamp:D})=>({id:S,type:z,detail:k,method:j,endpoint:_,timestamp:D})),[y]),g=a.useMemo(()=>y.find(S=>S.id===i)??null,[y,i]),f=u.isError||m.isError||p.isError||h.isError,N=on(s.dateInit,s.dateEnd)||_e(u.error)||_e(m.error)||_e(p.error)||_e(h.error),C=a.useCallback(()=>{u.refetch(),m.refetch(),p.refetch(),h.refetch()},[u,m,p,h]),T=a.useCallback(S=>{r(S-1),l(null)},[]),I=a.useCallback(()=>l(null),[]);return e.jsxs("div",{className:"flex flex-col gap-6","data-testid":"health-tab",children:[e.jsx(Zo,{filters:s,onFiltersChange:n}),N&&e.jsx("div",{"data-testid":"devx-range-too-large",className:"flex flex-col items-center justify-center px-6 py-12",children:e.jsx("span",{className:"text-center text-sm text-muted-foreground",children:t("inspector.common.dateRangeTooLarge",{maxDays:Dt})})}),f&&!N&&e.jsxs("div",{"data-testid":"devx-health-error",className:"flex flex-col items-center justify-center gap-3 px-6 py-12",children:[e.jsx("span",{className:"text-center text-sm text-muted-foreground",children:t("inspector.health.errorLoading")}),e.jsx("div",{children:e.jsx(M,{variant:"outline",size:"sm",startIcon:"ArrowsClockwise",onClick:C,children:t("inspector.health.retry")})})]}),!f&&!N&&e.jsx("div",{className:"@container/health min-w-0",children:e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-6 @lg/health:grid-cols-2","data-testid":"devx-health-chart-row",children:[e.jsx(es,{title:t("inspector.health.apiRequests"),info:t("inspector.health.apiRequestsInfo","Total API requests to your Yuno integration in the selected time range."),value:u.data?.total??0,data:x,granularity:s.granularity,isLoading:u.isLoading,tooltipValueLabel:t("inspector.health.requestsLabel","Requests")}),e.jsx(es,{title:t("inspector.health.apiErrors"),info:t("inspector.health.apiErrorsInfo","Total 4xx and 5xx responses returned by your integration."),value:m.data?.total??0,data:w,granularity:s.granularity,isLoading:m.isLoading,tooltipValueLabel:t("inspector.health.errorsLabel","Errors")})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-6 @4xl/health:grid-cols-[minmax(0,1fr)_412px]","data-testid":"devx-health-breakdown-row",children:[e.jsx(ma,{total:p.data?.total??0,data:b.chartData,lines:b.lines,lineTotals:b.totals,granularity:s.granularity,isLoading:p.isLoading}),e.jsx(xa,{errors:E,selectedErrorId:g?.id,onSelectError:l,totalPages:h.data?.total_pages??1,currentPage:o+1,onPageChange:T,isLoading:h.isLoading})]})]})}),e.jsx(Ca,{error:g,onClose:I})]})}function La(){return bt()}function Ra(){const t=localStorage.getItem("user");if(!t)return"";try{const s=JSON.parse(t);return s?.code||s?.value?.code||""}catch{return""}}function un(){const t=La(),s=Ra(),{statusPermission:n,accountsWithPermissions:o}=Ve("view_account_keys"),r=n===Se.ALLOWED,i=Ve("manage_customized_keys");return{accountCode:t,userCode:s,isAllowed:r,statusPermission:n,accountsWithKeysPermission:o??[],accountsWithManageKeysPermission:i.accountsWithPermissions??[],isManageKeysPermissionLoading:i.statusPermission===Se.LOADING}}const mn="â¢".repeat(28),Pa=!1,Oa=/^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/,Ma=[{value:"NOW",labelKey:"inspector.authentication.roll.now"},{value:"ONE_HOUR",labelKey:"inspector.authentication.roll.oneHour"},{value:"TWENTY_FOUR_HOURS",labelKey:"inspector.authentication.roll.twentyFourHours"},{value:"THREE_DAYS",labelKey:"inspector.authentication.roll.threeDays"},{value:"THIRTY_DAYS",labelKey:"inspector.authentication.roll.thirtyDays"}];function Ua(t){const[s,n]=a.useState(""),[o,r]=a.useState(""),[i,l]=a.useState(!1),[c,d]=a.use
1State(!1),u=jo(),m=vo(),p=wo(),h=No(),x=ko(),[w,b]=a.useState(null),y=a.useRef(0);a.useEffect(()=>{y.current+=1,n(""),r(""),l(!1),d(!1),b(null)},[t]);const E=c,g=c&&!0,f=u.isPending&&!w||h.isPending,N=a.useCallback(()=>{const j=y.current;u.mutate({accountCode:t},{onSuccess:_=>{y.current===j&&b(_??null)}})},[u,t]),C=a.useCallback((j,_)=>{n(j),r(_),l(!0),d(!0)},[]),T=a.useCallback(()=>{l(j=>!j)},[]),I=a.useCallback(async j=>{const _=y.current,D=await m.mutateAsync({accountCode:t,stepUpTicket:j});y.current===_&&(n(D?.public_api_key||""),r(D?.private_secret_key||""),l(!0),d(!0))},[m,t]),S=a.useCallback(async(j,_)=>{const D=y.current,v=await h.mutateAsync({password:j.password,otp:j.otp,mfaToken:j.mfaToken,stepUpTicket:_,accountCode:t});if(y.current===D){n(v?.public_api_key||""),r(v?.private_secret_key||""),l(!0),d(!0);try{await x.mutateAsync({note:"",password:j.password,accountCode:t})}catch{}N()}},[h,x,N,t]),z=a.useCallback(async(j,_)=>{await x.mutateAsync({note:j,password:_,accountCode:t}),N()},[x,N,t]),k=a.useCallback(async j=>{const _=y.current;await p.mutateAsync({password:j.password,otp:j.otp,mfaToken:j.mfaToken,accountCode:t}),y.current===_&&N()},[p,N,t]);return a.useMemo(()=>({metadata:w,publicKey:s,privateKey:o,isLoading:f,isRevealed:i,isRevealedThisSession:c,setRevealedKeys:C,toggleReveal:T,revealWithTicket:I,rollKeys:S,updateNote:z,markRevealed:k,isShowDisabled:E,canToggleReveal:g,fetchMetadata:N}),[w,s,o,f,i,c,C,T,I,S,z,k,E,g,N])}function as(t){return{name:t.name,apply_to_all_accounts:t.applyToAllAccounts,account_codes:t.accountCodes,users_to_be_assigned:t.usersToBeAssigned,products:[],product_permissions:t.productPermissions.flatMap(s=>s.permission==="READ_WRITE"?[{product:s.product,permission:"READ"},{product:s.product,permission:"WRITE"}]:[{product:s.product,permission:s.permission}])}}function za(t){const[s,n]=a.useState({}),[o,r]=a.useState({}),i=t.join(","),l=a.useRef(0);a.useEffect(()=>{l.current+=1,n({}),r({})},[i]);const c=qo(t),d=Co(),u=Eo(),m=To(),p=_o(),h=So(),x=Bo(),w=$o(),b=Wo(),y=a.useMemo(()=>{const j=c.data;return!j||!Array.isArray(j)?[]:j.map(_=>({code:_.code,name:_.name,credential:_.credential,userCode:_.user_code,createdAt:_.created_at??"",lastUsed:_.last_used??void 0,expiredAt:_.expired_at??void 0,note:_.note,isRevealed:!1,alreadyBeenShown:_.token_revealed_at!=null,applyToAllAccounts:_.apply_to_all_accounts??!1,accounts:_.details?.accounts??[],assignedUsers:_.details?.assigned_users??[],productPermissions:_.details?.product_permissions??[]}))},[c.data]),E=a.useMemo(()=>{const j=x.data||[];return Array.isArray(j)?j.filter(_=>`${_.first_name??""}${_.last_name??""}`.trim().length>0):[]},[x.data]),g=a.useMemo(()=>{const j=w.data;return Array.isArray(j)?j:[]},[w.data]),f=a.useMemo(()=>{const j=b.data;return Array.isArray(j)?j.map(_=>({key:_.description??_.key,name:_.description??_.key})):[]},[b.data]),N=c.isLoading||u.isPending||p.isPending,C=a.useCallback(async(j,_,D)=>{const v=l.current,L=await d.mutateAsync({code:j,password:_.password,otp:_.otp,mfaToken:_.mfaToken,stepUpTicket:D});if(l.current!==v)return"";const O=L?.private_secret_key||"",V=L?.public_api_key||"";return n(de=>({...de,[j]:O})),V&&r(de=>({...de,[j]:V})),c.refetch(),O},[d,c]),T=a.useCallback(async j=>{await p.mutateAsync({payload:as(j)}),c.refetch()},[p,c]),I=a.useCallback(async(j,_)=>{await h.mutateAsync({payload:{name:_.name,products:[],product_permissions:as(_).product_permissions},code:j}),c.refetch()},[h,c]),S=a.useCallback(async j=>{await u.mutateAsync({code:j}),c.refetch()},[u,c]),z=a.useCallback(async(j,_,D)=>{const v=l.current,L=await m.mutateAsync({payload:{expiration_in:D},code:j,password:_.password});l.current===v&&(L?.private_secret_key&&n(O=>({...O,[j]:L.private_secret_key})),L?.public_api_key&&r(O=>({...O,[j]:L.public_api_key})),c.refetch())},[m,c]),k=a.useCallback(()=>{c.refetch()},[c]);return a.useMemo(()=>({keys:y,isLoading:N,availableMembers:E,availableAccounts:g,availableProducts:f,revealedTokens:s,revealedCredentials:o,revealToken:C,createKey:T,updateKey:I,deleteKey:S,rollKey:z,refetch:k}),[y,N,E,g,f,s,o,C,T,I,S,z,k])}function Fa(t){return!t||t.trim()===""?[]:t.split(",").map(s=>
1s.trim()).filter(Boolean)}function Ka(){const{t}=A(),s=Ho(),n=Yo(),o=a.useMemo(()=>Fa(s.data?.ip_address),[s.data]),r=a.useCallback(()=>{s.refetch()},[s]),i=a.useCallback(async c=>{try{await n.mutateAsync({ip_address:c.join(",")}),s.refetch()}catch{throw B.error(t("inspector.authentication.allowedIps.saveError")),new Error("Failed to save allowed IPs")}},[n,s,t]),l=s.data?.isError===!0;return a.useMemo(()=>({ips:o,isLoading:s.isFetching&&(s.data===void 0||l),isError:!s.isFetching&&l,isSaving:n.isPending,fetchIps:r,saveIps:i}),[o,s.data,s.isFetching,l,n.isPending,r,i])}function rs(t){return t??{}}function pn(t){const s=rs(t);return rs(s.response).status??s.status}function Va(t){const s=t??{};if(s.is_sso===!0)return!0;const n=(s.auth_method??"").toLowerCase();return n!==""&&n!=="password"&&n!=="unknown"}function Ba(t,s){if(!t)return!1;const n=[t.code,t.account_code_live,t.account_code_testing].filter(Boolean);return n.includes(s.code_live)||n.includes(s.code_testing)}function Ha(t,s){return(t.accounts??[]).every(n=>s.some(o=>Ba(o,n)))}function $a(t){const s=pn(t);return s===403?"permission":s===400||s===401?"credential":"unknown"}function ee({className:t,containerClassName:s,...n}){return e.jsx("div",{className:P("relative w-full overflow-x-auto rounded-lg border border-border bg-background",s),children:e.jsx("table",{className:P("w-full caption-bottom text-sm",t),...n})})}function te({className:t,...s}){return e.jsx("thead",{className:P("[&_tr]:border-b [&_tr]:border-border",t),...s})}function se({className:t,...s}){return e.jsx("tbody",{className:P("[&_tr:last-child]:border-0",t),...s})}function q({className:t,...s}){return e.jsx("tr",{className:P("border-b border-border transition-colors hover:bg-muted/40 data-[state=selected]:bg-muted",t),...s})}function $({className:t,...s}){return e.jsx("th",{className:P("h-10 bg-sidebar px-2 text-left align-middle text-sm font-medium text-muted-foreground first:pl-6 last:pr-6",t),...s})}function U({className:t,...s}){return e.jsx("td",{className:P("h-13 p-2 text-left align-middle text-sm text-foreground first:pl-6 last:pr-6",t),...s})}function Pt({title:t,description:s,action:n,children:o,testId:r}){return e.jsxs("section",{className:"flex flex-col gap-6 rounded-xl border border-border bg-card p-6","data-testid":r,children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[e.jsx("h2",{className:"min-w-0 truncate text-base font-semibold text-foreground",children:t}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s})]}),n&&e.jsx("div",{className:"shrink-0",children:n})]}),o]})}function qa(){const{accountCode:t,userCode:s}=un();return{accountId:t,userId:s}}function is({label:t,value:s}){const n=s??"";return e.jsxs(q,{className:"group","data-testid":"account-ids-row",children:[e.jsx(U,{className:"font-medium",children:t}),e.jsx(U,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Rt,{label:t,value:n}),n.length>0&&e.jsx(Pe,{label:t,value:n,className:"flex size-6 shrink-0 items-center justify-center rounded-sm opacity-0 transition-opacity focus-visible:opacity-100 group-hover:opacity-100"})]})})]})}function Wa({accountCode:t}){const{t:s}=A(),{accountId:n,userId:o}=qa(),r=t||n,i=!r&&!o;return e.jsx(Pt,{title:s("inspector.authentication.accountKeys.title"),description:s("inspector.authentication.accountKeys.description"),testId:"account-ids-card",children:i?e.jsx("div",{"data-testid":"account-ids-empty",children:e.jsx(he,{icon:"IdentificationCard",title:s("inspector.authentication.accountKeys.emptyTitle","No account IDs yet"),description:s("inspector.authentication.accountKeys.emptyDescription","Account and user identifiers will appear here once your account is set up.")})}):e.jsxs(ee,{className:"table-fixed",children:[e.jsx(te,{children:e.jsxs(q,{children:[e.jsx($,{className:"w-[400px]",children:s("inspector.authentication.accountKeys.table.name")}),e.jsx($,{children:s("inspector.authentication.accountKeys.table.value")})]})}),e.jsxs(se,{children:[e.jsx(is,{label:s("inspector.authentication.accountKeys.accountCode"),value:r}),e.jsx(is,{label:s("inspector.authentication.accountKeys.userCode"),value:o})]})]})})}const rt=4;function Ya(t=200){const s=a.useRef(null),n=a.useRef(null),[o,r]=a.useState(!1),[i,l]=a.useState({top:0,left:0}),c=a.useCallback(()=>
1{if(!s.current)return;const p=s.current.getBoundingClientRect(),h=n.current?.offsetHeight??t;window.innerHeight-p.bottom<h+rt*2?l({top:p.top-h-rt,left:p.left}):l({top:p.bottom+rt,left:p.left})},[t]);a.useEffect(()=>{if(!o)return;c();const p=x=>{n.current&&!n.current.contains(x.target)&&!s.current?.contains(x.target)&&r(!1)},h=s.current?.closest(".overflow-auto, .overflow-y-auto");return document.addEventListener("mousedown",p),h?.addEventListener("scroll",c),window.addEventListener("scroll",c,!0),window.addEventListener("resize",c),()=>{document.removeEventListener("mousedown",p),h?.removeEventListener("scroll",c),window.removeEventListener("scroll",c,!0),window.removeEventListener("resize",c)}},[o,c]);const d=a.useCallback(()=>r(!0),[]),u=a.useCallback(()=>r(!1),[]),m=a.useCallback(()=>r(p=>!p),[]);return{anchorRef:s,popoverRef:n,isOpen:o,position:i,open:d,close:u,toggle:m}}const Ot=3e4;function hn(t,s,n=Ot){const o=a.useRef(null),r=a.useRef(s);r.current=s;const i=a.useCallback(()=>{o.current&&(clearTimeout(o.current),o.current=null)},[]),l=a.useCallback(()=>{t&&(i(),o.current=setTimeout(()=>r.current(),n))},[t,n,i]);return a.useEffect(()=>(t?l():i(),i),[t,l,i]),l}function cs({label:t,value:s,isRevealed:n,isBlurred:o}){const r=n&&!!s;return e.jsxs(q,{className:"group","data-testid":"org-key-row",children:[e.jsx(U,{className:"font-medium",children:t}),e.jsx(U,{children:r?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Rt,{label:t,value:s,testId:"org-key-token"}),e.jsx(Pe,{label:t,value:s,className:"flex size-6 shrink-0 items-center justify-center rounded-sm opacity-0 transition-opacity focus-visible:opacity-100 group-hover:opacity-100"})]}):e.jsx("span",{className:P("inline-block min-w-0 truncate align-middle text-sm tracking-widest text-foreground transition-[filter] duration-150",o&&"select-none blur-sm"),"data-testid":"org-key-token",children:mn})})]})}function Ga({onRollChoice:t,onAddNote:s,note:n,isRevealed:o,canRoll:r}){const{t:i}=A(),{popoverRef:l,isOpen:c,position:d,close:u}=Ya(),m=()=>{u(),t()};return e.jsxs("div",{className:"flex items-center gap-2",children:[Pa,n?e.jsx(oe,{content:n,children:e.jsx(M,{variant:"outline",size:"sm",startIcon:"Note","data-testid":"org-keys-view-note",children:i("inspector.authentication.organizationKeys.viewNote")})}):e.jsx(M,{variant:"outline",size:"sm",startIcon:"NotePencil",onClick:s,disabled:!o,"data-testid":"org-keys-add-note",children:i("inspector.authentication.organizationKeys.addNote")}),c&&jt.createPortal(e.jsxs("div",{ref:l,style:{top:d.top,left:d.left},className:"fixed z-[2000011] w-80 overflow-clip rounded-md border shadow-md border-border bg-card",children:[e.jsx("div",{className:"px-4 py-4",children:e.jsx("p",{className:"text-sm font-semibold text-foreground",children:i("inspector.authentication.tam.dropdownTitle")})}),e.jsx("div",{className:"h-px bg-muted"}),e.jsxs("button",{type:"button",onClick:m,className:"flex w-full items-center gap-4 p-4 text-left transition-colors hover:bg-accent",children:[e.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-full bg-muted",children:e.jsx(F,{name:"ArrowsClockwise",size:"sm",className:"text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:i("inspector.authentication.tam.continueRoll")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("inspector.authentication.tam.continueRollDescription")})]})]})]}),document.body)]})}function Xa({publicKey:t,privateKey:s,isRevealed:n,isShowDisabled:o,isLoading:r,note:i,onReveal:l,onRoll:c,onAddNote:d,canReveal:u,canToggleReveal:m=!1,onAutoHide:p}){const{t:h}=A(),[x,w]=a.useState(!1),[b,y]=a.useState(!1),E=hn(n,()=>p?.(),Ot),g=!n&&(m||!o),f=x||b,N=!r&&n&&!t&&!s,C=()=>e.jsxs("div",{className:"relative",onMouseEnter:()=>g&&w(!0),onMouseLeave:()=>w(!1),onMouseMove:n?E:void 0,children:[e.jsxs(ee,{className:"table-fixed",children:[e.jsx(te,{children:e.jsxs(q,{children:[e.jsx($,{className:"w-[400px]",children:h("inspector.authentication.organizationKeys.table.name")}),e.jsx($,{children:h("inspector.authentication.organizationKeys.table.token")})]})}),e.jsxs(se,{children:[e.jsx(cs,{label:h("inspector.authentication.organizationKeys.publicKey"),value:t,isRevealed:n,isBlurred:g&&f}),e.jsx(cs,{label:h("inspector.authentication.organizationKeys.privateKey"),value:s,isRevealed:n,isBlurred:g&&f})]})]}),g&&e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 top-10 z-10 flex items-center justify-center",children:e.jsxs("div",{className:P("pointer-events-auto flex flex-col items-center gap-2 transition-opacity duration-200",f?"opacity-100":"opacity-0"),onFocus:()=>y(!0),onBlur:()=>y(!1),"data-testid":"org-keys-reveal-affordance",children:[e.jsx(M,{variant:"outline",size:"sm",onClick:()=>u&&l(),disabled:!u,startIcon:"Eye",className:"shadow-sm","data-testid":"org-keys-reveal",children:h("inspector.authentication.organizationKeys.showTokens")}),!u&&e.jsx("span",{className:"max-w-[420px] rounded px-2 py-1 text-center text-xs bg-foreground text-background","data-testid":"org-keys-no-permission-hint",children:h("inspector.authentication.organizationKeys.noPermissionHint")})]})})]}),T=()=>r?e.jsx("div",{className:"h-[120px] animate-pulse rounded-lg border border-border bg-accent","data-testid":"org-keys-skeleton"}):N?e.jsx("div",{"data-testid":"org-keys-empty",children:e.jsx(he,{icon:"Key",title:h("inspector.authentication.organizationKeys.emptyTitle","No organization keys yet"),description:h("inspector.authentication.organizationKeys.emptyDescription","Public and secret API keys for your organization will appear here once generated.")})}):e.jsxs(e.Fragment,{children:[C(),e.jsx(Ga,{onRollChoice:c,onAddNote:d,note:i,isRevealed:n,canRoll:u})]});return e.jsx(Pt,{title:h("inspector.authentication.organizationKeys.title"),description:h("inspector.authentication.organizationKeys.description"),testId:"organization-keys-card",children:T()})}const Ja=()=>!0;function Za(t){const s=new Date(t).getTime()-Date.now();if(s<=0)return"expired";const n=Math.ceil(s/6e4);return n<60?`${n}m`:`${Math.ceil(n/60)}h`}function ls({value:t,label:s,visible:n,blurred:o,onCopy:r}){return n?e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(Rt,{label:s,value:t,onCopy:r,testId:"customized-key-token"}),e.jsx(Pe,{label:s,value:t,className:"flex size-6 shrink-0 items-center justify-center rounded-sm opacity-0 transition-opacity focus-visible:opacity-100 group-hover:opacity-100"})]}):e.jsx("span",{className:P("inline-block min-w-0 truncate align-middle text-sm tracking-widest text-foreground transition-[filter] duration-150",o&&"select-none blur-sm"),"data-testid":"customized-key-token",children:mn})}
1function Qa({item:t,isSelected:s,revealedToken:n,revealedCredential:o,onSelect:r,onViewDetails:i,onEdit:l,onRoll:c,onDelete:d,onRevealToken:u,canManage:m}){const{t:p}=A(),[h,x]=a.useState(!1),[w,b]=a.useState(!1),[y,E]=a.useState(!1),g=!!n,f=g&&!y;a.useEffect(()=>{g&&E(!1)},[g]);const N=hn(f,()=>E(!0),Ot),C=(h||w)&&!f,T=D=>{if(D.stopPropagation(),g){E(!1);return}u(t)},I=D=>{D.stopPropagation(),f&&N()},S=o||t.credential,z=n||"",k=t.expiredAt&&new Date(t.expiredAt).getTime()>Date.now(),j=p("inspector.authentication.customizedKeys.menu.noManagePermission","You don't have permission to manage this API key. You need API key management access on every account it is assigned to. Contact an admin of your organization."),_=[{key:"view",name:p("inspector.authentication.customizedKeys.menu.viewDetails"),icon:"Eye",allowed:!0,handleClick:()=>i(t)},{key:"edit",name:p("inspector.authentication.customizedKeys.menu.edit"),icon:"PencilSimple",allowed:m,message:j,handleClick:()=>l(t)},{key:"roll",name:p("inspector.authentication.customizedKeys.menu.roll"),icon:"ArrowsClockwise",allowed:m,message:j,handleClick:()=>c(t)},{key:"delete",name:p("inspector.authentication.customizedKeys.menu.delete"),icon:"Trash",allowed:m,message:j,handleClick:()=>d(t)}];return e.jsxs(q,{onClick:()=>r(t),"data-testid":"customized-key-row",className:P("group relative cursor-pointer",s&&"bg-muted"),onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),onMouseMove:f?N:void 0,children:[e.jsx(U,{className:"font-medium",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(F,{name:"Key",size:"sm",className:P("shrink-0",s?"text-primary-500":"text-muted-foreground")}),e.jsx("span",{className:"min-w-0 truncate",children:t.name})]})}),e.jsx(U,{children:e.jsx("div",{onClick:I,children:e.jsx(ls,{value:S,label:p("inspector.authentication.customizedKeys.publicTokenOf","{{name}} public token",{name:t.name}),visible:f,blurred:C,onCopy:N})})}),e.jsxs(U,{children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",onClick:I,children:[e.jsx(ls,{value:z,label:p("inspector.authentication.customizedKeys.privateTokenOf","{{name}} private token",{name:t.name}),visible:f,blurred:C,onCopy:N}),k&&t.expiredAt&&e.jsx(Y,{variant:"warning",className:"shrink-0",children:p("inspector.authentication.customizedKeys.expiresIn",{value:Za(t.expiredAt)})})]}),!f&&e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 right-0 flex items-center justify-center",children:e.jsx("div",{className:P("flex items-center transition-opacity duration-200",C?"pointer-events-auto opacity-100":"opacity-0"),onFocus:()=>b(!0),onBlur:()=>b(!1),"data-testid":"customized-key-reveal-affordance",children:e.jsx(M,{variant:"outline",size:"sm",startIcon:"Eye",className:"shadow-sm",onClick:T,"aria-label":p("inspector.a11y.showTokensFor","Show tokens for {{name}}",{name:t.name}),"data-testid":"customized-key-reveal",children:p("inspector.authentication.organizationKeys.showTokens")})})})]}),e.jsx(U,{children:e.jsx("div",{className:"flex items-center justify-end",onClick:D=>D.stopPropagation(),children:e.jsx(It,{options:{actions:_},ariaLabel:p("inspector.a11y.keyActions","More actions for {{name}}",{name:t.name})})})})]})}function er({keys:t,selectedKeyCode:s,onSelectKey:n,onViewDetails:o,onEdit:r,onRoll:i,onDelete:l,onRevealToken:c,canManage:d=Ja,isLoading:u,revealedTokens:m,revealedCredentials:p}){const{t:h}=A();return u?e.jsx("div",{className:"flex flex-col gap-2 rounded-lg border border-border p-4","data-testid":"customized-keys-loading",children:[1,2,3].map(x=>e.jsx("div",{className:"h-10 animate-pulse rounded bg-accent"},x))}):t.length===0?e.jsx("div",{"data-testid":"customized-keys-empty",children:e.jsx(he,{icon:"Key",title:h("inspector.authentication.customizedKeys.emptyTitle"),description:h("inspector.authentication.customizedKeys.emptyDescription")})}):e.jsxs(ee,{className:"table-fixed",children:[e.jsx(te,{children:e.jsxs(q,{children:[e.jsx($,{className:"w-[280px]",children:h("inspector.authentication.customizedKeys.table.name")}),e.jsx($,{children:h("inspector.authentication.customizedKeys.table.token")}),e.jsx($,{children:h("inspector.authentication.customizedKeys.table.privateToken")}),e.jsx($,{className:"w-[80px]"})]})}),e.jsx(se,{children:t.map(x=>e.jsx(Qa,{item:x,isSelected:x.code===s,revealedToken:m[x.code],revealedCredential:p[x.code],onSelect:n,onViewDetails:o,onEdit:r,onRoll:i,onDelete:l,onRevealToken:c,canManage:d(x)},x.code))})]})}function tr({keys:t,selectedKeyCode:s,isLoading:n,revealedTokens:o,revealedCredentials:r,onCreateKey:i,onSelectKey:l,onViewDetails:c,onEditKey:d,onRollKey:u,onDeleteKey:m,onRevealToken:p,canManageKey:h}){const{t:x}=A();return e.jsx(Pt,{title:x("inspector.authentication.customizedKeys.title"),description:x("inspector.authentication.customizedKeys.description"),testId:"customized-keys-section",action:e.jsx(M,{size:"sm",onClick:i,"data-testid":"customized-keys-create",children:x("inspector.authentication.customizedKeys.create")}),children:e.jsx(er,{keys:t,selectedKeyCode:s,isLoading:n,revealedTokens:o,revealedCredentials:r,onSelectKey:l,onViewDetails:c,onEdit:d,onRoll:u,onDelete:m,onRevealToken:p,canManage:h})})}function sr({products:t,value:s,onChange:n,disabled:o=!1}){const{t:r}=A(),[i,l]=a.useState(""),c=a.useMemo(()=>
1{if(!i.trim())return t;const g=i.toLowerCase();return t.filter(f=>f.name.toLowerCase().includes(g))},[t,i]),d=g=>s.some(f=>f.product===g&&(f.permission==="READ"||f.permission==="READ_WRITE")),u=g=>s.some(f=>f.product===g&&(f.permission==="WRITE"||f.permission==="READ_WRITE")),m=g=>d(g)||u(g),p=(g,f)=>{const N=s.filter(C=>C.product!==g);f&&N.push({product:g,permission:"READ_WRITE"}),n(N)},h=(g,f)=>{const N=f==="READ"?!d(g):d(g),C=f==="WRITE"?!u(g):u(g),T=s.filter(I=>I.product!==g);N&&C?T.push({product:g,permission:"READ_WRITE"}):N?T.push({product:g,permission:"READ"}):C&&T.push({product:g,permission:"WRITE"}),n(T)},x=c.length>0&&c.every(g=>m(g.key)),w=c.length>0&&c.every(g=>d(g.key)),b=c.length>0&&c.every(g=>u(g.key)),y=g=>{let f=[...s];for(const N of c)f=f.filter(C=>C.product!==N.key),g&&f.push({product:N.key,permission:"READ_WRITE"});n(f)},E=(g,f)=>{let N=[...s];for(const C of c){N=N.filter(S=>S.product!==C.key);const T=g==="READ"?f:d(C.key),I=g==="WRITE"?f:u(C.key);T&&I?N.push({product:C.key,permission:"READ_WRITE"}):T?N.push({product:C.key,permission:"READ"}):I&&N.push({product:C.key,permission:"WRITE"})}n(N)};return t.length===0?e.jsx("p",{className:"py-4 text-center text-xs text-muted-foreground",children:r("inspector.authentication.form.noProducts")}):e.jsxs("div",{className:"flex flex-col gap-4","data-testid":"product-permissions",children:[e.jsx("div",{children:e.jsx(le,{placeholder:r("inspector.authentication.form.searchProducts","Search"),onSearch:l,value:i,searchOnChange:!0,disabled:o})}),e.jsxs("div",{className:"flex flex-col gap-4",children:[!i.trim()&&c.length>0&&e.jsxs("div",{children:[e.jsxs("label",{className:"flex cursor-pointer items-center gap-3",children:[e.jsx("div",{children:e.jsx(X,{checked:x,onChange:g=>y(g.target.checked),disabled:o})}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:r("inspector.authentication.form.all")})]}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 pl-7",children:[e.jsxs("label",{className:"flex cursor-pointer items-center gap-3",children:[e.jsx("div",{children:e.jsx(X,{checked:w,onChange:g=>E("READ",g.target.checked),disabled:o})}),e.jsx("span",{className:"text-sm text-muted-foreground",children:r("inspector.authentication.form.canView","Can view")})]}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-3",children:[e.jsx("div",{children:e.jsx(X,{checked:b,onChange:g=>E("WRITE",g.target.checked),disabled:o})}),e.jsx("span",{className:"text-sm text-muted-foreground",children:r("inspector.authentication.form.canCreate","Can create/update")})]})]})]}),c.length===0&&e.jsx("p",{className:"py-2 text-center text-sm text-muted-foreground",children:r("inspector.authentication.form.noProductsMatch","No products match your search.")}),c.map(g=>e.jsxs("div",{children:[e.jsxs("label",{className:"flex cursor-pointer items-center gap-3",children:[e.jsx("div",{children:e.jsx(X,{checked:m(g.key),onChange:f=>p(g.key,f.target.checked),disabled:o})}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:g.name})]}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 pl-7",children:[e.jsxs("label",{className:"flex cursor-pointer items-center gap-3",children:[e.jsx("div",{children:e.jsx(X,{checked:d(g.key),onChange:()=>h(g.key,"READ"),disabled:o,"aria-label":r("inspector.a11y.canViewProduct","{{product}}: can view",{product:g.name})})}),e.jsx("span",{className:"text-sm text-muted-foreground",children:r("inspector.authentication.form.canView","Can view")})]}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-3",children:[e.jsx("div",{children:e.jsx(X,{checked:u(g.key),onChange:()=>h(g.key,"WRITE"),disabled:o,"aria-label":r("inspector.a11y.canCreateProduct","{{product}}: can create or update",{product:g.name})})}),e.jsx("span",{className:"text-sm text-muted-foreground",children:r("inspector.authentication.form.canCreate","Can create/update")})]})]})]},g.key))]})]})}function it(t,s){return t.length===s.length&&t.every(n=>s.includes(n))}function ds(t){return t.flatMap(s=>s.permission==="READ_WRITE"?[`${s.product}:READ`,`${s.product}:WRITE`]:[`${s.product}:${s.permission}`])}function nr({initialData:t,onSubmit:s,availableAccounts:n,availableMembers:o,availableProducts:r,existingKeyNames:i,isSubmitting:l,formId:c="devx-api-key-form",onCanSubmitChange:d}){const{t:u}=A(),m=!!t,p=a.useMemo(()=>({name:t?.name||"",applyToAllAccounts:t?.applyToAllAccounts||!1,accountCodes:t?.accounts?.map(v=>v.code_live)||[],usersToBeAssigned:t?.assignedUsers?.map(v=>v.code)||[],productPermissions:t?.productPermissions||[]}
1),[t]),[h,x]=a.useState(p),w=a.useMemo(()=>n.map(v=>({code:v.code,name:v.name,disabled:m})),[n,m]),b=h.name.trim()!==""&&i.some(v=>v.toLowerCase()===h.name.trim().toLowerCase()&&v.toLowerCase()!==(t?.name||"").toLowerCase()),y=a.useMemo(()=>h.name!==p.name||h.applyToAllAccounts!==p.applyToAllAccounts||!it(h.accountCodes,p.accountCodes)||!it(h.usersToBeAssigned,p.usersToBeAssigned)?!0:!it(ds(h.productPermissions),ds(p.productPermissions)),[h,p]),g=h.name.trim().length>0&&!b&&(!m||y);a.useEffect(()=>{d?.(g)},[g,d]);const f=v=>{x(L=>({...L,accountCodes:v}))},N=v=>{x(L=>({...L,usersToBeAssigned:L.usersToBeAssigned.includes(v)?L.usersToBeAssigned.filter(O=>O!==v):[...L.usersToBeAssigned,v]}))},C=v=>{x(L=>({...L,usersToBeAssigned:L.usersToBeAssigned.filter(O=>O!==v)}))},[T,I]=a.useState(!1),[S,z]=a.useState(""),k=a.useRef(null),j=a.useId();a.useEffect(()=>{const v=L=>{k.current&&!k.current.contains(L.target)&&I(!1)};return T&&document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[T]);const _=a.useMemo(()=>{if(!S.trim())return o;const v=S.toLowerCase();return o.filter(L=>L.first_name.toLowerCase().includes(v)||L.last_name.toLowerCase().includes(v))},[o,S]),D=v=>{v.preventDefault(),!(!g||l)&&s(h)};return e.jsxs("form",{id:c,onSubmit:D,className:"flex flex-col gap-6","data-testid":"api-key-form",children:[e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(ae,{name:"name",label:u("inspector.authentication.form.keyName"),type:"text",value:h.name,onChange:v=>x({...h,name:v.target.value}),placeholder:u("inspector.authentication.form.namePlaceholder","Enter a name"),autoFocus:!m,error:b?u("inspector.authentication.form.duplicateName"):void 0,"data-testid":"api-key-name-field"})}),o.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-sm font-medium text-foreground",htmlFor:m?void 0:j,children:u("inspector.authentication.form.memberWithAccess")}),m?e.jsx("div",{className:"flex flex-wrap gap-1",children:o.filter(v=>h.usersToBeAssigned.includes(v.code)).map(v=>e.jsxs(Y,{variant:"secondary",children:[v.first_name," ",v.last_name]},v.code))}):e.jsxs("div",{ref:k,className:"relative",children:[h.usersToBeAssigned.length>0&&e.jsx("div",{className:"mb-2 flex flex-wrap gap-1",children:h.usersToBeAssigned.map(v=>{const L=o.find(V=>V.code===v),O=L?`${L.first_name} ${L.last_name}`:v;return e.jsxs("span",{className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-xs bg-muted text-foreground","data-testid":"member-chip",children:[O,e.jsx("button",{type:"button",onClick:()=>C(v),className:"ml-0.5 rounded-full hover:bg-accent","aria-label":u("inspector.authentication.form.removeMember","Remove {{name}}",{name:O}),"data-testid":"member-chip-remove",children:e.jsx(F,{name:"X",size:"xs"})})]},v)})}),e.jsxs("button",{type:"button",id:j,onClick:()=>I(v=>!v),className:"flex w-full items-center justify-between rounded-md border px-3 py-2 text-sm border-input bg-card text-foreground","data-testid":"member-dropdown-trigger",children:[e.jsx("span",{className:h.usersToBeAssigned.length===0?"text-muted-foreground":void 0,children:h.usersToBeAssigned.length===0?u("inspector.authentication.form.selectMember"):u("inspector.authentication.form.memberSelected",{count:h.usersToBeAssigned.length})}),e.jsx(F,{name:"CaretUpDown",size:"sm",className:"text-muted-foreground"})]}),T&&e.jsxs("div",{className:"absolute z-10 mt-1 w-full rounded-md border shadow-lg border-border bg-card","data-testid":"member-dropdown",children:[e.jsx("div",{className:"p-2",children:e.jsx("div",{children:e.jsx(le,{placeholder:u("inspector.authentication.form.searchMembers"),onSearch:z,value:S,searchOnChange:!0})})}),e.jsx("div",{className:"max-h-48 overflow-y-auto p-1",children:_.map(v=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-accent",children:[e.jsx(X,{checked:h.usersToBeAssigned.includes(v.code),onChange:()=>N(v.code)}),e.jsxs("span",{className:"text-foreground",children:[v.first_name," ",v.last_name]})]},v.code))})]})]})]}),e.jsx(W,{}),n.length>0&&e.jsxs("section",{className:"flex flex-col gap-6 rounded-lg border border-border p-6",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("h3",{className:"text-base font-semibold text-foreground",children:u("inspector.authentication.form.accountsAccess","A
1ccount(s) access")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:u("inspector.authentication.form.accountsAccessDescription","This key will have access to the following accounts:")})]}),e.jsx(zn,{className:"rounded-none border-0 p-0",accounts:w,selectedCodes:h.accountCodes,onChange:f,currentAccountCode:"",showCurrentAccountOnly:!1,disabled:m,maxListHeight:mt,labels:{searchPlaceholder:u("inspector.authentication.form.searchAccounts","Search"),empty:u("inspector.authentication.form.noAccountsMatch","No accounts match your search.")}})]}),r.length>0&&e.jsxs("section",{className:"flex flex-col gap-6 rounded-lg border border-border p-6",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("h3",{className:"text-base font-semibold text-foreground",children:u("inspector.authentication.form.productsAccess","Product(s) access")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:u("inspector.authentication.form.productsAccessDescription","This key will have access to the following products:")})]}),e.jsx(sr,{products:r,value:h.productPermissions,onChange:v=>x({...h,productPermissions:v})})]}),!m&&e.jsx(X,{checked:h.applyToAllAccounts,onChange:v=>x({...h,applyToAllAccounts:v.target.checked}),label:u("inspector.authentication.form.allAccountsCreated","Checking this box will automatically add all newly created accounts to this key."),"data-testid":"api-key-auto-add-accounts"})]})}function or({label:t,value:s,isLast:n=!1}){return e.jsxs("div",{className:P("flex flex-col gap-1 px-4 py-4",!n&&"border-b","border-border"),children:[e.jsx("span",{className:"text-sm font-semibold text-foreground",children:t}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s})]})}function ar({apiKey:t}){const{t:s}=A(),n=t.applyToAllAccounts?[s("inspector.authentication.customizedKeys.allAccounts")]:t.accounts?.map(i=>i.name)||[],o=t.assignedUsers?.map(i=>i.name)||[],r=[{label:s("inspector.authentication.detail.name"),value:t.name},{label:s("inspector.authentication.detail.code"),value:t.code},{label:s("inspector.authentication.detail.assignedUsers"),value:o.length>0?e.jsx("div",{className:"flex flex-wrap gap-1",children:o.map(i=>e.jsx(Y,{variant:"secondary",children:i},i))}):"-"},{label:s("inspector.authentication.detail.createdAt"),value:t.createdAt?new Date(t.createdAt).toLocaleString():"-"},{label:s("inspector.authentication.detail.lastUsed"),value:t.lastUsed?new Date(t.lastUsed).toLocaleString():s("inspector.authentication.detail.never")},{label:s("inspector.authentication.detail.accounts"),value:n.length>0?e.jsx("div",{className:"flex flex-wrap gap-1",children:n.map(i=>e.jsx(Y,{variant:"secondary",children:i},i))}):"-"}];return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card",children:r.map((i,l)=>e.jsx(or,{label:i.label,value:i.value,isLast:l===r.length-1},i.label))}),t.productPermissions&&t.productPermissions.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:s("inspector.authentication.detail.productPermissions")}),e.jsx("div",{className:"overflow-hidden rounded-md border border-border",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border bg-muted",children:[e.jsx("th",{className:"px-3 py-1.5 text-left text-xs font-medium text-muted-foreground",children:s("inspector.authentication.form.product")}),e.jsx("th",{className:"px-3 py-1.5 text-left text-xs font-medium text-muted-foreground",children:s("inspector.authentication.detail.permission")})]})}),e.jsx("tbody",{children:t.productPermissions.map(i=>e.jsxs("tr",{className:"border-b last:border-b-0 border-border",children:[e.jsx("td",{className:"px-3 py-1.5 text-sm text-foreground",children:i.product}),e.jsx("td",{className:"px-3 py-1.5 font-mono text-xs text-muted-foreground",children:i.permission})]},`${i.product}-${i.permission}`))})]})})]})]})}function rr({open:t,selectedKey:s,mode:n,onClose:o,onSubmitForm:r,availableAccounts:i,availableMembers:l,availableProducts:c,existingKeyNames:d,isSubmitting:u}){const{t:m}
1=A(),[p,h]=a.useState(!1),x=n==="create",w=n==="edit",b=x||w,E=x?m("inspector.authentication.detail.createTitle"):w?m("inspector.authentication.detail.editTitle"):s?.name||"",g=()=>u?m("inspector.authentication.form.saving"):w?m("inspector.authentication.form.save","Save changes"):m("inspector.authentication.form.create"),f=[{children:m("inspector.authentication.form.cancel"),variant:"outline",onClick:o,disabled:u},{children:g(),type:"submit",form:"devx-api-key-form",disabled:u||!p,"data-testid":"api-key-form-submit"}];return e.jsx(Xe,{open:t,onClose:o,title:E,buttons:b?f:[],testId:"api-key-detail-panel",children:e.jsxs("div",{className:P(b&&"flex flex-col"),children:[b&&e.jsx(nr,{formId:"devx-api-key-form",initialData:w?s:null,onSubmit:r,onCanSubmitChange:h,availableAccounts:i,availableMembers:l,availableProducts:c,existingKeyNames:d,isSubmitting:u},s?.code??"create"),!b&&s&&e.jsx(ar,{apiKey:s})]})})}function ir({open:t,ips:s,onSave:n,onClose:o,isLoading:r,isSaving:i,isError:l=!1,onRetry:c}){const{t:d}=A(),[u,m]=a.useState([]),[p,h]=a.useState(new Set),[x,w]=a.useState(""),[b,y]=a.useState(!1);a.useEffect(()=>{m(s),h(new Set)},[s]);const E=a.useMemo(()=>{if(u.length!==s.length)return!0;const v=[...u].sort((O,V)=>O.localeCompare(V)),L=[...s].sort((O,V)=>O.localeCompare(V));return v.some((O,V)=>O!==L[V])},[u,s]),g=a.useMemo(()=>x.trim()?u.filter(v=>v.toLowerCase().includes(x.toLowerCase())):u,[u,x]),f=a.useMemo(()=>g.filter(v=>p.has(v)).length,[g,p]),N=g.length>0&&f===g.length,C=a.useCallback(()=>{h(v=>{const L=new Set(v),O=g.length>0&&g.every(V=>v.has(V));return g.forEach(V=>{O?L.delete(V):L.add(V)}),L})},[g]),T=a.useCallback(v=>{h(L=>{const O=new Set(L);return O.has(v)?O.delete(v):O.add(v),O})},[]),I=a.useCallback(v=>{m(L=>L.filter(O=>O!==v)),h(L=>{const O=new Set(L);return O.delete(v),O})},[]),S=a.useCallback(()=>{m(v=>v.filter(L=>!(p.has(L)&&g.includes(L)))),h(new Set)},[p,g]),z=a.useCallback(()=>{m([]),h(new Set)},[]),k=a.useCallback(async()=>{y(!1);try{await n(u),y(!0),setTimeout(()=>y(!1),3e3)}catch{}},[u,n]),j=a.useCallback(v=>Oa.test(v)?!0:d("inspector.authentication.allowedIps.invalidIp"),[d]),_=()=>l?e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 rounded-lg border border-border px-6 py-8","data-testid":"allowed-ips-error",children:[e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:d("inspector.authentication.allowedIps.errorLoading","The allowed IPs could not be loaded.")}),c&&e.jsx(M,{variant:"outline",size:"sm",startIcon:"ArrowsClockwise",onClick:c,children:d("inspector.authentication.allowedIps.retry","Retry")})]}):r?e.jsx("div",{className:"flex h-[120px] items-center justify-center rounded-lg border border-border","data-testid":"allowed-ips-loading",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:d("inspector.authentication.allowedIps.loading")})}):e.jsxs(ee,{children:[e.jsx(te,{children:e.jsxs(q,{children:[e.jsx($,{className:"w-[52px]",children:e.jsx(X,{checked:N,onChange:C,disabled:i||u.length===0,"aria-label":d("inspector.authentication.allowedIps.selectAll","Select all IP addresses"),"data-testid":"allowed-ips-select-all"})}),e.jsx($,{children:d("inspector.authentication.allowedIps.ipAddressColumn")}),e.jsx($,{className:"w-[52px]"})]})}),e.jsxs(se,{children:[g.map(v=>e.jsxs(q,{"data-testid":"allowed-ips-row",children:[e.jsx(U,{children:e.jsx(X,{checked:p.has(v),onChange:()=>T(v),disabled:i,"aria-label":d("inspector.authentication.allowedIps.selectIp","Select {{ip}}",{ip:v})})}),e.jsx(U,{className:"text-sm text-foreground",children:v}),e.jsx(U,{children:e.jsx(M,{variant:"ghost",size:"icon",onClick:()=>I(v),disabled:i,"aria-label":d("inspector.authentication.allowedIps.deleteIp","Delete {{ip}}",{ip:v}),"data-testid":"allowed-ips-delete",children:e.jsx(F,{name:"Trash",size:"sm"})})})]},v)),g.length===0&&e.jsx(q,{children:e.jsx(U,{colSpan:3,className:"py-8 text-center text-sm text-muted-foreground","data-testid":"allowed-ips-empty",children:d(x?"inspector.authentication.allowedIps.noResults":"inspector.authentication.allowedIps.emptyState")})})]})]}),D=[{children:d("inspector.authentication.allowedIps.cancel"),variant:"outline",onClick:o,disabled:i},{children:i?d("inspector.authentication.mfa.verifying"):d("inspector.authentication.allowedIps.save","Save changes"),onClick:()=>{k()},disabled:!E||i||l,"data-testid":"allowed-ips-save"}];return e.jsx(Xe,{open:t,onClose:o,title:d("inspector.authentication.allowedIps.panelTitle"),buttons:D,testId:"allowed-ips-panel",children:e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx("div",{role:"alert",className:"relative flex w-full items-center gap-4 roun
1ded-lg border border-border bg-card px-4 py-3 text-foreground",children:e.jsxs("div",{className:"relative min-w-0 flex-1 pl-7",children:[e.jsx(F,{name:"Warning",size:"sm",weight:"fill",className:"absolute left-0 top-0.5 text-amber-500"}),e.jsx("p",{className:"mb-1 text-sm font-medium",children:d("inspector.authentication.allowedIps.warningTitle","Precaution")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:d("inspector.authentication.allowedIps.warningMessage","If no IP addresses are added, IPs will not be validated by default. Please be mindful when adding new IPs, as it is a sensitive change that may impact payment processing.")})]})}),b&&e.jsx("div",{children:e.jsx(Ge,{icon:"CheckCircle",title:d("inspector.authentication.allowedIps.saveSuccess")})}),e.jsx("div",{children:e.jsx(Ao,{value:u,onChange:m,label:d("inspector.authentication.allowedIps.addIpLabel","Add IP address"),description:d("inspector.authentication.allowedIps.addIpInfo","Separate each IP address with a comma, semicolon, space or by pressing the enter key."),placeholder:d("inspector.authentication.allowedIps.addIpPlaceholder","Enter IP address"),triggerKeys:["Enter","Comma","Space"],validate:j,allowDuplicates:!1,disabled:i||l,deleteAll:{label:d("inspector.authentication.allowedIps.deleteSelection"),length:2,onClick:z}})}),e.jsx(W,{}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("h4",{className:"text-sm font-medium text-foreground",children:d("inspector.authentication.allowedIps.tableTitle","Current allowlist")}),f>0&&e.jsx(M,{variant:"outline",size:"sm",startIcon:"Trash",onClick:S,disabled:i,"data-testid":"allowed-ips-delete-selected",children:d("inspector.authentication.allowedIps.deleteSelected","Delete selected")})]}),e.jsx("div",{children:e.jsx(le,{placeholder:d("inspector.authentication.allowedIps.searchPlaceholder","Search"),onSearch:w,value:x,searchOnChange:!0})}),_()]})]})})}function Ze({open:t,onClose:s,title:n,children:o,footer:r,maxWidth:i="sm:max-w-lg",testId:l="inspector-dialog"}){const{t:c}=A();return a.useEffect(()=>{if(!t)return;const d=u=>{u.key==="Escape"&&s()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[t,s]),t?jt.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[2000011] flex items-center justify-center p-4","data-yuno-inspector-root":"","data-testid":l,children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:s,"aria-hidden":"true"}),e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":n,className:P("relative z-10 flex max-h-[90vh] w-full flex-col overflow-hidden rounded-lg border text-foreground shadow-lg",i,"border-border bg-card"),children:[e.jsxs("div",{className:"flex min-h-16 items-center justify-between gap-4 border-b px-6 py-3 border-border",children:[e.jsx("h3",{className:"min-w-0 truncate text-base font-semibold text-foreground",children:n}),e.jsx("div",{className:"shrink-0",children:e.jsx(M,{variant:"ghost",size:"icon",onClick:s,"aria-label":c("inspector.authentication.detail.close","Close"),"data-testid":"inspector-dialog-close",children:e.jsx(F,{name:"X",size:"sm"})})})]}),e.jsx("div",{className:P("min-h-0 flex-1 overflow-auto p-6",r&&"border-b border-border"),children:o}),r&&e.jsx("div",{className:"flex min-h-16 items-center justify-end gap-2 px-6 py-3",children:r})]})]}),document.body):null}function cr({isOpen:t,onClose:s,onConfirm:n,isSubmitting:o,isSsoUser:r,keyName:i,lastUsed:l,passwordError:c}){const{t:d}=A(),[u,m]=a.useState(""),[p,h]=a.useState(""),[x,w]=a.useState(!1);a.useEffect(()=>{t&&(m(""),h(""),w(!1))},[t]);const b=a.useMemo(()=>Ma.map(f=>({label:d(f.labelKey),value:f.value})),[d]),y=()=>{!u||!p||n(u,p)},E=u.length===0||p.length===0||o,g=x?d("inspector.authentication.roll.hidePassword","Hide password"):d("inspector.authentication.roll.showPassword","Show password");return t?e.jsx(Ze,{open:t,onClose:s,title:d("inspector.authentication.roll.title"),testId:"roll-dialog",footer:e.jsxs(e.Fragment,{children:[e.jsx(M,{variant:"outline",onClick:s,disabled:o,children:d("inspector.authentication.roll.cancel")}),e.jsx(M,{variant:"default",onClick:y,disabled:E,"data-testid":"roll-confirm",children:d(o?"inspector.authentication.roll.rolling":"inspector.authentication.roll.rollApiKey")})]}),children:e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-border bg-card p-4",children:[e.jsx(F,{name:"Info",size:"sm",className:"mt-0.5 shrink-0 text-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:d("inspector.authentication.roll.alertDescription")})]}
1),i&&e.jsxs("div",{className:"flex flex-col gap-4 rounded-lg border border-border p-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 text-sm",children:[e.jsx("span",{className:"font-medium text-foreground",children:d("inspector.authentication.roll.keyLabel")}),e.jsx("span",{className:"min-w-0 truncate text-foreground",children:i})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 text-sm",children:[e.jsx("span",{className:"font-medium text-foreground",children:d("inspector.authentication.roll.lastUsedLabel")}),e.jsx("span",{className:"text-foreground",children:l?new Date(l).toLocaleString():d("inspector.authentication.roll.never")})]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-sm font-medium text-foreground",htmlFor:"roll-grace",children:d("inspector.authentication.roll.expirationLabel")}),e.jsx(ze,{id:"roll-grace",value:u,onChange:f=>m(f),options:b,placeholder:d("inspector.authentication.roll.selectPlaceholder")})]}),e.jsx(W,{}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-sm font-medium text-foreground",htmlFor:"roll-password-input",children:d("inspector.authentication.roll.authRequired")}),r?e.jsx(ae,{id:"roll-password-input",value:p,onChange:f=>h(f.target.value),placeholder:d("inspector.authentication.roll.enterOtp"),name:"roll-password",type:"password",autoComplete:"one-time-code",error:c,"data-testid":"roll-password"}):e.jsxs("div",{className:"relative",children:[e.jsx(ae,{id:"roll-password-input",value:p,onChange:f=>h(f.target.value),placeholder:d("inspector.authentication.roll.enterPassword"),name:"roll-password",type:x?"text":"password",autoComplete:"current-password",error:c,inputProps:{className:"pr-9"},"data-testid":"roll-password"}),e.jsx(oe,{content:g,children:e.jsx("button",{type:"button","aria-label":g,onClick:()=>w(f=>!f),className:"absolute right-2 top-[18px] flex size-6 -translate-y-1/2 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:text-foreground","data-testid":"roll-password-toggle",children:e.jsx(F,{name:x?"EyeSlash":"Eye",size:"sm"})})})]})]})]})}):null}const us="\0";function lr({isOpen:t,onClose:s,onConfirm:n,keyName:o,isSubmitting:r=!1}){const{t:i}=A();if(!t)return null;const l=i("inspector.authentication.delete.description","Are you sure you want to delete {{name}}? This action can't be undone.",{name:us}),[c,d]=l.split(us);return e.jsx(Ze,{open:t,onClose:s,title:i("inspector.authentication.delete.title"),testId:"delete-confirm-dialog",footer:e.jsxs(e.Fragment,{children:[e.jsx(M,{variant:"outline",onClick:s,disabled:r,children:i("inspector.authentication.delete.cancel")}),e.jsx(M,{onClick:n,disabled:r,"data-testid":"delete-confirm",children:i("inspector.authentication.delete.confirm")})]}),children:e.jsxs("p",{className:"text-sm text-foreground",children:[c,e.jsxs("span",{className:"font-medium",children:["â",o??"","â"]}),d??""]})})}function dr({isOpen:t,onClose:s,onConfirm:n}){const{t:o}=A();return t?e.jsx(Ze,{open:t,onClose:s,title:o("inspector.authentication.roll.immediateWarningTitle"),testId:"immediate-roll-warning-dialog",footer:e.jsxs(e.Fragment,{children:[e.jsx(M,{variant:"outline",onClick:s,children:o("inspector.authentication.roll.cancel")}),e.jsx(M,{variant:"default",onClick:n,"data-testid":"immediate-roll-confirm",children:o("inspector.authentication.roll.immediateWarningConfirm")})]}),children:e.jsx("div",{children:e.jsx(Ge,{variant:"default",icon:"Warning",description:o("inspector.authentication.roll.immediateWarning")})})}):null}function ur({isOpen:t,onClose:s,onSubmit:n,isSubmitting:o=!1}){const{t:r}=A(),[i,l]=a.useState("");return a.useEffect(()=>{t&&l("")},[t]),t?e.jsxs(Ze,{open:t,onClose:s,title:r("inspector.authentication.organizationKeys.addNote"),testId:"note-dialog",footer:e.jsxs(e.Fragment,{children:[e.jsx(M,{variant:"outline",onClick:s,disabled:o,children:r("inspector.authentication.organizationKeys.cancel")}),e.jsx(M,{variant:"default",onClick:()=>n(i),disabled:i.length===0||o,"data-testid":"note-submit",children:r("inspector.authentication.organizationKeys.save")})]}),children:[e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:r("inspector.authentication.organizationKeys.addNoteDescription")}),e.jsx("div",{children:e.jsx(ae,{name:"org-note",type:"text",value:i,onChange:c=>l(c.target.value),placeholder:r("inspector.authentication.organizationKeys.notePlaceholder"),"data-testid":"note-field"})})]}):null}function mr({}){const{t}=A(),{accountCode:s,isAllowed:n,statusPermission:o,accountsWithKeysPermission:r,accountsWithManageKeysPermission:i,isManageKeysPermissionLoading:l}
1=un(),[c,d]=a.useState(s);a.useEffect(()=>{d(s)},[s]);const{accounts:u}=be({roles:[]}),m=a.useMemo(()=>(u??[]).filter(R=>!!R),[u]),p=Hs(m),h=a.useMemo(()=>m.map(R=>({label:R.name||R.code||"",value:R.code||""})),[m]),x=a.useCallback(R=>{d(R)},[]),w=a.useMemo(()=>{const R=[];return h.length>0&&R.push({id:"accounts",icon:"Buildings",label:t("inspector.authentication.filters.accounts"),type:"radio",items:p.items,groups:p.groups,selectedValue:c,onValueChange:x,searchable:!0,clearable:!1}),R},[t,h.length,p,c,x]),b=a.useMemo(()=>c?[{id:"accounts",label:h.find(G=>G.value===c)?.label||c}]:[],[c,h]),y=a.useCallback((R,G)=>!!R&&!!G&&(R.code===G||R.account_code_live===G||R.account_code_testing===G),[]),E=a.useMemo(()=>(u??[]).find(R=>y(R,c))??null,[u,c,y]),g=E?Ye(E):c||s,f=a.useMemo(()=>r.some(R=>y(R,c)),[r,c,y]),N=a.useCallback(R=>l||Ha(R,i),[l,i]),C=Ua(g),T=za(c?[c]:[]),I=Io(),S=Ka(),{data:z}=Fn(),k=Va(z),[j,_]=a.useState(null),[D,v]=a.useState("view"),[L,O]=a.useState(!1),V=a.useRef(null),[de,ue]=a.useState(!1),[Qe,je]=a.useState(!1),[et,re]=a.useState(!1),[wn,Oe]=a.useState(!1),[Nn,ve]=a.useState(void 0),[kn,zt]=a.useState(!1),[we,tt]=a.useState(null),[Ne,ke]=a.useState(null),[Cn,Ft]=a.useState(!1);a.useEffect(()=>{C.fetchMetadata()},[g]),Re(()=>C.fetchMetadata());const Me=a.useRef(g);a.useEffect(()=>{Me.current=g},[g]);const Kt=a.useRef(g);a.useEffect(()=>{Kt.current!==g&&(Kt.current=g,re(!1),Oe(!1),ue(!1),ke(null),ve(void 0),Ce.current=null,I.dismissFailure())},[g]);const En=!!j||D==="create"||L,Ce=a.useRef(null),ie=a.useCallback(async(R,G)=>{Ce.current={action:R,run:G};const Ue=Me.current;try{const ce=await I.requireStepUp(R);if(!ce)return;if(await G(ce),Me.current!==Ue){Ce.current=null;return}}catch(ce){if(Me.current!==Ue){Ce.current=null;return}B.error(pn(ce)===403?t("inspector.authentication.mfa.noPermission"):t("inspector.authentication.stepUp.error"))}},[I,t]),Tn=a.useCallback(()=>{const R=Ce.current;R&&ie(R.action,R.run)},[ie]),st=a.useCallback(()=>{ie("reveal_org_keys",async R=>{await C.revealWithTicket(R)})},[ie,C]),_n=a.useCallback(()=>{if(C.isRevealedThisSession){C.toggleReveal();return}st()},[C,st]),Sn=a.useCallback(()=>{C.isRevealed&&C.toggleReveal()},[C]);a.useEffect(()=>{I.resumedAction==="reveal_org_keys"&&st()},[I.resumedAction]);const An=a.useCallback(()=>{Oe(!0)},[]),In=a.useCallback(()=>{Oe(!1),ie("roll_org_keys",R=>C.rollKeys({password:""},R))},[ie,C]),Dn=a.useCallback(async R=>{Ft(!0);try{await C.updateNote(R),re(!1)}catch{B.error(t("inspector.authentication.organizationKeys.noteError"))}finally{Ft(!1)}},[C,t]),Ee=a.useCallback(()=>{_(null),v("view")},[]),Vt=a.useCallback(R=>{_(R),v("view"),O(!1)},[]),Ln=a.useCallback(()=>{_(null),v("create"),O(!1)},[]),Bt=a.useCallback(R=>{_(R),v("edit"),O(!1)},[]);a.useEffect(()=>()=>{V.current&&clearTimeout(V.current)},[]);const Rn=a.useCallback(R=>{if(!T.revealedTokens[R.code]){if(R.alreadyBeenShown){B.error(t("inspector.authentication.tokenAlreadyRevealed"));return}ie("reveal_customized_token",async G=>{await T.revealToken(R.code,{password:""},G)})}},[T,t,ie]),Ht=a.useCallback(R=>{ke(R),ve(void 0),ue(!0)},[]),Pn=a.useCallback(async(R,G)=>{if(Ne){zt(!0),ve(void 0);try{await T.rollKey(Ne.code,{password:G},R),ue(!1),ke(null)}catch(Ue){const ce=$a(Ue);if(ce==="credential"){ve(t(k?"inspector.authentication.roll.wrongCode":"inspector.authentication.roll.wrongPassword"));return}ce==="permission"&&(ue(!1),ke(null)),B.error(t(ce==="permission"?"inspector.authentication.roll.noPermission":"inspector.authentication.roll.error"))}finally{zt(!1)}}},[Ne,T,t,k]),$t=a.useCallback(R=>{tt(R),je(!0)},[]),On=a.useCallback(async()=>{if(we)try{await T.deleteKey(we.code),je(!1),j?.code===we.code&&Ee(),tt(null)}catch{B.error(t("inspector.authentication.deleteError"))}},[we,T,j,Ee,t]),Mn=a.useCallback(async R=>{try{D==="create"?await T.createKey(R):D==="edit"&&j&&await T.updateKey(j.code,R),Ee()}catch{B.error(t("inspector.authentication.form.submitError"))}},[D,j,T,Ee,t]),Un=a.useCallback(()=>{_(null),v("view"),O(!0),S.fetchIps()},[S]);return!n&&o!=="LOADING"?e.jsx("div",{className:"flex h-full items-center justify-center p-6","data-testid":"authentication-tab",children:e.jsx($s,{text:t("inspector.authentication.accessDenied"),"data-testid":"access-denied-alert"})}):e.jsxs("div",{className:"flex flex-col gap-8","data-testid":"authentication-tab",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[w.length>0&&e.jsx("div",{"data-testid":"authentication-account-filter",children:e.jsx(De,{filters:w,translations:{addFilter:t("inspector.authentication.filters.addFilter")},appliedFilters:b,maxVisibleTags:1})}),e.jsx(M,{variant:"outline",size:"sm",startIcon:"CheckSquareOffset",onClick:Un,className:"ml-auto shrink-0","data-testid":"open-allowed-ips",children:t("inspector.authentication.allowedIps.openButton")})]}),I.failure&&e.jsx("div",{className:"shrink-0",children:e.jsx(Ge,{variant:"destructive",icon:"Warning","data-testid":"step-up-banner",title:I.failure==="EMBEDDED"?t("inspector.authentication.stepUp.embedded"):t("inspector.authentication.stepUp.notCompleted"),actions:I.failure==="NOT_COMPLETED"?e.jsx(M,{variant:"outline",size:"sm",onClick:Tn,"data-testid":"step-up-retry",children:t("inspector.authentication.stepUp.retry")}):void 0,onClose:I.dismissFailure,closeLabel:t("inspector.authentication.stepUp.dism
1iss")})}),e.jsx(Wa,{accountCode:g}),e.jsx(Xa,{publicKey:C.publicKey,privateKey:C.privateKey,isRevealed:C.isRevealed,isShowDisabled:C.isShowDisabled,isLoading:C.isLoading,note:C.metadata?.note,onReveal:_n,onRoll:An,onAddNote:()=>re(!0),canReveal:f,canToggleReveal:C.canToggleReveal,onAutoHide:Sn}),e.jsx(tr,{keys:T.keys,selectedKeyCode:j?.code,isLoading:T.isLoading,revealedTokens:T.revealedTokens,revealedCredentials:T.revealedCredentials,onCreateKey:Ln,onSelectKey:Vt,onViewDetails:Vt,onEditKey:Bt,onRollKey:Ht,canManageKey:N,onDeleteKey:$t,onRevealToken:Rn}),e.jsx(cr,{isOpen:de,onClose:()=>{ue(!1),ke(null),ve(void 0)},onConfirm:Pn,isSubmitting:kn,isSsoUser:k,keyName:Ne?.name,lastUsed:Ne?.lastUsed,passwordError:Nn}),e.jsx(lr,{isOpen:Qe,onClose:()=>{je(!1),tt(null)},onConfirm:On,keyName:we?.name}),e.jsx(dr,{isOpen:wn,onClose:()=>Oe(!1),onConfirm:In}),e.jsx(rr,{open:En&&!L,selectedKey:j,mode:D,onClose:Ee,onEdit:Bt,onRoll:Ht,onDelete:$t,onSubmitForm:Mn,availableAccounts:T.availableAccounts,availableMembers:T.availableMembers,availableProducts:T.availableProducts,existingKeyNames:T.keys.map(R=>R.name),isSubmitting:T.isLoading}),e.jsx(ir,{open:L,ips:S.ips,onSave:S.saveIps,onClose:()=>O(!1),isLoading:S.isLoading,isSaving:S.isSaving,isError:S.isError,onRetry:S.fetchIps}),e.jsx(ur,{isOpen:et,onClose:()=>re(!1),onSubmit:Dn,isSubmitting:Cn})]})}var Ae=(t=>(t.ACTIVE="ACTIVE",t.INACTIVE="INACTIVE",t))(Ae||{});const pr=["enrollment_triggers","payment_triggers","report_triggers","customer_triggers","subscription_triggers","onboarding_triggers"],hr="INPUT",Mt="MULTIPLE_CHECKBOX",xr="INPUT_OAUTH",fr="INPUT_HMAC",gr=["OAUTH2_SCOPE"],br={ENROLLMENT:"enrollment_triggers",PAYMENT:"payment_triggers",REPORT:"report_triggers",CUSTOMER:"customer_triggers",SUBSCRIPTION:"subscription_triggers",ONBOARDING:"onboarding_triggers"},yr=["GET","POST","PUT","DELETE","PATCH"],jr=["PAYMENT","REPORT","SUBSCRIPTION","ENROLLMENT","CUSTOMER","ONBOARDING"],qe="LAST_7_DAYS",vr=25;function pt(t){const s=new Date,n=new Date(s);n.setHours(23,59,59,999);const o={TODAY:0,LAST_3_DAYS:2,LAST_7_DAYS:6,LAST_30_DAYS:29};if(o[t]!==void 0){const r=new Date(s);return r.setDate(r.getDate()-o[t]),r.setHours(0,0,0,0),{dateInit:r,dateEnd:n}}if(t==="THIS_MONTH"){const r=new Date(s.getFullYear(),s.getMonth(),1);return r.setHours(0,0,0,0),{dateInit:r,dateEnd:n}}return{dateInit:void 0,dateEnd:void 0}}const ms=3;function wr(t){const s=[];return pr.forEach(n=>{const o=t[n];if(!o?.length)return;const r=n.split("_")[0],i=`${r.charAt(0).toUpperCase()}${r.slice(1)}`;o.forEach(l=>{s.push(`${i} ${l.name.toLowerCase()}`)})}),s}function Nr({webhook:t}
1){const s=wr(t);if(s.length===0)return e.jsx("span",{"data-testid":"webhook-triggers-empty",children:"-"});const n=s.slice(0,ms),o=s.slice(ms);return e.jsxs("div",{className:"flex flex-wrap items-center gap-1","data-testid":"webhook-triggers-badges",children:[n.map(r=>e.jsx("div",{children:e.jsx(Y,{variant:"secondary",children:r})},r)),o.length>0&&e.jsx("div",{children:e.jsx(oe,{content:o.join(", "),children:e.jsxs(Y,{variant:"secondary",children:["+",o.length]})})})]})}function kr({webhook:t,canManage:s,onToggleStatus:n,onEdit:o,onDelete:r}){const{t:i}=A(),l=t.state===Ae.ACTIVE,c={actions:[{key:"edit",name:i("inspector.webhooks.menu.edit"),icon:"PencilSimple",allowed:s,handleClick:()=>o(t)},{key:"delete",name:i("inspector.webhooks.menu.delete"),icon:"Trash",allowed:s,handleClick:()=>r(t)}]};return e.jsxs(q,{"data-testid":"webhook-row",children:[e.jsx(U,{children:e.jsx(Kn,{label:"","aria-label":i("inspector.webhooks.a11y.toggleStatus","{{name}} enabled",{name:t.name}),disabled:!s,checked:l,onChange:()=>n(t.id,t.state),"data-testid":`webhook-toggle-${t.id}`})}),e.jsx(U,{className:"font-medium",children:e.jsx("span",{className:"block max-w-[200px] truncate",children:t.name||"-"})}),e.jsx(U,{className:"text-muted-foreground",children:e.jsx("span",{className:"block max-w-[250px] truncate",children:t.url||"-"})}),e.jsx(U,{children:e.jsx(Nr,{webhook:t})}),e.jsx(U,{children:e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(oe,{content:i("inspector.webhooks.actionsTooltip","Actions"),contentProps:{side:"left"},children:e.jsx(It,{options:c,disabled:!s,ariaLabel:i("inspector.webhooks.a11y.rowActions","More actions for {{name}}",{name:t.name})})})})})]})}const Cr=[0,1,2];function Er({webhooks:t,isLoading:s,canManage:n,searchTerm:o,onToggleStatus:r,onEdit:i,onDelete:l}){const{t:c}=A(),d=e.jsxs(q,{children:[e.jsx($,{className:"w-[100px]",children:c("inspector.webhooks.table.status","Status")}),e.jsx($,{children:c("inspector.webhooks.table.name","Name")}),e.jsx($,{children:c("inspector.webhooks.table.url","URL")}),e.jsx($,{children:c("inspector.webhooks.table.triggers","Triggers")}),e.jsx($,{className:"w-[52px]"})]});return s?e.jsxs(ee,{"data-testid":"webhooks-table-loading",children:[e.jsx(te,{children:d}),e.jsx(se,{children:Cr.map(u=>e.jsxs(q,{children:[e.jsx(U,{children:e.jsx(K,{className:"h-5 w-10 rounded-full"})}),e.jsx(U,{children:e.jsx(K,{className:"h-4 w-28 rounded"})}),e.jsx(U,{children:e.jsx(K,{className:"h-4 w-40 rounded"})}),e.jsx(U,{children:e.jsx("div",{className:"flex gap-1",children:[0,1].map(m=>e.jsx(K,{className:"h-5 w-16 rounded bg-accent"},m))})}),e.jsx(U,{children:e.jsx(K,{className:"h-6 w-6 rounded"})})]},u))})]}):t.length===0&&o.trim()===""?e.jsx("div",{"data-testid":"webhooks-empty",children:e.jsx(he,{icon:"PlugsConnected",title:c("inspector.webhooks.emptyTitle","No webhooks yet"),description:c("inspector.webhooks.emptyDescription","Add a webhook to receive payment status updates in real time.")})}):e.jsxs(ee,{"data-testid":"webhooks-table",children:[e.jsx(te,{children:d}),e.jsxs(se,{children:[t.map(u=>e.jsx(kr,{webhook:u,canManage:n,onToggleStatus:r,onEdit:i,onDelete:l},u.id)),t.length===0&&e.jsx(q,{children:e.jsx(U,{colSpan:5,className:"py-8 text-center text-sm text-muted-foreground",children:c("inspector.webhooks.noResults","No webhooks match your search.")})})]})]})}function Tr({className:t,onAccountChange:s}){const{t:n}=A(),{accounts:o,isLoadingAccount:r}=be({roles:[]}),{isTesting:i}=Ie(),[l,c]=a.useState("");Re(()=>c(""));const d=a.useMemo(()=>(o??[]).filter(b=>!!b),[o]),u=Hs(d),m=a.useMemo(()=>d.map(b=>({code:b.code||"",name:b.name||b.code||"",accountCode:Ye(b,i)})),[d,i]);a.useEffect(()=>{if(r||m.length===0||l)return;const b=m[0];c(b.code),s(b.accountCode)},[m,r,l,s]);const p=a.useCallback(b=>{c(b);const y=m.find(E=>E.code===b);y&&s(y.accountCode)},[m,s]),h=a.useMemo(()=>m.find(b=>b.code===l)?.name??"",[m,l]),x=a.useMemo(()=>m.length===0?[]:[{id:"accounts",icon:"Buildings",label:n("inspector.webhooks.filters.accounts"),type:"radio",items:u.items,groups:u.groups,selectedValue:l,onValueChange:p,searchable:!0}],[n,m.length,u,l,p]),w=a.useMemo(()=>l?[{id:"accounts",label:h,...J()&&{icon:"User"}}]:[],[l,h]);return r||m.length===0?null:e.jsx("div",{"data-testid":"webhooks-filter-bar",className:P(t),children:e.jsx(De,{filters:x,translations:{addFilter:n("inspector.webhooks.addFilter")},appliedFilters:w}
1)})}function _r({webhooks:t,isLoading:s,isError:n,canManage:o,searchTerm:r,onSearchChange:i,onAccountChange:l,onToggleStatus:c,onEdit:d,onDelete:u,onCreate:m,onRefresh:p}){const{t:h}=A();return e.jsxs("div",{className:"flex flex-col gap-6","data-testid":"webhooks-list",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("div",{className:"w-full max-w-sm",children:e.jsx(le,{"data-testid":"webhooks-search",placeholder:h("inspector.webhooks.searchPlaceholder"),value:r,onSearch:i,searchOnChange:!0})}),o&&e.jsx("div",{className:"shrink-0",children:e.jsx(M,{size:"sm",onClick:m,"data-testid":"webhooks-create",children:h("inspector.webhooks.addWebhook")})})]}),e.jsx(Tr,{onAccountChange:l}),n?e.jsxs("div",{"data-testid":"webhooks-error",className:"flex flex-col items-center justify-center px-6 py-12",children:[e.jsx("p",{className:"text-sm font-medium leading-none mb-3 text-muted-foreground",children:h("inspector.webhooks.errorLoading")}),e.jsx("div",{children:e.jsx(M,{variant:"outline",size:"sm",startIcon:"ArrowsClockwise",onClick:p,children:h("inspector.webhooks.retry")})})]}):e.jsx(Er,{webhooks:t,isLoading:s,canManage:o,searchTerm:r,onToggleStatus:c,onEdit:d,onDelete:u})]})}function Sr(){try{return Vn.getItem(Bn.ACCOUNT)??null}catch{return null}}function Ar(){return bt()}function Ir(){return Sr()?.organization_code||""}function Dr(){const t=Ar(),s=Ir(),{statusPermission:n}=Ve(["view_webhooks","manage_webhooks"],{scopeToActiveAccount:!0}),{statusPermission:o}=Ve("manage_webhooks",{scopeToActiveAccount:!0});return{accountCode:t,organizationCode:s,canView:n===Se.ALLOWED,canManage:o===Se.ALLOWED,isLoading:n===Se.LOADING}}function Lr({accountCode:t,searchTerm:s="",enabled:n=!0}){const{data:o,isLoading:r,isFetching:i,isError:l,refetch:c}=Hn({accountCode:t,name:s,enabled:n});return{webhooks:o??[],isLoading:r||i,isError:l,refetch:()=>{c()}}}function Rr(t,s){const{t:n}=A(),{mutateAsync:o,isPending:r}=qs({}),i=a.useCallback(async(l,c)=>{const d=c===Ae.ACTIVE?Ae.INACTIVE:Ae.ACTIVE;try{await o({code:l.toString(),payload:{state:d},accountCode:t}),s?.(),B.success(n("inspector.webhooks.statusUpdated"))}catch{B.error(n("inspector.webhooks.statusError"))}},[o,t,s,n]);return{isLoading:r,toggleStatus:i}}function Pr(t,s){const{t:n}=A(),{mutateAsync:o,isPending:r}=Do({}),i=a.useCallback(async l=>{try{await o({code:l,accountCode:t}),B.success(n("inspector.webhooks.deleteSuccess")),s?.()}catch{B.error(n("inspector.webhooks.deleteError"))}},[o,t,s,n]);return{isLoading:r,handleDelete:i}}function Or(t){const{t:s}=A(),{mutateAsync:n,isPending:o}=zo();return{resend:a.useCallback(async i=>{try{await n({codes:[i]}),t?.(),B.success(s("inspector.webhooks.logs.resendSuccess"))}catch{B.error(s("inspector.webhooks.logs.resendError"))}},[n,t,s]),isResending:o}}const Mr={ENDPOINT_URL:"url",...br};function xe(t,s){const n=t[s];return Array.isArray(n)?[...n]:[]}function Ur(t,s){return t.DEFAULT_ACCOUNT?.[0]?s?[s]:[]:t.ACCOUNTS.filter(Boolean)}function ps(t,s){return{name:t.NAME,url:t.ENDPOINT_URL,api_key:t.API_KEY,secret:t.SECRET,enrollment_triggers:xe(t,"ENROLLMENT"),payment_triggers:xe(t,"PAYMENT"),report_triggers:xe(t,"REPORT"),customer_triggers:xe(t,"CUSTOMER"),subscription_triggers:xe(t,"SUBSCRIPTION"),onboarding_triggers:xe(t,"ONBOARDING"),account_codes:Ur(t,s),hmac_client_secret:t.HMAC_CLIENT_SECRET,...t.OAUTH2_AUTHENTICATION_URL||t.OAUTH2_CLIENT_ID||t.OAUTH2_CLIENT_SECRET||t.OAUTH2_GRANT_TYPE?{oauth2_authentication_url:t.OAUTH2_AUTHENTICATION_URL,oauth2_client_secret:t.OAUTH2_CLIENT_SECRET,oauth2_client_id:t.OAUTH2_CLIENT_ID,oauth2_grant_type:t.OAUTH2_GRANT_TYPE,oauth2_scope:t.OAUTH2_SCOPE?.trim()||void 0}:{}}}function zr(t,s,n){const{t:o}=A(),{data:r,isLoading:i}=$n(),l=Lo({}),c=qs({}),{data:d,isLoading:u,refetch:m}=qn({accountCode:t,enabled:!!s});a.useEffect(()=>{s&&m()},[s?.id]);const p=a.useMemo(()=>!Array.isArray(d)||!s?null:d.find(b=>b.id===s.id)??null,[d,s]),h=a.useMemo(()=>{const b=r??[];if(!s)return b;const y=p??s;return b.map(E=>
1{const g=E.id.toLowerCase(),f=Mr[E.id],N=y[g]??(f?y[f]:void 0);return{...E,value:N}})},[r,s,p]),x=a.useCallback(async b=>{try{await l.mutateAsync({payload:ps(b,t)}),B.success(o("inspector.webhooks.createSuccess")),n?.()}catch{B.error(o("inspector.webhooks.createError"))}},[l,t,n,o]),w=a.useCallback(async(b,y)=>{try{await c.mutateAsync({code:b,payload:ps(y,t),accountCode:t}),B.success(o("inspector.webhooks.editSuccess")),n?.()}catch{B.error(o("inspector.webhooks.editError"))}},[c,t,n,o]);return{fields:h,isLoadingParams:i,isLoadingDetail:u,isSubmitting:l.isPending||c.isPending,handleCreate:x,handleEdit:w}}function Fr(t){return pe({queryKey:["devx-webhook-logs",t],queryFn:async()=>(await ne.getInstance().postWebhookLogsV2({payload:t}))?.data,enabled:!!t.organizationCode,cacheTime:0,useErrorBoundary:!1})}function Kr({organizationCode:t,filters:s,searchTerm:n,page:o,size:r=vr}){const i=At({roles:[]}),l=a.useMemo(()=>({page:o-1,size:r,organizationCode:t,periodicity:"CUSTOM",account_code:wt(s.accountCodes,i),methods:s.methods.length?s.methods:void 0,start_date:s.dateInit?.toISOString(),end_date:s.dateEnd?.toISOString(),origin_id:s.originId.trim()||void 0,webhook_id:s.webhookId.trim()||void 0}),[o,r,t,s.accountCodes,i,s.methods,s.dateInit,s.dateEnd,s.originId,s.webhookId]),{data:c,isLoading:d,isError:u,refetch:m}=Fr(l);return{logs:a.useMemo(()=>{let h=c?.data??[];if(s.webhookTypes.length){const w=new Set(s.webhookTypes.map(b=>b.toLowerCase()));h=h.filter(b=>w.has(b.type?.toLowerCase()))}const x=n.trim().toLowerCase();return x&&(h=h.filter(w=>w.url?.toLowerCase().includes(x)||w.trace_id?.toLowerCase().includes(x)||w.exception?.toLowerCase().includes(x))),h},[c?.data,s.webhookTypes,n]),totalPages:c?.total_pages??0,totalRows:c?.total_rows??0,currentPage:(c?.page??0)+1,hasPageData:(c?.data??[]).length>0,isLoading:d,isError:u,refetch:()=>{m()}}}function Vr({fields:t,isChecked:s,onTriggerChange:n,onSelectAll:o,onInverse:r,onNone:i}){const{t:l}=A(),c=t.filter(d=>d.type.includes(Mt));return c.length===0?null:e.jsxs("div",{className:"flex flex-col","data-testid":"webhook-triggers-section",children:[e.jsx(W,{className:"mb-6"}),e.jsxs("div",{className:"mb-6 flex items-baseline justify-between",children:[e.jsx("p",{className:"text-sm leading-none font-semibold text-foreground",children:l("inspector.webhooks.form.triggerOn")}),e.jsx("div",{children:e.jsx(Y,{variant:"outline",children:l("inspector.webhooks.form.required")})})]}),c.map((d,u)=>{const m=d.options.some(p=>s(d.id,p.id));return e.jsxs("div",{"data-testid":`webhook-trigger-group-${d.id}`,children:[u!==0&&e.jsx(W,{className:"mb-6"}),e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("p",{className:"text-sm leading-none font-semibold text-foreground",children:d.name}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(M,{variant:"link",size:"sm",onClick:p=>{p.preventDefault(),o(d)},children:l("inspector.webhooks.form.selectAll")}),m&&e.jsxs(e.Fragment,{children:[e.jsx(M,{variant:"link",size:"sm",onClick:p=>{p.preventDefault(),r(d)},children:l("inspector.webhooks.form.inverse")}),e.jsx(M,{variant:"link",size:"sm",onClick:p=>{p.preventDefault(),i(d)},children:l("inspector.webhooks.form.none")})]})]})]}),e.jsx("div",{className:"mb-6 grid grid-cols-4 gap-2",children:d.options.map(p=>e.jsx("div",{children:e.jsx(X,{label:p.name,value:`${d.id}_${p.id}`,checked:s(d.id,p.id),onChange:()=>n(d,p.id)})},p.id))})]},d.id)})]})}const Br=/^(http(s)?:\/\/)[\w.-]+(?:[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/i;function hs({fields:t,secretFieldIds:s,urlFieldId:n,optionalFieldIds:o=[],isEditMode:r,toggleLabel:i,description:l,testId:c}){const{t:d}=A(),u=Ws(),[m,p]=a.useState(r&&t.some(x=>!!x.value));if(t.length===0)return null;const h=()=>{p(x=>(x?(t.forEach(w=>{u.unregister(w.id),u.setValue(w.id,"",{shouldDirty:!0,shouldValidate:!1})}),u.clearErrors(t.map(w=>w.id))):t.forEach(w=>{const b=w.value||"";r?u.setValue(w.id,b,{shouldDirty:!0,shouldValidate:!0}):u.resetField(w.id,{defaultValue:b})}),!x))};return e.jsxs("div",{"data-testid":c,className:"mb-6 rounded-lg border border-border",children:[e.jsxs("div",{className:"p-4",children:[e.jsx("div",{children:e.jsx(X,{label:i,checked:m,onChange:h})}),e.jsx("p",{className:"text-xs font-medium leading-none mt-1 ml-6 text-muted-foreground",children:l})]}),m&&e.jsxs(e.Fragment,{children:[e.jsx(W,{}),e.jsx("div",{className:"flex flex-col gap-4 p-4",children:t.map(x=>e.jsx(Ro,{name:x.id,control:u.control,rules:{required:m&&!o.includes(x.id)?{value:!0,message:d("inspector.webhooks.form.fillField")}:!1,pattern:x.id===n?{value:Br,message:d("inspector.webhooks.form.validUrl")}:void 0},render:({field:w,fieldState:b})=>
1e.jsx("div",{children:s.includes(x.id)?e.jsx(Ys,{label:x.name,placeholder:x.description,...w,error:b.error?.message}):e.jsx(ae,{label:x.name,placeholder:x.description,...w,error:b.error?.message})})},x.id))})]})]})}const ct="default";function Hr({}){const{t}=A(),s=Ws(),[n,o]=a.useState(""),{accounts:r}=Wn({roles:["manage_webhooks"]}),l=Vs()?.code||"",c=a.useMemo(()=>{const b=(r??[]).filter(E=>!!E).filter(E=>E.code!==l).map(E=>({code:E.code||"",name:E.name||E.code||""}));if(!n)return b;const y=n.toLowerCase();return b.filter(E=>E.name.toLowerCase().includes(y))},[r,n,l]),d=a.useMemo(()=>[{code:ct,name:t("inspector.webhooks.form.currentAccount")},...c],[c,t]),u=Be({name:"ACCOUNTS"})||[],p=(Be({name:"DEFAULT_ACCOUNT"})||[])[0]===ct,h=d.length>Yn,x=(b,y)=>()=>{if(y){s.setValue("ACCOUNTS",[]),s.setValue("DEFAULT_ACCOUNT",[b]);return}s.setValue("DEFAULT_ACCOUNT",[]);const E=u.includes(b)?u.filter(g=>g!==b):[...u,b];s.setValue("ACCOUNTS",E)},w=b=>{const y=b.code===ct,E=y?p:u.includes(b.code);return e.jsx("div",{children:e.jsx(X,{label:b.name,value:b.code,checked:E,onChange:x(b.code,y)})},b.code)};return e.jsxs("div",{className:"pb-1","data-testid":"webhook-accounts-section",children:[e.jsx(W,{className:"mb-6"}),e.jsx("p",{className:"text-sm leading-none mb-4 font-semibold text-foreground",children:t("inspector.webhooks.form.accountList")}),e.jsx("div",{className:"mb-4",children:e.jsx(le,{placeholder:t("inspector.webhooks.form.searchAccounts"),value:n,onSearch:o,"data-testid":"webhook-accounts-search"})}),h?e.jsx(Gn,{items:d,columns:2,estimateSize:32,height:mt,rowClassName:"grid grid-cols-2 gap-2","data-testid":"webhook-accounts-virtualized",renderItem:w}):e.jsx("div",{className:"grid grid-cols-2 gap-2 overflow-y-auto",style:{maxHeight:mt},"data-testid":"webhook-accounts-options",children:d.map(w)})]})}const $r=/^(http(s)?:\/\/)[\w.-]+(?:[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/i,qr=["API_KEY","SECRET"];function xs(t){const s={};return t.forEach(n=>{if(n.type===Mt){const o=n.value;s[n.id]=o?.map(r=>r.id)??[]}else s[n.id]=n.value??""}),s}function lt(t){const s=[];return t.filter(n=>n.type.includes(Mt)).forEach(n=>{n.value?.forEach(o=>{s.push(`${n.id}_${o.id}`)})}),s}function Wr({fields:t,webhooksList:s,mode:n,editWebhookId:o,onSubmit:r,onValidityChange:i}){const{t:l}=A(),c=n==="edit",[d,u]=a.useState(c?lt(t):[]),m=Po({mode:"onChange",defaultValues:{...xs(t),ACCOUNTS:[],DEFAULT_ACCOUNT:["default"]}}),{register:p,handleSubmit:h,formState:{errors:x,isValid:w,isDirty:b}}=m,y=Be({control:m.control,name:"ACCOUNTS"}),E=Be({control:m.control,name:"DEFAULT_ACCOUNT"});a.useEffect(()=>{c&&t.length>0&&(m.reset({...xs(t),ACCOUNTS:[],DEFAULT_ACCOUNT:["default"]},{keepDefaultValues:!1}),u(lt(t)))},[c,t]),a.useEffect(()=>{const j=c?JSON.stringify(lt(t))!==JSON.stringify(d):!1,_=(E?.length??0)>0||(y?.length??0)>0;i(w&&(j||b)&&d.length>0&&_)},[w,d,b,y,E]);const g=(j,_)=>m.watch(j)?.includes(_)??!1,f=(j,_)=>{const D=`${j.id}_${_}`,v=m.getValues(j.id)||[];!d.includes(D)?(u(O=>[...O,D]),m.setValue(j.id,[...v,_],{shouldDirty:!0})):(u(O=>O.filter(V=>V!==D)),m.setValue(j.id,v.filter(O=>O!==_),{shouldDirty:!0}))},N=j=>{const _=j.options.map(v=>`${j.id}_${v.id}`),D=j.options.map(v=>v.id);u(v=>[...v.filter(L=>!L.startsWith(`${j.id}_`)),..._]),m.setValue(j.id,D,{shouldDirty:!0})},C=j=>{const _=m.getValues(j.id)||[],D=j.options.filter(L=>!_.includes(L.id)).map(L=>L.id),v=D.map(L=>`${j.id}_${L}`);u(L=>[...L.filter(O=>!O.startsWith(`${j.id}_`)),...v]),m.setValue(j.id,D,{shouldDirty:!0})},T=j=>{u(_=>_.filter(D=>!D.startsWith(`${j.id}_`))),m.setValue(j.id,[],{shouldDirty:!0})},I=j=>s.filter(D=>D.id!==o).some(D=>typeof D.name=="string"&&D.name.toLowerCase().trim()===j.toLowerCase().trim())?l("inspector.webhooks.form.nameAlreadyExists"):!0,S=t.filter(j=>j.type===hr),z=t.filter(j=>j.type.includes(xr)),k=t.filter(j=>j.type.includes(fr));return e.jsx(Oo,{...m,children:e.jsxs("form",{id:"webhook-form","data-testid":"webhook-form",onSubmit:h(r),className:"flex flex-col gap-6",children:[S.map(j=>{const _=p(j.id,{required:{value:!0,message:l("inspector.webhooks.form.fillField")},validate:j.id==="NAME"?{validateUniqueName:I}:void 0,pattern:j.id==="ENDPOINT_URL"?{value:$r,message:l("inspector.webhooks.form.validUrl")}:void 0}),D=x[j.id]?.message;
1return e.jsx("div",{children:qr.includes(j.id)?e.jsx(Ys,{label:j.name,placeholder:j.description,..._,error:D}):e.jsx(ae,{label:j.name,placeholder:j.description,..._,error:D})},j.id)}),e.jsx(W,{}),e.jsx(hs,{testId:"webhook-oauth-section",fields:z,secretFieldIds:["OAUTH2_CLIENT_SECRET"],urlFieldId:"OAUTH2_AUTHENTICATION_URL",optionalFieldIds:gr,isEditMode:c,toggleLabel:l("inspector.webhooks.form.useOAuth"),description:l("inspector.webhooks.form.oauthDescription")}),e.jsx(hs,{testId:"webhook-hmac-section",fields:k,secretFieldIds:["HMAC_CLIENT_SECRET"],isEditMode:c,toggleLabel:l("inspector.webhooks.form.useHMAC"),description:l("inspector.webhooks.form.hmacDescription")}),e.jsx(Vr,{fields:t,isChecked:g,onTriggerChange:f,onSelectAll:N,onInverse:C,onNone:T}),!c&&e.jsx(Hr,{})]})})}const Yr=["name","endpoint","api-key","secret"],Gr=["oauth","hmac"],Xr=["a","b","c","d"];function Jr(){return e.jsxs("div",{className:"flex flex-col gap-6","data-testid":"webhook-form-loading",role:"status","aria-busy":"true",children:[Yr.map(t=>e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(K,{className:"h-4 w-24 rounded"}),e.jsx(K,{className:"h-10 w-full rounded-md"})]},t)),e.jsx(W,{}),Gr.map(t=>e.jsxs("div",{className:"rounded-lg border border-border p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(K,{className:"h-4 w-4 shrink-0 rounded"}),e.jsx(K,{className:"h-4 w-48 rounded"})]}),e.jsx(K,{className:"mt-2 ml-6 h-3 w-64 rounded"})]},t)),e.jsxs("div",{className:"flex flex-col",children:[e.jsx(W,{className:"mb-6"}),e.jsxs("div",{className:"mb-6 flex items-baseline justify-between",children:[e.jsx(K,{className:"h-4 w-24 rounded"}),e.jsx(K,{className:"h-5 w-20 rounded-full"})]}),e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx(K,{className:"h-4 w-28 rounded"}),e.jsx(K,{className:"h-4 w-16 rounded"})]}),e.jsx("div",{className:"flex flex-col gap-3",children:Xr.map(t=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(K,{className:"h-4 w-4 shrink-0 rounded"}),e.jsx(K,{className:"h-4 w-40 rounded"})]},t))})]})]})}function Zr({open:t,mode:s,fields:n,webhooksList:o,editWebhookId:r,isLoading:i,isSubmitting:l,isFormValid:c,onClose:d,onSubmit:u,onValidityChange:m}){const{t:p}=A(),h=p(s==="create"?"inspector.webhooks.form.createTitle":"inspector.webhooks.form.editTitle"),x=p(s==="create"?"inspector.webhooks.form.create":"inspector.webhooks.form.save");return e.jsxs(St,{open:t,onClose:d,side:"right",width:Lt,showFooter:!1,title:h,"data-testid":"webhook-form-panel",children:[e.jsx("div",{children:i?e.jsx(Jr,{}):e.jsx(Wr,{fields:n,webhooksList:o,mode:s,editWebhookId:r,onSubmit:u,onValidityChange:m},`${s}-${r??"new"}`)}),e.jsxs("div",{className:"mb-6 flex items-center justify-end gap-2 border-t px-6 pt-4 border-border",children:[e.jsx(M,{variant:"outline",onClick:d,disabled:l,children:p("inspector.webhooks.form.cancel")}),e.jsx(M,{type:"submit",form:"webhook-form",loading:l,disabled:!c||l,"data-testid":"webhook-form-submit",children:l?p("inspector.webhooks.form.saving"):x})]})]})}function Qr({accountCode:t,mode:s,selectedWebhook:n,webhooks:o,isFormValid:r,onClose:i,onSuccess:l,onValidityChange:c}){const{fields:d,isLoadingParams:u,isLoadingDetail:m,isSubmitting:p,handleCreate:h,handleEdit:x}=zr(t,s==="edit"?n:null,l),w=b=>{s==="create"?h(b):s==="edit"&&n&&x(n.id.toString(),b)};return e.jsx(Zr,{open:!0,mode:s,fields:d,webhooksList:o,editWebhookId:n?.id,isLoading:u||s==="edit"&&m,isSubmitting:p,isFormValid:r,onClose:i,onSubmit:w,onValidityChange:c})}function ei({isOpen:t,onClose:s,onConfirm:n,isLoading:o=!1,webhookName:r}){const{t:i}=A();return a.useEffect(()=>{if(!t)return;const l=c=>{c.key==="Escape"&&s()};return document.addEventListener("keydown",l),()=>document.removeEventListener("keydown",l)},[t,s]),t?jt.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[2000011] flex items-center justify-center p-4","data-testid":"delete-webhook-dialog",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:s,"aria-hidden":"true"}),e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":i("inspector.webhooks.delete.title"),className:"relative z-10 flex w-full max-w-md flex-col rounded-lg border shadow-lg border-border bg-card",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-6 py-4 border-border",children:[e.jsx("h3",{className:"text-base font-semibold text-foreground",children:i("inspector.webhooks.delete.title")}),e.jsx("div",{children:e.jsx(M,{variant:"ghost",size:"icon",onClick:s,"aria-label":i("inspector.webhooks.delete.cancel"),"data-testid":"delete-webhook-close",children:e.jsx(F,{name:"X",size:"sm"})})})]}),e.jsx("div",{className:"px-6 py-5",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:r?i("inspector.webhooks.delete.descriptionNamed",{name:r}):i("inspector.webhooks.delete.description")})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t px-6 py-4 border-border",children:[e.jsx(M,{variant:"outline",onClick:s,disabled:o,children:i("inspector.webhooks.delete.cancel")}),e.jsx(M,{variant:"destructive",onClick:n,disabled:o,"data-testid":"delete-webhook-confirm",children:i(o?"inspector.webhooks.delete.deleting":"inspector.webhooks.delete.confirm")})]})]})]}),document.body):null}const fs={TODAY:"inspector.webhooks.logs.filters.today",LAST_3_DAYS:"inspector.webhooks.logs.filters.last3Days",LAST_7_DAYS:"inspector.webhooks.logs.filters.last7Days",LAST_30_DAYS:"inspector.webhooks.logs.filters.last30Days",THIS_MONTH:"inspector.webhooks.logs.filters.thisMonth",CUSTOM:"inspector.webhooks.logs.filters.custom"};function ti({filters:t,onFiltersChange:s,accounts:n}){const{t:o}=A(),[r,i]=a.useState(t.originId),[l,c]=a.useState(t.webhookId);a.useEffect(()=>{i(t.originId)},[t.originId]),a.useEffect(()=>{c(t.webhookId)},[t.webhookId]);const d=a.useMemo(()=>n.map(k=>({label:k.name||k.code,value:k.code})),[n]),u=a.useMemo(()=>yr.map(k=>({label:k,value:k})),[]),m=a.useMemo(()=>jr.map(k=>({label:k.charAt(0)+k.slice(1).toLowerCase(),value:k})),[]),p=a.useCallback(k=>{const j=d.map(v=>v.value),D=J()&&j.length>0&&j.every(v=>k.includes(v))?[]:k;s({...t,accountCodes:D})},[d,t,s]),h=a.useCallback(k=>s({...t,methods:k}),[t,s]),x=a.useCallback(k=>s({...t,webhookTypes:k}),[t,s]),w=a.useCallback(k=>{if(k==="CUSTOM"){s({...t,dateValue:k});return}const j=pt(k);s({...t,dateValue:k,dateInit:j.dateInit,dateEnd:j.dateEnd})},[t,s]),b=a.useCallback(k=>s({...t,dateInit:k}),[t,s]),y=a.useCallback(k=>s({...t,dateEnd:k}),[t,s]),E=a.useCallback(()=>{const k=r.trim();k!==t.originId&&s({...t,originId:k})},[r,t,s]),g=a.useCallback(()=>{const k=l.trim();k!==t.webhookId&&s({...t,webhookId:k})},[l,t,s]),f=a.useCallback(k=>{k.key==="Enter"&&(k.preventDefault(),k.target.blur())},[]),N=a.useCallback(()=>e.jsx("div",{className:"w-[280px] p-3",children:e.jsx(ae,{"data-testid":"webhooks-logs-origin-id",label:o("inspector.webhooks.logs.filters.originId"),placeholder:o("inspector.webhooks.logs.filters.originIdPlaceholder"),value:r,onChange:k=>i(k.target.value),onBlur:E,onKeyDown:f})}),[o,r,E,f]),C=a.useCallback(()=>e.jsx("div",{className:"w-[280px] p-3",children:e.jsx(ae,{"data-testid":"webhooks-logs-webhook-id",label:o("inspector.webhooks.logs.filters.webhookId"),placeholder:o("inspector.webhooks.logs.filters.webhookIdPlaceholder"),value:l,onCh
1ange:k=>c(k.target.value),onBlur:g,onKeyDown:f})}),[o,l,g,f]),T=a.useMemo(()=>{const k=[];return d.length>0&&k.push({id:"accounts",icon:"Buildings",label:o("inspector.webhooks.logs.filters.accounts"),type:"checkbox",items:d,selectedValues:vt(t.accountCodes,d.map(j=>j.value),J()),onChange:p,searchable:!0,showActions:!0}),k.push({id:"methods",icon:"Code",label:o("inspector.webhooks.logs.filters.methods"),type:"checkbox",items:u,selectedValues:t.methods,onChange:h,searchable:!0,showActions:!0}),k.push({id:"webhookTypes",icon:"Notification",label:o("inspector.webhooks.logs.filters.webhookTypes"),type:"checkbox",items:m,selectedValues:t.webhookTypes,onChange:x,searchable:!0,showActions:!0}),k.push({id:"date",icon:"CalendarBlank",label:o("inspector.webhooks.logs.filters.date"),type:"date",clearable:!1,dateValue:t.dateValue,dateInit:t.dateInit,dateEnd:t.dateEnd,dateMode:"range",showAllTime:!1,onDateValueChange:w,onDateInitChange:b,onDateEndChange:y}),k.push({id:"originId",icon:"Hash",label:o("inspector.webhooks.logs.filters.originId"),t
1ype:"custom",renderContent:N}),k.push({id:"webhookId",icon:"Hash",label:o("inspector.webhooks.logs.filters.webhookId"),type:"custom",renderContent:C}),k},[o,d,u,m,t.accountCodes,t.methods,t.webhookTypes,t.dateValue,t.dateInit,t.dateEnd,p,h,x,w,b,y,N,C]),I=a.useMemo(()=>{const k=[];return d.length>0&&k.push({id:"accounts",label:Nt(o,t.accountCodes.length,d.length),...J()&&{icon:"User"}}),t.methods.length>0&&k.push({id:"methods",label:t.methods.join(", ")}),t.webhookTypes.length>0&&k.push({id:"webhookTypes",label:`${t.webhookTypes.length} ${o("inspector.webhooks.logs.filters.webhookTypes").toLowerCase()}`}),t.dateValue&&k.push({id:"date",label:fs[t.dateValue]?o(fs[t.dateValue]):t.dateValue}),t.originId&&k.push({id:"originId",label:`${o("inspector.webhooks.logs.filters.originId")}: ${t.originId}`}),t.webhookId&&k.push({id:"webhookId",label:`${o("inspector.webhooks.logs.filters.webhookId")}: ${t.webhookId}`}),k},[t,o]),S=a.useCallback(k=>{if(k==="accounts")s({...t,accountCodes:[]});else if(k==="methods")s({...t,methods:[]});else if(k==="webhookTypes")s({...t,webhookTypes:[]});else if(k==="originId")i(""),s({...t,originId:""});else if(k==="webhookId")c(""),s({...t,webhookId:""});else if(k==="date"){const j=pt(qe);s({...t,dateValue:qe,dateInit:j.dateInit,dateEnd:j.dateEnd})}},[t,s]),z=a.useCallback(()=>{i(""),c(""),s({...t,accountCodes:[],methods:[],webhookTypes:[],originId:"",webhookId:""})},[t,s]);return e.jsx("div",{"data-testid":"webhooks-logs-filter-bar",className:"flex items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(De,{filters:T,translations:{addFilter:o("inspector.webhooks.logs.addFilter")},appliedFilters:I,onRemoveFilter:S,onClearAllFilters:z,maxVisibleTags:4})})})}function si(t,s="en-US"){if(!t)return"-";const n=new Date(t);return Number.isNaN(n.getTime())?t:new Intl.DateTimeFormat(s,{month:"short",day:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0,timeZoneName:"short"}).format(n)}function ni(t){return t?t.charAt(0)+t.slice(1).toLowerCase():"-"}const oi="sticky right-0 z-10 w-10 border-l border-border bg-card pl-4 pr-4!";function ai({log:t,accountName:s,onResend:n}){const{t:o,i18n:r}=A(),i=t.response_status>=400,l={actions:[{key:"resend",name:o("inspector.webhooks.logs.resend"),icon:"ArrowsClockwise",allowed:!0,handleClick:()=>n(t.trace_id)}]};return e.jsxs(q,{"data-testid":"webhooks-logs-row",children:[e.jsx(U,{className:"whitespace-nowrap",children:si(t.created_at,r.language)}),e.jsx(U,{children:t.account_code||"-"}),e.jsx(U,{children:s||"-"}),e.jsx(U,{children:t.id??"-"}),e.jsx(U,{children:t.http_method?e.jsx(ge,{method:t.http_method}):"-"}),e.jsx(U,{className:"max-w-[220px] truncate text-muted-foreground",children:t.url||"-"}),e.jsx(U,{children:e.jsx(ye,{code:t.response_status})}),e.jsx(U,{children:e.jsx(Y,{variant:"secondary",children:ni(t.type)})}),e.jsx(U,{className:"text-muted-foreground",children:t.trace_id||"-"}),e.jsx(U,{className:"text-muted-foreground",children:t.exception||"-"}),e.jsx(U,{className:oi,children:i&&e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(oe,{content:o("inspector.webhooks.actionsTooltip","Actions"),contentProps:{side:"left"},children:e.jsx(It,{options:l,ariaLabel:o("inspector.webhooks.logs.a11y.rowActions","More actions for log {{id}}",{id:t.trace_id})})})})})]})}const gs=[{key:"createdDate",width:"min-w-44",fallback:"Created date"},{key:"account",width:"min-w-32",fallback:"Account"},{key:"accountName",width:"min-w-32",fallback:"Account name"},{key:"webhookId",width:"min-w-32",fallback:"Webhook ID"},{key:"httpMethod",width:"min-w-32",fallback:"Method"},{key:"url",width:"min-w-56",fallback:"URL"},{key:"responseStatus",width:"min-w-32",fallback:"Response"},{key:"type",width:"min-w-28",fallback:"Type"},{key:"traceId",width:"min-w-36",fallback:"Trace ID"},{key:"exception",width:"min-w-40",fallback:"Exception"}],ri=[0,1,2,3,4],ii="sticky right-0 z-10 w-10 border-l border-border pl-4 pr-4!",ci="sticky right-0 z-10 w-10 border-l border-border bg-card pl-4 pr-4!";function li({logs:t,isLoading:s,hasPageData:n,accountsMap:o,onResend:r}){const{t:i}=A(),l=e.jsxs(q,{children:[gs.map(c=>e.jsx($,{className:P("whitespace-nowrap",c.width),children:i(`inspector.webhooks.logs.table.${c.key}`,c.fallback)},c.key)),e.jsx($,{className:ii})]});return s?e.jsxs(ee,{className:"min-w-[1600px]","data-testid":"webhooks-logs-table-loading",children:[e.jsx(te,{children:l}),e.jsx(se,{children:ri.map(c=>e.jsxs(q,{children:[gs.map(d=>e.jsx(U,{children:e.jsx(K,{className:"h-4 w-16 rounded"})},d.key)),e.jsx(U,{className:ci,children:e.jsx(K,{className:"h-6 w-6 rounded"})})]},c))})]}):t.length===0&&!n?e.jsx("div",{"data-testid":"webhooks-logs-empty",children:e.jsx(he,{icon:"ListChecks",title:i("inspector.webhooks.logs.emptyTitle","No delivery logs yet"),description:i("inspector.webhooks.logs.emptyDescription","Webhook delivery attempts will appear here once your endpoint receives an event.")})}):e.jsxs(ee,{className:"min-w-[1600px]","data-testid":"webhooks-logs-table",children:[e.jsx(te,{children:l}),e.jsxs(se,{children:[t.map(c=>e.jsx(ai,{log:c,accountName:o[c.account_code],onResend:r},`${c.id}-${c.trace_id}`)),t.length===0&&e.jsx(q,{children:e.jsx(U,{colSpan:11,className:"py-8 text-center text-sm text-muted-foreground",children:i("inspector.webhooks.logs.noResults","N
1o logs match your search.")})})]})]})}function bs(t,s){if(t==="webhook-logs"){const o=[{id:"created_at",label:s("inspector.export.col.createdDate")},{id:"account_code",label:s("inspector.export.col.account")},{id:"webhook_id",label:s("inspector.export.col.webhookId")},{id:"http_method",label:s("inspector.export.col.httpMethod")},{id:"url",label:s("inspector.export.col.url")},{id:"response_status",label:s("inspector.export.col.responseStatus")},{id:"type",label:s("inspector.export.col.type")},{id:"trace_id",label:s("inspector.export.col.traceId")},{id:"exception",label:s("inspector.export.col.exception")},{id:"origin_id",label:s("inspector.export.col.originId")},{id:"connect_timeout",label:s("inspector.export.col.connectTimeout")},{id:"read_timeout",label:s("inspector.export.col.readTimeout")}];return{all:o,defaultActiveIds:o.map(r=>r.id)}}const n=[{id:"created_at",label:s("inspector.export.col.createdDate")},{id:"account_code",label:s("inspector.export.col.account")},{id:"status_code",label:s("inspector.export.col.status")},{id:"method",label:s("inspector.export.col.method")},{id:"url",label:s("inspector.export.col.url")}];return{all:n,defaultActiveIds:n.map(o=>o.id)}}var Z=(t=>(t.DEFAULT="DEFAULT",t.CUSTOM="CUSTOM",t))(Z||{});const di=26;function ui({column:t,iconName:s,index:n,onAction:o,onDragStart:r,onDropOnItem:i}){const{t:l}=A(),c=t.label.length>di,d=s==="PlusCircle"?l("inspector.a11y.addColumn","Add column {{name}}",{name:t.label}):l("inspector.a11y.removeColumn","Remove column {{name}}",{name:t.label});return e.jsxs("div",{className:"flex items-center gap-2 rounded-md border px-3 py-2 border-border bg-card",draggable:!0,"data-index":n,"data-testid":`devx-export-column-${t.id}`,onDragStart:r,onDrop:i,onDragOver:u=>u.preventDefault(),children:[e.jsx(F,{name:"DotsSixVertical",size:"md",className:"text-muted-foreground"}),e.jsx("div",{className:"flex-1 min-w-0 truncate",children:e.jsx(oe,{content:t.label,show:c,children:e.jsx("span",{className:"text-sm text-foreground",children:t.label})})}),e.jsx("button",{type:"button",onClick:o,"aria-label":d,"data-testid":`devx-export-column-${t.id}-action`,className:"inline-flex items-center bg-transparent border-0 p-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 cursor-pointer text-foreground",children:e.jsx(F,{name:s,size:"sm"})})]})}function mi({}){const{t}=A();return e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-center","data-testid":"devx-export-columns-empty",children:[e.jsx("div",{className:"text-base font-semibold text-foreground",children:t("inspector.export.noColumnsYetTitle")}),e.jsx("div",{className:"mt-2 max-w-[280px] text-sm text-muted-foreground",children:t("inspector.export.noColumnsYetDescription")})]})}const ys=t=>{const s=t.dataTransfer.getData("application/json");if(!s)return null;try{return JSON.parse(s)}catch{return null}};function js({listIndex:t,items:s,iconName:n,enableEmptyState:o,onAction:r,onDropItem:i,onDropToEnd:l}){const c=a.useCallback(m=>p=>{p.dataTransfer.setData("application/json",JSON.stringify(m)),p.dataTransfer.effectAllowed="move"},[]),d=a.useCallback(m=>p=>{p.preventDefault(),p.stopPropagation();const h=ys(p);h&&i(h,m)},[i]),u=a.useCallback(m=>{m.preventDefault();const p=ys(m);p&&l(p)},[l]);return s.length===0&&o?e.jsx(mi,{}):e.jsx("div",{className:"flex flex-col gap-2",onDrop:u,onDragOver:m=>m.preventDefault(),"data-list-index":t,"data-testid":`devx-export-column-list-${t}`,children:s.map((m,p)=>e.jsx(ui,{column:m,iconName:n,index:p,onAction:()=>r(m),onDragStart:c({fromListIndex:t,itemId:m.id}),onDropOnItem:d(p)},m.id))})}function vs({value:t,onChange:s,onClear:n,"data-testid":o}){const{t:r}=A(),i=l=>{l===""&&n(),s(l)};return e.jsx(le,{placeholder:r("inspector.export.searchColumnsPlaceholder"),value:t,onSearch:i,searchOnChange:!0,className:"mb-4","data-testid":o})}const pi=(t,s,n)=>{const o=Array.from(t),[r]=o.splice(s,1);return o.splice(n,0,r),o},ws=(t,s,n,o,r)=>{const i=[[...t[0]],[...t[1]]],l=i[s],c=i[n],[d]=l.splice(o,1);return d?(c.splice(r,0,d),i):t},Ns=(t,s)=>{const n=s.trim().toUpperCase();return n.length===0?t:t.filter(o=>o.label.toUpperCase().includes(n))},dt=(t,s)=>{const n=s.map(i=>t.find(l=>l.id===i)).filter(i=>!!i),o=new Set(n.map(i=>i.id));return[t.filter(i=>!o.has(i.id)),n]};function hi({allColumns:t,selectedIds:s,isDisabled:n=!1,onChange:o}){const{t:r}=A(),i=a.useRef(o),[l,c]=a.useState(Z.DEFAULT),[d,u]=a.useState(()=>
1dt(t,s)),[m,p]=a.useState(()=>dt(t,s)),[h,x]=a.useState(""),[w,b]=a.useState(""),y=a.useMemo(()=>m[1].map(S=>S.id),[m]),E=a.useRef(t),g=a.useRef(s);E.current=t,g.current=s;const f=a.useCallback(()=>{const S=dt(E.current,g.current);u(S),p(S),x(""),b("")},[]);a.useEffect(()=>{f(),c(Z.DEFAULT)},[t]),a.useEffect(()=>{i.current=o},[o]),a.useEffect(()=>{i.current(y)},[y]),a.useEffect(()=>{const S=h.trim().length>0,z=w.trim().length>0;if(!S&&!z){u(m);return}u([S?Ns(m[0],h):m[0],z?Ns(m[1],w):m[1]])},[m,h,w]);const N=S=>{const z=S;if(c(z),z===Z.DEFAULT)f();else if(z===Z.CUSTOM){const k=[t,[]];u(k),p(k),x(""),b("")}},C=(S,z)=>{if(n)return;const k=S===0?1:0,j=m[S].findIndex(D=>D.id===z.id);if(j===-1)return;const _=ws(m,S,k,j,m[k].length);p(_),u(_)},T=S=>(z,k)=>{if(n||l!==Z.CUSTOM)return;const j=z.fromListIndex,_=m[j].findIndex(v=>v.id===z.itemId);if(_===-1)return;let D;if(j===S){const v=pi(m[S],_,k);D=S===0?[v,m[1]]:[m[0],v]}else D=ws(m,j,S,_,k);p(D),u(D)},I=S=>z=>{T(S)(z,m[S].length)};return e.jsxs("div",{className:"flex flex-col gap-3","data-testid":"devx-export-columns",children:[e.jsx(W,{orientation:"horizontal"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-base font-medium text-foreground",children:r("inspector.export.columns")}),e.jsx("div",{children:e.jsx(Mo,{name:"columnsMode",orientation:"horizontal",value:l,onChange:N,options:[{label:r("inspector.export.default"),value:Z.DEFAULT},{label:r("inspector.export.custom"),value:Z.CUSTOM}]})})]}),l===Z.DEFAULT&&e.jsx("div",{className:"flex flex-wrap gap-2","data-testid":"devx-export-columns-default",children:m[1].map(S=>e.jsx(Y,{className:"rounded-full bg-muted text-foreground",children:S.label},S.id))}),l===Z.CUSTOM&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"rounded-lg border p-4 border-border",children:[e.jsx("p",{className:"mb-4 font-bold text-base text-foreground",children:r("inspector.export.availableColumns")}),e.jsx("div",{children:e.jsx(vs,{value:h,onChange:x,onClear:()=>x(""),"data-testid":"devx-export-columns-search-available"})}),e.jsx(js,{listIndex:0,items:d[0],iconName:"PlusCircle",onAction:S=>C(0,S),onDropItem:T(0),onDropToEnd:I(0)})]}),e.jsxs("div",{className:"rounded-lg border p-4 border-border",children:[e.jsx("p",{className:"mb-4 font-bold text-base text-foreground",children:r("inspector.export.activeColumns")}),e.jsx("div",{children:e.jsx(vs,{value:w,onChange:b,onClear:()=>b(""),"data-testid":"devx-export-columns-search-active"})}),e.jsx(js,{listIndex:1,items:d[1],iconName:"MinusCircle",enableEmptyState:!0,onAction:S=>C(1,S),onDropItem:T(1),onDropToEnd:I(1)})]})]})]})}const xi=/^[a-zA-Z0-9\s\-_.=*[\]{}|!,\\:;]+$/,ks=30,fi=6;function gi(){return yt({mutationFn:async({tab:t,payload:s})=>{const n=ne.getInstance(),o=s;return(t==="webhook-logs"?await n.postWebhookLogsExport(o):await n.postApiLogsExport(o))?.data},useErrorBoundary:!1})}function Cs(t){return t?.toISOString()}function fe(t){return t&&t.length>0?t:void 0}function bi(t,s,n){const{t:o}=A(),{getTimezone:r}=Uo(),[i,l]=a.useState(!1),c=gi(),d=Fo();return{handleExport:a.useCallback(async m=>{l(!0);try{const p=r()||"UTC",h=Cs(s.dateInit),x=Cs(s.dateEnd),w=fe(s.accountCodes);if(t==="webhook-logs"){const b={export_name:m.reportName,start_date:h??"",end_date:x??"",timezone:p,accounts:w,columns:m.columns,webhook_types:fe(s.webhookTypes),http_methods:fe(s.methods),response_statuses:fe(s.responseStatuses),trace_id:s.traceId?.trim()||void 0};await d.mutateAsync({tab:"webhook-logs",payload:b})}else{const b={account_ids:w,start_date:h,end_date:x,status_codes:fe(s.statusCodes),methods:fe(s.methods),search:s.search?.trim()||void 0};await c.mutateAsync({tab:"api-logs",payload:{export_name:m.reportName,filters:b}})}B.success(o("inspector.export.started")),n()}catch{B.error(o("inspector.export.exportError"))}finally{l(!1)}},[t,s,c,d,r,n,o]),isExporting:i}}function yi(t){if(t)try{const s=document.createElement("a");s.href=t,s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s)}catch{window.location.assign(t)}}function ji(t){return t?t==="IN_PROCESS"?"PROCESSING":t:"PENDING"}function vi(t){switch(t){case"COMPLETED":return{variant:"success",icon:"CheckCircle"};case"FAILED":return{variant:"error",icon:"XCircle"};case"IN_PROCESS":case"PROCESSING":return{variant:"info",icon:"CircleNotch"};default:return{variant:"warning",icon:"Clock"}}}function wi(t){return t?co(new Date,new Date(t))<=fi:!1}function Ni({exportTab:t,refreshKey:s}){const{t:n}=A(),o=po({tab:t,page:0,size:50}),{isLoading:r,refetch:i}=o,c=(o.isFetching??!1)&&!r;a.useEffect(()=>{s&&i()},[s,i]);const d=a.useMemo(()=>{const h=new Date;return h.setDate(h.getDate()-ks),[...o.data?.exports??[]].filter(w=>new Date(w.created_at)>=h).sort((w,b)=>new Date(b.created_at).getTime()-new Date(w.created_at).getTime())},[o.data]),[u,m]=a.useState(null),p=a.useCallback((h,x)=>{m(h);try{yi(x)}finally{m(null)}},[]);return r?e.jsxs("div",{className:"flex flex-col gap-2 py-4","data-testid":"devx-export-downloads-loading",children:[e.jsx(K,{className:"h-16 w-full rounded-lg"}),e.jsx(K,{className:"h-16 w-full rounded-lg"}),e.jsx(K,{className:"h-16 w-full rounded-lg"})]}):e.jsxs("div",{className:"flex flex-col gap-4","data-testid":"devx-export-downloads",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:n("inspector.export.downloadsRetentionInfo",{days:ks})}),e.jsx("div",{children:e.jsx(M,{variant:"ghost",size:"sm",startIcon:"ArrowsClockwise",onClick:()=>i(),disabled:c,"data-testid":"devx-export-downloads-refresh",children:n("inspector.export.refresh")})})]}),d.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center","data-testid":"devx-export-downloads-empty",children:[e.jsx(F,{name:"FileCsv",size:"lg",className:"mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:n("inspector.export.noDownloadsAvailable")})]}):e.jsxs("div",{className:"flex flex-col gap-2",children:[c&&e.jsx(K,{className:"h-16 w-full rounded-lg"}),e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-xs font-medium text-muted-foreground bg-muted",children:[e.jsx("th",{className:"px-4 py-3 w-[200px]",children:n("inspector.export.fileName")}
1),e.jsx("th",{className:"px-4 py-3 w-[250px]",children:n("inspector.export.creationDate")}),e.jsx("th",{className:"px-4 py-3 w-[200px] text-center",children:n("inspector.export.action")})]})}),e.jsx("tbody",{children:d.map(h=>{const x=ji(h.status),w=vi(x),b=x==="COMPLETED"&&!!h.download_url&&wi(h.created_at),y=u===h.export_id;return e.jsxs("tr",{"data-testid":"devx-export-download-row",className:"border-b border-border",children:[e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:"text-sm font-medium truncate block max-w-[180px] text-foreground",title:h.export_name,children:h.export_name})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:"text-sm text-foreground",children:io(new Date(h.created_at),"EEE, MMM d, yyyy HH:mm:ss")})}),e.jsx("td",{className:"px-4 py-3 text-center",children:x==="COMPLETED"?e.jsx("div",{children:e.jsx(M,{variant:"ghost",size:"sm",startIcon:"Download",disabled:!b||y,onClick:()=>p(h.export_id,h.download_url),"data-testid":"devx-export-download-action",children:n("inspector.export.download")})}):e.jsx("div",{children:e.jsx(Y,{variant:w.variant,startIcon:w.icon,children:n(`inspector.export.status.${x.toLowerCase()}`)})})})]},h.export_id)})})]})]})]})}function ki({isOpen:t,onClose:s,exportTab:n,currentFilters:o}){const{t:r}=A(),i=a.useMemo(()=>bs(n,r),[n]),[l,c]=a.useState(0),[d,u]=a.useState(""),[m,p]=a.useState(i.defaultActiveIds),[h,x]=a.useState(0);a.useEffect(()=>{t||(u(""),p(i.defaultActiveIds),c(0))},[t]),a.useEffect(()=>{t&&(u(""),p(bs(n,r).defaultActiveIds),c(0))},[t,n]);const w=a.useCallback(()=>{x(C=>C+1),s()},[s]),{handleExport:b,isExporting:y}=bi(n,o,w),E=d.trim().length>0&&xi.test(d),g=E&&m.length>0&&!y,f=a.useCallback(()=>{g&&b({reportName:d.trim(),columns:m})},[g,b,d,m]),N=[{label:r("inspector.export.configure"),content:e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx("div",{children:e.jsx(Ge,{icon:"Info",description:r("inspector.export.filtersAppliedInfo"),variant:"default"})}),e.jsx("div",{children:e.jsx(ae,{"data-testid":"devx-export-report-name",label:r("inspector.export.reportName"),placeholder:r("inspector.export.reportNamePlaceholder"),value:d,onChange:C=>u(C.target.value),disabled:y,error:d.length>0&&!E?r("inspector.export.reportNameInvalid"):void 0})}),e.jsx(hi,{allColumns:i.all,selectedIds:m,isDisabled:y,onChange:p})]})},{label:r("inspector.export.downloads"),content:e.jsx(Ni,{exportTab:n,refreshKey:h})}];return e.jsx(St,{open:t,onClose:s,side:"right",width:Lt,showFooter:!1,title:r("inspector.export.title"),"data-testid":"devx-export-dialog",children:e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Le,{defaultTab:l,onChange:c,tabs:N},l),l===0&&e.jsxs("div",{className:"flex items-center justify-end gap-3 border-t border-border pt-6",children:[e.jsx(M,{variant:"outline",onClick:s,"data-testid":"devx-export-cancel",children:r("inspector.export.cancel")}),e.jsx(M,{onClick:f,disabled:!g,loading:y,"data-testid":"devx-export-submit",children:r("inspector.export.export")})]})]})})}function xn({exportTab:t,currentFilters:s}){const{t:n}=A(),[o,r]=a.useState(!1);return e.jsxs("div",{className:"shrink-0",children:[e.jsx(M,{variant:"outline",size:"sm",startIcon:"Export",onClick:()=>r(!0),"data-testid":"devx-export-button",children:n("inspector.export.export")}),o&&e.jsx(ki,{isOpen:!0,onClose:()=>r(!1),exportTab:t,currentFilters:s})]})}const Es=pt(qe),Ci={accountCodes:[],methods:[],webhookTypes:[],dateValue:qe,dateInit:Es.dateInit,dateEnd:Es.dateEnd,originId:"",webhookId:""};function Ei({organizationCode:t}){const{t:s}=A(),[n,o]=a.useState(""),[r,i]=a.useState(Ci),[l,c]=a.useState(1),{accounts:d}=be({roles:[]}),u=a.useMemo(()=>(d??[]).filter(T=>!!T).map(T=>({code:T.code||"",name:T.name||T.code||""})),[d]),m=a.useMemo(()=>{const T={};return u.forEach(I=>{I.code&&(T[I.code]=I.name)}),T},[u]),{logs:p,totalPages:h,isLoading:x,isError:w,hasPageData:b,refetch:y}=Kr({organizationCode:t,filters:r,searchTerm:n,page:l}),{resend:E}=Or(),g=a.useCallback(T=>{o(T),c(1)},[]),f=a.useCallback(T=>{i(T),c(1)},[]),N=a.useCallback(T=>{E(T)},[E]),C=a.useCallback(T=>{c(T)},[]);return e.jsxs("div",{className:"flex flex-col gap-6","data-testid":"webhooks-logs",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("div",{className:"w-full max-w-sm",children:e.jsx(le,{"data-testid":"webhooks-logs-search",value:n,onSearch:g,placeholder:s("inspector.webhooks.logs.searchPlaceholder"),searchOnChange:!0})}),e.jsx(xn,{exportTab:"webhook-logs",currentFilters:{accountCodes:r.accountCodes,methods:r.methods,webhookTypes:r.webhookTypes,traceId:n.trim()||void 0,dateInit:r.dateInit,dateEnd:r.dateEnd}})]}),e.jsx(ti,{filters:r,onFiltersChange:f,accounts:u}),w?e.jsxs("div",{"data-testid":"webhooks-logs-error",className:"flex flex-col items-center justify-center px-6 py-12",children:[e.jsx("p",{className:"text-sm font-medium leading-none mb-3 text-muted-foreground",children:s("inspector.webhooks.logs.errorLoading")}),e.jsx("div",{children:e.jsx(M,{variant:"outline",size:"sm",startIcon:"ArrowsClockwise",onClick:y,children:s("inspector.webhooks.retry")})})]}):e.jsxs(e.Fragment,{children:[e.jsx(li,{logs:p,isLoading:x,hasPageData:b,accountsMap:m,onResend:N}),h>1&&e.jsx("div",{className:"flex justify-end",children:e.jsx(_t,{currentPage:l,totalPages:h,maxVisiblePages:5,onPageClick:C,onClickPrev:()=>C(Math.max(1,l-1)),onClickNext:()=>C(Math.min(h,l+1))})})]})]})}function Ti(){const{t}=A(),{accountCode:s,organizationCode:n,canView:o,canManage:r,isLoading:i}=Dr(),[l,c]=a.useState(""),d=l||s;Re(()=>c(""));
1const[u,m]=a.useState(""),[p,h]=a.useState(null),[x,w]=a.useState(null),[b,y]=a.useState(!1),[E,g]=a.useState(!1),[f,N]=a.useState(null),{webhooks:C,isLoading:T,isError:I,refetch:S}=Lr({accountCode:d,searchTerm:u,enabled:o}),{toggleStatus:z}=Rr(d,S),k=a.useCallback(()=>{h(null),w(null)},[]),j=a.useCallback(()=>{k(),S()},[k,S]),_=a.useCallback(()=>{g(!1),x?.id===f?.id&&k(),N(null),S()},[x,f,k,S]),{handleDelete:D,isLoading:v}=Pr(d,_),L=a.useCallback(()=>{w(null),h("create")},[]),O=a.useCallback(re=>{w(re),h("edit")},[]),V=a.useCallback(re=>{N(re),g(!0)},[]),de=a.useCallback(()=>{f&&D(f.id.toString())},[f,D]),ue=p!==null&&r,Qe=e.jsxs("div",{"data-testid":"webhooks-configuration",children:[e.jsx("div",{className:"min-w-0",children:e.jsx(_r,{webhooks:C,isLoading:T,isError:I,canManage:r,searchTerm:u,onSearchChange:m,onAccountChange:c,onToggleStatus:z,onEdit:O,onDelete:V,onCreate:L,onRefresh:S})}),ue&&p&&e.jsx(Qr,{accountCode:d,mode:p,selectedWebhook:x,webhooks:C,isFormValid:b,onClose:k,onSuccess:j,onValidityChange:y})]}),je=e.jsx(Ei,{organizationCode:n}),et=[{id:"configuration",label:t("inspector.webhooks.configurationTab"),content:Qe},{id:"logs",label:t("inspector.webhooks.logsTab"),content:je}];return i?null:o?e.jsxs("div",{className:"flex flex-col","data-testid":"webhooks-tab",children:[e.jsx(Le,{tabs:et,defaultTab:0,variant:"pill"}),e.jsx(ei,{isOpen:E,onClose:()=>{g(!1),N(null)},onConfirm:de,isLoading:v,webhookName:f?.name})]}):e.jsx("div",{"data-testid":"webhooks-tab",children:e.jsx($s,{text:t("inspector.webhooks.noPermission"),"data-testid":"access-denied-alert"})})}const _i=["GET","POST","PUT","DELETE","PATCH"],We="LAST_7_DAYS",Si=25;function ht(t){const s=new Date,n=new Date(s);n.setHours(23,59,59,999);const o={TODAY:0,LAST_3_DAYS:2,LAST_7_DAYS:6,LAST_30_DAYS:29};if(o[t]!==void 0){const r=new Date(s);return r.setDate(r.getDate()-o[t]),r.setHours(0,0,0,0),{dateInit:r,dateEnd:n}}if(t==="THIS_MONTH"){const r=new Date(s.getFullYear(),s.getMonth(),1);return r.setHours(0,0,0,0),{dateInit:r,dateEnd:n}}return{dateInit:void 0,dateEnd:void 0}}const Ts={TODAY:"inspector.apiLogs.filters.today",LAST_3_DAYS:"inspector.apiLogs.filters.last3Days",LAST_7_DAYS:"inspector.apiLogs.filters.last7Days",LAST_30_DAYS:"inspector.apiLogs.filters.last30Days",THIS_MONTH:"inspector.apiLogs.filters.thisMonth",CUSTOM:"inspector.apiLogs.filters.custom"};function Ai({filters:t,onFiltersChange:s,onRefresh:n,isRefreshing:o}){const{t:r}=A(),{accounts:i}=be({roles:[]}),{isTesting:l}=Ie(),c=a.useMemo(()=>(i??[]).filter(f=>!!f).map(f=>({label:f.name||f.code||"",value:Ye(f,l)})),[i,l]),d=a.useMemo(()=>_i.map(f=>({label:f,value:f})),[]),u=a.useCallback(f=>{const N=c.map(I=>I.value),T=J()&&N.length>0&&N.every(I=>f.includes(I))?[]:f;s(I=>({...I,accounts:T}))},[c,s]),m=a.useCallback(f=>{s(N=>({...N,methods:f}))},[s]),p=a.useCallback(f=>{if(f==="CUSTOM"){s(C=>({...C,dateValue:f}));return}const N=ht(f);s(C=>({...C,dateValue:f,dateInit:N.dateInit,dateEnd:N.dateEnd}))},[s]),h=a.useCallback(f=>{s(N=>({...N,dateInit:f}))},[s]),x=a.useCallback(f=>{s(N=>({...N,dateEnd:f}))},[s]),w=a.useCallback(f=>{s(N=>({...N,search:f}))},[s]),b=a.useMemo(()=>{const f=[];return c.length>0&&f.push({id:"accounts",icon:"Buildings",label:r("inspector.apiLogs.filters.accounts"),type:"checkbox",items:c,selectedValues:vt(t.accounts,c.map(N=>N.value),J()),onChange:u,searchable:!0,showActions:!0}),f.push({id:"methods",icon:"Code",label:r("inspector.apiLogs.filters.method"),type:"checkbox",items:d,selectedValues:t.methods,onChange:m,searchable:!0,showActions:!0}),f.push({id:"date",icon:"CalendarBlank",label:r("inspector.apiLogs.filters.date"),type:"date",dateValue:t.dateValue,dateInit:t.dateInit,dateEnd:t.dateEnd,onDateValueChange:p,onDateInitChange:h,onDateEndChange:x,dateMode:"range",showAllTime:!1,clearable:!1}),f},[r,t.dateValue,t.dateInit,t.dateEnd,t.methods,t.accounts,d,c,p,h,x,m,u]),y=a.useMemo(()=>{const f=[];return c.length>0&&f.push({id:"accounts",label:Nt(r,t.accounts.length,c.length),...J()&&{icon:"User"}}),t.methods.length>0&&f.push({id:"methods",label:t.methods.join(", ")}),f.push({id:"date",label:Ts[t.dateValue]?r(Ts[t.dateValue]):t.dateValue}),f},[t.dateValue,t.methods,t.accounts,r]),E=a.useCallback(f=>{if(f==="accounts")s(N=>({...N,accounts:[]}));else if(f==="methods")s(N=>({...N,methods:[]}));else if(f==="date"){const N=ht(We);s(C=>({...C,dateValue:We,dateInit:N.dateInit,dateEnd:N.dateEnd}))}},[s]),g=a.useCallback(()=>{s(f=>({...f,accounts:[],methods:[]}))},[s]);return e.jsxs("div",{"data-testid":"devx-api-logs-filter-bar",className:"flex flex-col gap-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("div",{className:"w-full max-w-sm",children:e.jsx(le,{"data-testid":"devx-api-logs-search",value:t.search,onSearch:w,placeholder:r("inspector.apiLogs.searchPlaceholder")})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(M,{variant:"outline",size:"sm",startIcon:"ArrowsClockwise",onClick:n,disabled:o,loading:o,children:r("inspector.apiLogs.refresh")}),e.jsx(xn,{exportTab:"api-logs",currentFilters:{accountCodes:t.accounts,methods:t.methods,search:t.search.trim()||void 0,dateInit:t.dateInit,dateEnd:t.dateEnd}})]})]}),e.jsx(De,{filters:b,translations:{addFilter:r("inspector.apiLogs.addFilter")},appliedFilters:y,onRemoveFilter:E,onClearAllFilters:g,maxVisibleTags:4})]})}function fn(t,s="en-US",n=!1){if(!t)return"-";try{return new Intl.DateTimeFormat(s,{month:"short",day:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",...n?{second:"2-digit"}:{},hour12:!0,timeZoneName:"short"}).format(new Date(t))}catch{return t}}function Ii(t){return t.replace(/^\//,"").replace(/^v1\//i,"V1/").replace(/\/[0-9a-f-]{8,}.*$/,s=>s.replace(/\/[0-9a-f-]{8,}/,""))}function _s(t){if(t==null)return{};if(typeof t!="string")return t??{};try{return JSON.parse(t||"{}")}catch{return{}}}function Di(t){const s={};for(const n of t)if(n?.name)for(const o of[n.code,n.account_code_live,n.account_code_testing])o&&(s[o]=n.name);return s}function Li(t,s,n){const o=t.account_code??"";return{id:`${t.trace_id??"log"}-${s}`,accountCode:o,accountName:o?n?.[o]??"":"",method:t.method??"",requestUri:t.request_uri??"",statusCode:t.status_code??0,traceId:t.trace_id??"",timestamp:t.created_at??"",requestBody:_s(t.request_body),responseBody:_s(t.response_body)}}
1function Ri({log:t,isSelected:s,onClick:n}){const{t:o,i18n:r}=A();return e.jsxs(q,{"data-testid":"devx-api-logs-row","data-state":s?"selected":void 0,onClick:n,className:"cursor-pointer",children:[e.jsx(U,{className:"whitespace-nowrap",children:t.timestamp?fn(t.timestamp,r.language):"-"}),e.jsx(U,{children:t.accountName||t.accountCode||"-"}),e.jsx(U,{children:e.jsx(ye,{code:t.statusCode})}),e.jsx(U,{children:t.method?e.jsx(ge,{method:t.method}):"-"}),e.jsx(U,{className:"max-w-[280px] truncate text-muted-foreground",children:t.requestUri||"-"}),e.jsx(U,{children:e.jsx(oe,{content:o("inspector.apiLogs.viewDetails","View details"),contentProps:{side:"left"},children:e.jsx("button",{type:"button","aria-label":o("inspector.apiLogs.a11y.viewDetails","View details for {{id}}",{id:t.id}),onClick:i=>{i.stopPropagation(),n()},className:"inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent bg-transparent text-muted-foreground transition-all hover:border-border hover:bg-background hover:text-foreground hover:shadow-xs",children:e.jsx(F,{name:"Eye",className:"size-4"})})})})]})}const Ss=[{key:"createdDate",width:"min-w-56"},{key:"account",width:"min-w-40"},{key:"status",width:"min-w-32"},{key:"method",width:"min-w-24"},{key:"url",width:"min-w-60"}],Pi=[1,2,3,4,5];function Oi({logs:t,isLoading:s,selectedId:n,onRowClick:o}){const{t:r}=A(),i=e.jsxs(q,{children:[Ss.map(l=>e.jsx($,{className:P("whitespace-nowrap",l.width),children:r(`inspector.apiLogs.table.${l.key}`)},l.key)),e.jsx($,{className:"w-[52px]"})]});return s?e.jsxs(ee,{"data-testid":"devx-api-logs-table-loading",children:[e.jsx(te,{children:i}),e.jsx(se,{children:Pi.map(l=>e.jsxs(q,{children:[Ss.map(c=>e.jsx(U,{children:e.jsx(K,{className:"h-4 w-16 rounded"})},c.key)),e.jsx(U,{})]},l))})]}):e.jsxs(ee,{"data-testid":"devx-api-logs-table",children:[e.jsx(te,{children:i}),e.jsx(se,{children:t.map(l=>e.jsx(Ri,{log:l,isSelected:l.id===n,onClick:()=>o(l)},l.id))})]})}function As({log:t,onClose:s}){const{t:n,i18n:o}=A(),r=Ii(t?.requestUri??""),i=Object.keys(t?.requestBody??{}).length>0,l=a.useMemo(()=>[{id:"response",label:e.jsx("span",{"data-testid":"devx-api-log-tab-response",children:n("inspector.apiLogs.detail.responseBody","Response body")}),content:e.jsx($e,{title:n("inspector.apiLogs.detail.responseBody","Response body"),data:t?.responseBody??{},testId:"devx-api-log-json-block"})},{id:"request",label:e.jsx("span",{"data-testid":"devx-api-log-tab-request",children:n("inspector.apiLogs.detail.requestBody","Request body")}),content:i?e.jsx($e,{title:n("inspector.apiLogs.detail.requestBody","Request body"),data:t?.requestBody??{},testId:"devx-api-log-json-block"}):e.jsx("div",{"data-testid":"devx-api-log-no-body",className:"rounded-lg border border-border p-6 text-sm text-muted-foreground",children:n("inspector.apiLogs.noBody","{{method}} requests don't have a body. This endpoint takes only path and query parameters.",{method:t?.method})})}],[n,t,i]);return e.jsx(Xe,{open:t!==null,onClose:s,title:n("inspector.apiLogs.detail.title","API log details"),testId:"devx-api-log-detail",children:t&&e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs("div",{className:"flex flex-col gap-6 rounded-lg border border-border p-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[t.method&&e.jsx(ge,{method:t.method}),e.jsx("span",{className:"truncate text-sm text-muted-foreground",children:t.requestUri||"-"})]}),e.jsx(W,{}),e.jsxs(He,{children:[e.jsx(Q,{label:n("inspector.apiLogs.detail.createdDate","Creation date"),children:fn(t.timestamp,o.language,!0)}),e.jsx(Q,{label:n("inspector.apiLogs.detail.httpStatus","HTTP status"),children:e.jsx(ye,{code:t.statusCode})})]}),e.jsxs(He,{children:[e.jsx(Q,{label:n("inspector.apiLogs.detail.method","Method"),children:t.method?e.jsx(ge,{method:t.method}):"-"}),e.jsx(Q,{label:n("inspector.apiLogs.detail.endpoint","Endpoint"),copyValue:r||void 0,children:r||"-"})]}),e.jsx(Q,{label:n("inspector.apiLogs.detail.xTraceId","X-Trace-Id"),copyValue:t.traceId||void 0,children:t.traceId||"-"})]}),e.jsx(Le,{tabs:l,defaultTab:0,navTabsClassName:"gap-2",contentClassName:"mt-4"})]})})}const Is=ht(We),ut={accounts:[],methods:[],search:"",dateValue:We,dateInit:Is.dateInit,dateEnd:Is.dateEnd};function Mi(t,s){const n=wt(t.accounts,s);return{start_date:t.dateInit?.toISOString(),end_date:t.dateEnd?.toISOString(),timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,accounts:n.length>0?n:void 0,methods:t.methods.length>0?t.methods:void 0,search:t.search.trim()||void 0}}function Ui(){const{t}=A(),n=Xn().state?.apiLogsSearch,[o,r]=a.useState(()=>n?{...ut,search:n}
1:ut),[i,l]=a.useState(0),[c,d]=a.useState(null);Re(()=>r(I=>({...I,accounts:ut.accounts}))),a.useEffect(()=>{n&&r(I=>I.search===n?I:{...I,search:n})},[n]);const u=At({roles:[],environmentCodes:!0}),m=a.useMemo(()=>Mi(o,u),[o,u]);a.useEffect(()=>{l(0),d(null)},[m]);const p=Gs({...m,page:i,size:Si}),{accounts:h}=be({roles:[]}),x=a.useMemo(()=>Di(h??[]),[h]),w=a.useMemo(()=>(p.data?.data??[]).map((I,S)=>Li(I,S,x)),[p.data,x]),b=a.useMemo(()=>w.find(I=>I.id===c)??null,[w,c]),y=p.data?.total_pages??1,E=on(o.dateInit,o.dateEnd)||_e(p.error),g=a.useCallback(()=>{p.refetch()},[p]),f=a.useCallback(I=>{d(I.id)},[]),N=a.useCallback(()=>{d(null)},[]),C=a.useCallback(I=>{l(I-1),d(null)},[]),T=()=>{if(E)return e.jsx("div",{"data-testid":"devx-api-logs-range-too-large",className:"flex flex-col items-center justify-center px-6 py-12",children:e.jsx("span",{className:"text-center text-sm text-muted-foreground",children:t("inspector.common.dateRangeTooLarge",{maxDays:Dt})})});if(p.isError)return e.jsxs("div",{"data-testid":"devx-api-logs-error",className:"flex flex-col items-center justify-center gap-3 px-6 py-12",children:[e.jsx("span",{className:"text-center text-sm text-muted-foreground",children:t("inspector.apiLogs.errorLoading")}),e.jsx("div",{children:e.jsx(M,{variant:"outline",size:"sm",startIcon:"ArrowsClockwise",onClick:g,children:t("inspector.apiLogs.retry")})})]});if(!p.isLoading&&w.length===0){const I=o.search.trim().length>0||o.accounts.length>0||o.methods.length>0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{"data-testid":"devx-api-logs-empty",className:"flex flex-1 flex-col",children:e.jsx(he,{icon:"Receipt",title:I?t("inspector.apiLogs.noResults","No logs match your search."):t("inspector.apiLogs.emptyTitle","No API requests yet"),description:I?void 0:t("inspector.apiLogs.emptyDescription","Requests to your Yuno integration will appear here.")})}),e.jsx(As,{log:b,onClose:N})]})}return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-6",children:[e.jsx(Oi,{logs:w,isLoading:p.isLoading,selectedId:c,onRowClick:f}),y>1&&e.jsx("div",{className:"flex justify-center",children:e.jsx(_t,{currentPage:i+1,totalPages:y,maxVisiblePages:7,onPageClick:C,onClickPrev:()=>C(Math.max(i,1)),onClickNext:()=>C(Math.min(i+2,y))})})]}),e.jsx(As,{log:b,onClose:N})]})};return e.jsxs("div",{className:"flex flex-col gap-6","data-testid":"api-logs-tab",children:[e.jsx(Ai,{filters:o,onFiltersChange:r,onRefresh:g,isRefreshing:p.isFetching&&!p.isLoading}),T()]})}const zi={flowType:"direct_flow",gateway:"yuno_test_gateway",paymentStatus:"CREATED"},Fi=["SUCCEEDED","CREATED","PENDING","DECLINED","REJECTED","ERROR"],Ki=JSON.stringify({merchant_customer_id:"{{merchant-customer-id}}",first_name:"John",last_name:"Smith",email:"{{playground-email}}",phone:{number:"5551234567",country_code:"1"},document:{document_type:"PASSPORT",document_number:"AB1234567"},billing_address:{address_line_1:"123 Main Street",city:"San Francisco",state:"CA",zip_code:"94102",country:"US"}},null,2),Vi=JSON.stringify({account_id:"{{account-id}}",country:"US",amount:{currency:"USD",value:1e3},payment_method:{type:"CARD",card:{number:"4111111111111111",expiration_month:12,expiration_year:28,security_code:"123",holder_name:"John Smith",capture:!0}}},null,2),xt="https://docs.y.uno/reference/customers/create-customer",Fe="https://docs.y.uno/reference/payments/create-payment",Bi=[{name:"merchant_customer_id",type:"String",required:!0},{name:"first_name",type:"String",required:!0},{name:"last_name",type:"String",required:!0},{name:"email",type:"String",required:!0},{name:"phone",type:"Object ...",required:!1,docRef:xt,objectFields:[{name:"number",type:"String",required:!0,description:"Phone number without country code (MIN 1, MAX 32)"},{name:"country_code",type:"String",required:!0,description:"Country calling code (MIN 1, MAX 3)"}]},{name:"billing_address",type:"Object ...",required:!1,docRef:xt,objectFields:[{name:"address_line_1",type:"String",required:!0,description:"Primary address line (MIN 3, MAX 255)"},{name:"address_line_2",type:"String",required:!1,description:"Secondary address line (MIN 3, MAX 255)"},{name:"city",type:"String",required:!0,description:"City (MIN 3, MAX 255)"},{name:"state",type:"String",required:!1,description:"State (MIN 3, MAX 255)"},{name:"country",type:"String",required:!0,description:"ISO 3166-1 country code (2 chars)"},{name:"zip_code",type:"String",required:!1,description:"Zip code (MIN 5, MAX 10)"},{name:"neighborhood",type:"String",required:!1,description:"Neighborhood (MIN 1, MAX 255)"},{name:"building_number_1",type:"String",required:!1,description:"Primary building number"},{name:"building_number_2",type:"String",required:!1,description:"Secondary building number"}]}],Hi=[{name:"account_id",type:"String",required:!0},{name:"country",type:"String",required:!0},{name:"workflow",type:"String",required:!0},{name:"amount",type:"Object ...",required:!0,docRef:Fe,objectFields:[{name:"currency",type:"String",required:!0,description:"ISO 4217 currency code (3 chars)"},{name:"value",type:"Number",required:!0,description:"Payment amount (multiple of 0.0001)"},{name:"currency_conversion",type:"Object",required:!1,description:"Optional conversion details"}]},{name:"payment_method",type:"Object ...",required:!0,docRef:Fe,objectFields:[{name:"type",type:"String",required:!0,description:"Payment method type (e.g., CARD)"},{name:"card",type:"Object",required:!1,description:"Card details when type is CARD"},{name:"token",type:"String",required:!1,description:"Tokenized payment method"},{name:"vaulted_token",type:"String",required:!1,description:"Previously stored token"}]},{name:"metadata",type:"Object ...",required:!1,docRef:Fe,objectFields:[{name:"key",type:"String",required:!1,description:"Custom key-value pairs for merchant use"}]}],gn=[{id:"customer",stepNumber:1,titleKey:"inspector.playground.steps.customerJson",endpointKey:"inspector.playground.steps.customerEndpoint",defaultBody:Ki,schema:Bi,docRef:xt},{id:"payment",stepNumber:2,titleKey:"inspector.playground.steps.paymentJson",endpointKey:"inspector.playground.steps.paymentEndpoint",defaultBody:Vi,schema:Hi,docRef:Fe}];function $i({config:t,onChange:s,onRun:n,status:o,isTesting:r,hasAccount:i=!0,accountName:l}){const{t:c}=A(),d=o==="running",u=o==="completed",m=d||!r||!i,p=a.useCallback(y=>s({...t,flowType:y}),[t,s]),h=a.useCallback(y=>s({...t,gateway:y}),[t,s]),x=a.useCallback(y=>s({...t,paymentStatus:y}),[t,s]),w=Fi.map(y=>({value:y,label:c(`inspector.playground.status.${y.toLowerCase()}`)})),b=c(u?"inspector.playground.header.reRunTest":"inspector.playground.header.runTest");return e.jsxs("div",{className:"flex items-center gap-4",children:[l&&e.jsxs(e.Fragment,{children:[e.jsxs(Y,{variant:"secondary",className:"h-8 shrink-0 gap-2 px-3 py-2 shadow-xs","data-testid":"playground-account-tag","aria-label":c("inspector.playground.header.appliedAccount","Applied account: {{name}}",{name:l}),children:[e.jsx(F,{name:"User",className:"size-4"}),e.jsx("span",{className:"max-w-[12rem] truncate text-xs font-medium leading-none",children:l})]}),e.jsx("div",{className:"h-5 w-px shrink-0 bg-border"})]}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(ze,{value:t.flowType,onCh
1ange:p,options:[{value:"direct_flow",label:c("inspector.playground.header.directFlow")}]})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(ze,{value:t.gateway,onChange:h,options:[{value:"yuno_test_gateway",label:c("inspector.playground.header.yunoTestGateway")}]})}),e.jsx("div",{className:"h-5 w-px shrink-0 bg-border"}),e.jsx("div",{className:"w-[200px] shrink-0",children:e.jsx(ze,{value:t.paymentStatus,onChange:x,options:w})}),e.jsx("div",{className:"h-5 w-px shrink-0 bg-border"}),e.jsx("div",{className:"shrink-0",children:e.jsx(oe,{content:c("inspector.playground.header.testingModeOnly"),show:!r,providerProps:{delayDuration:150},children:e.jsx(M,{size:"sm",disabled:m,loading:d,onClick:n,children:d?c("inspector.playground.header.running","Running"):b})})})]})}function bn({variant:t,icon:s,title:n,children:o,action:r,className:i,"data-testid":l}){const c=t==="destructive";return e.jsxs("div",{role:"alert","data-testid":l,className:P("relative flex w-full items-center gap-4 rounded-lg border bg-card px-4 py-3 text-foreground",c&&"text-destructive",i),children:[e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx(F,{name:s,size:"sm",className:P("absolute left-0 top-0.5",c?"text-destructive":"text-primary")}),e.jsx("p",{className:"mb-1 pl-7 text-sm font-medium",children:n}),e.jsx("div",{className:P("pl-7 text-sm",c?"text-destructive":"text-muted-foreground"),children:o})]}),r&&e.jsx("div",{className:"shrink-0",children:r})]})}function Ut(){return bt()}const Ds="YUNO_TEST_PAYMENT_GW",Ls="CARD";function qi(){const t=Ut(),s=Jn({accountCode:t,paymentMethod:Ls}),n=a.useMemo(()=>(s.data??[]).some(d=>d.provider_id===Ds&&d.active&&d.connection_state!=="PAUSED"&&d.connection_state!=="ARCHIVED"),[s.data]),o=Ko(t,Ls),r=a.useMemo(()=>(o.data?.versions??[]).find(d=>d.status==="PUBLISHED")?.code??"",[o.data]),i=Vo({accountCode:t,workflowVersionId:r}),l=a.useMemo(()=>(i.data?.condition_sets??[]).some(d=>(d.routes??[]).some(u=>u.data?.provider_id===Ds)),[i.data]),c=s.isFetching||o.isFetching||i.isFetching;return{hasConnection:n,hasRoute:l,isLoading:c}}const Rs="Yuno test payment gateway",Ps="\0";function Wi({onRequestClose:t}){const{t:s}=A(),n=gt(),{isTesting:o}=Ie(),{hasConnection:r,hasRoute:i,isLoading:l}=qi();if(!o||l||r&&i)return null;const c=r&&!i,d=()=>{const m=c?"/routing":`/connections?search=${encodeURIComponent(Rs)}`;n(m),t?.()},u=s("inspector.playground.setupBanner.message","Make sure you have configured the connection named {{connection}} and your Routing settings before running this test.",{connection:Ps}).split(Ps);return e.jsx("div",{className:"pt-6",children:e.jsxs(bn,{variant:"info",icon:"Info","data-testid":"playground-setup-banner",title:s("inspector.playground.setupBanner.title","Finish setting up the test gateway"),action:e.jsx(M,{variant:"outline",size:"sm",onClick:d,"data-testid":"playground-setup-banner-action",children:s(c?"inspector.playground.setupBanner.goToRouting":"inspector.playground.setupBanner.goToConnections")}),children:[u[0],e.jsx("span",{className:"text-foreground",children:Rs}),u[1]]})})}function Yi(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Gi(t){return Yi(t).replace(/("(?:\\.|[^"\\])*"(?:\s*:)?|\b(?:true|false)\b|\bnull\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|[{}\[\],])/g,n=>{let o="number";return/^"/.test(n)?o=/:\s*$/.test(n)?"property":"string":/true|false/.test(n)?o="boolean":/null/.test(n)?o="null":/[{}\[\],]/.test(n)&&(o="punctuation"),`<span class="token ${o}">${n}</span>`})}const Os={fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace',fontSize:13,lineHeight:"24px",tabSize:2},Ms=340;function Xi({value:t,onChange:s,onValidationChange:n,copyLabel:o}){const{t:r}=A(),i=Je(),[l,c]=a.useState(!1),[d,u]=a.useState(!1),m=a.useRef(null),p=a.useRef(null),h=a.useRef(null);a.useEffect(()=>()=>{m.current&&clearTimeout(m.current)},[]);const x=a.useMemo(()=>t.split(` 2`).length,[t]),w=a.useMemo(()=>Gi(t),[t]),b=a.useCallback(g=>{const f=g.target.value;s(f);try{JSON.parse(f),c(!1),n(!1)}catch{c(!0),n(!0)}},[s,n]),y=a.useCallback(()=>{p.current&&h.current&&(h.current.scrollTop=p.current.scrollTop,h.current.scrollLeft=p.current.scrollLeft)},[]),E=a.useCallback(async()=>{await i(o,t),u(!0),m.current=setTimeout(()=>u(!1),2e3)},[i,o,t]);return e.jsxs("div",{className:P("relative min-w-0 flex-1 overflow-hidden rounded-md border bg-background",l?"border-destructive":"border-input"),style:{minHeight:Ms},children:[e.jsx("div",{className:"absolute right-3 top-3 z-10",children:e.jsx(M,{size:"icon",variant:"ghost",className:"size-8",onClick:E,"aria-label":d?r("inspector.playground.jsonEditor.copied","Copied"):r("inspector.a11y.copyLabel","Copy {{label}}",{label:o}),children:e.jsx(F,{name:d?"Check":"CopySimple",size:"sm"})})}),e.jsxs("div",{className:"flex h-full",children:[e.jsx("div",{className:"shrink-0 select-none border-r border-input bg-muted/40 px-3 py-4 text-center text-muted-foreground","aria-hidden":"true",children:Array.from({length:x},(g,f)=>e.jsx("div",{className:"text-xs",style:{lineHeight:"24px",height:24},children:f+1},f))}),e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsx("pre",{ref:h,className:"json-highlight pointer-events-none m-0 overflow-hidden p-4 text-foreground",style:{...Os,whiteSpace:"pre-wrap",wordBreak:"break-all",minHeight:Ms-32},"aria-hidden":"true",children:e.jsx("code",{dangerouslySetInnerHTML:{__html:w+` 3`}})}),e.jsx("textarea",{ref:p,value:t,onChange:b,onScroll:y,spellCheck:!1,autoCapitalize:"off",autoComplete:"off",className:P("absolute inset-0 m-0 h-full w-full resize-none p-4","bg-transparent text-transparent caret-foreground outline-none"),style:{...Os,whiteSpace:"pre-wrap",wordBreak:"break-all",WebkitTextFillColor:"transparent"}})]})]}),e.jsx("style",{children:` 4 .json-highlight .token.property { color: var(--primary); } 5 .json-highlight .token.string { color: var(--foreground); } 6 .json-highlight .token.number { color: var(--foreground); } 7 .json-highlight .token.boolean { color: color-mix(in oklab, var(--primary) 60%, transparent); } 8 .json-highlight .token.null { color: var(--muted-foreground); } 9 .json-highlight .token.punctuation { color: var(--muted-foreground); } 10 .json-highlight .token.operator { color: var(--muted-foreground); } 11 `})]})}const Us="\0",zs=80;function Fs({field:t}){const{t:s}
11=A(),[n,o]=a.useState(!1),r=Array.isArray(t.objectFields)&&t.objectFields.length>0,i=a.useRef(),l=a.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);a.useEffect(()=>l,[l]);const c=a.useCallback(()=>{l(),i.current=setTimeout(()=>o(!0),zs)},[l]),d=a.useCallback(()=>{l(),i.current=setTimeout(()=>o(!1),zs)},[l]),u=a.useCallback(()=>{l(),o(!0)},[l]),m=a.useCallback(()=>{l(),o(!1)},[l]),p=a.useCallback(x=>x.preventDefault(),[]),h=s("inspector.playground.schema.objectFields","Fields of {{name}}",{name:Us}).split(Us);return e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("p",{className:"flex-1 truncate text-sm text-foreground",children:t.name}),r?e.jsxs(Zn,{open:n,onOpenChange:o,children:[e.jsx(Qn,{className:"shrink-0 cursor-help rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring",onMouseEnter:c,onMouseLeave:d,onFocus:u,onBlur:m,"aria-label":s("inspector.playground.schema.objectFields","Fields of {{name}}",{name:t.name}),children:e.jsx(Y,{variant:"outline",children:t.type})}),e.jsxs(eo,{align:"end",side:"left",className:"w-80 rounded-md border-border bg-popover p-4 shadow-md",onMouseEnter:c,onMouseLeave:d,onOpenAutoFocus:p,onCloseAutoFocus:p,children:[e.jsxs("p",{className:"mb-3 text-sm font-semibold text-foreground",children:[h[0],e.jsx("span",{className:"font-mono",children:t.name}),h[1]]}),e.jsx(W,{className:"mb-4"}),e.jsx("ul",{className:"flex flex-col gap-4",children:t.objectFields.map(x=>e.jsxs("li",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate font-mono text-sm text-foreground",children:x.name}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:x.type}),x.required&&e.jsx(Y,{variant:"outline",className:"border-destructive/30 bg-destructive/5 px-1.5 py-0 text-[10px] font-medium uppercase text-destructive",children:s("inspector.playground.schema.required")})]})]}),x.description&&e.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:x.description})]},x.name))}),t.docRef&&e.jsxs(e.Fragment,{children:[e.jsx(W,{className:"my-4"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s("inspector.playground.schema.reference"),":"," ",e.jsx("a",{href:t.docRef,target:"_blank",rel:"noreferrer noopener",className:"text-primary-text hover:underline",children:s("inspector.playground.schema.docsLinkLabel","docs.y.uno")})]})]})]})]}):e.jsx(Y,{variant:"outline",children:t.type})]})}function Ji({schema:t}){const{t:s}=A(),n=t.filter(r=>r.required),o=t.filter(r=>!r.required);return e.jsx("div",{className:"w-[280px] shrink-0 self-start overflow-hidden rounded-md border border-input bg-background",children:e.jsxs("div",{className:"flex flex-col gap-5 p-5",children:[n.length>0&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:s("inspector.playground.schema.required")}),e.jsx("div",{className:"flex flex-col gap-2.5",children:n.map(r=>e.jsx(Fs,{field:r},r.name))})]}),o.length>0&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:s("inspector.playground.schema.optional")}),e.jsx("div",{className:"flex flex-col gap-2.5",children:o.map(r=>e.jsx(Fs,{field:r},r.name))})]})]})})}function Zi({step:t,value:s,onChange:n,onValidationChange:o}){const{t:r}=A(),i=r(t.titleKey);return e.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[e.jsxs("div",{className:"mb-6 flex items-start gap-4",children:[e.jsx("div",{className:"flex size-6 shrink-0 items-center justify-center rounded-full bg-primary text-xs font-semibold text-primary-foreground",children:t.stepNumber}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[e.jsx("p",{className:"text-base font-semibold text-foreground",children:i}),e.jsx("p",{className:"truncate font-mono text-xs text-muted-foreground",children:r(t.endpointKey)})]}),t.docRef&&e.jsx(M,{variant:"outline",size:"sm",asChild:!0,className:"shrink-0",children:e.jsxs("a",{href:t.docRef,target:"_blank",rel:"noreferrer noopener","aria-label":r("inspector.playground.a11y.viewDocs","View docs for {{step}}",{step:i}),title:t.docRef,children:[r("inspector.playground.viewDocs"),e.jsx(F,{name:"ArrowSquareOut",size:"sm"})]})})]}),e.jsxs("div",{className:"flex gap-6",children:[e.jsx(Xi,{value:s,onChange:n,onValidationChange:o,copyLabel:i}),e.jsx(Ji,{schema:t.schema})]})]})}const Ks={SUCCEEDED:"success",VERIFIED:"success",FRAUD_VERIFIED:"success",PENDING:"warning",CREATED:"info",READY_TO_PAY:"info",ERROR:"error",DECLINED:"error",CANCELED:"error",REJECTED:"error",EXPIRED:"error",CHARGEBACK:"error",REFUNDED:"secondary",IN_DISPUTE:"secondary"},yn={success:{border:"border-success/30",cardTint:"border-success/30 bg-success/5",icon:"text-success"},warning:{border:"border-yellow-600/30",cardTint:"border-yellow-600/30 bg-yellow-600/5",icon:"text-yellow-600"},error:{border:"border-destructive/30",cardTint:"border-destructive/30 bg-destructive/5",icon:"text-destructive"},info:{border:"border-blue-600/30",cardTint:"border-blue-600/30 bg-blue-600/5",icon:"text-blue-600"}
11,secondary:{border:"border-muted-foreground/30",cardTint:"border-muted-foreground/30 bg-muted/40",icon:"text-muted-foreground"}},Qi={success:"CheckCircle",warning:"Clock",error:"WarningCircle",info:"FlagBanner",secondary:"ArrowCircleLeft"};function jn(t){const s=typeof t.response?.status=="string"?t.response.status:null;if(s&&Ks[s])return Ks[s];if(t.httpStatus){const n=parseInt(t.httpStatus,10);if(!Number.isNaN(n)){if(n>=200&&n<300)return"success";if(n>=400)return"error"}}return t.status==="success"?"success":t.status==="error"?"error":"info"}function ec(t){return Qi[t]}function tc({step:t,index:s=0}){const{t:n}=A(),o=t.status==="running",r=t.status==="pending",i=t.status==="success"||t.status==="error",l=jn(t),c=yn[l],d=ec(l),u=t.httpStatus?Number(t.httpStatus):NaN,m=()=>o?e.jsx(F,{name:"CircleNotch",className:"size-4 animate-spin text-muted-foreground"}):r?e.jsx("div",{className:"size-4 rounded-full border-2 border-border"}):e.jsx(F,{name:d,weight:"fill",size:"sm",className:c.icon});return e.jsxs("div",{className:P("devx-fade-in flex items-center gap-4 roun
11ded-md border px-4 py-3 transition-colors",i?c.cardTint:"border-input bg-background",r&&"opacity-60"),style:{animationDelay:`${s*90}ms`},children:[e.jsx("div",{className:"shrink-0",children:m()}),e.jsx("p",{className:P("flex-1 truncate text-sm font-medium",r?"text-muted-foreground":"text-foreground"),children:n(t.name)}),t.durationMs!==void 0&&e.jsxs("span",{className:"shrink-0 text-xs text-muted-foreground",children:[t.durationMs,"ms"]}),t.httpStatus&&i&&(Number.isNaN(u)?e.jsx("span",{className:"shrink-0 text-xs font-semibold text-muted-foreground",children:t.httpStatus}):e.jsx(ye,{code:u,className:"shrink-0"}))]})}function sc(t){try{const o=JSON.parse(t);return typeof o=="object"&&o!==null?o:null}catch{}const s=t.indexOf("{"),n=t.lastIndexOf("}");if(s===-1||n===-1||n<=s)return null;try{const o=JSON.parse(t.slice(s,n+1));return typeof o=="object"&&o!==null?o:null}catch{return null}}function nc({step:t}){const{t:s}=A(),n=Je(),[o,r]=a.useState(!0),[i,l]=a.useState(!1),c=a.useRef(null);a.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const d=jn(t),u=yn[d],m=!!(t.response||t.errorMessage),p=s(t.name),h=t.httpStatus?Number(t.httpStatus):NaN,x=a.useMemo(()=>t.errorMessage?sc(t.errorMessage):null,[t.errorMessage]),w=t.response??x,b=w?JSON.stringify(w,null,2):t.errorMessage??"",y=a.useCallback(async()=>{b&&(await n(p,b),l(!0),c.current=setTimeout(()=>l(!1),2e3))},[n,p,b]),E=a.useCallback(()=>r(g=>!g),[]);return m?e.jsxs("div",{className:P("rounded-md border p-5",u.border),children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:p}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(M,{variant:"ghost",size:"icon",className:"size-8",onClick:y,"aria-label":i?s("inspector.playground.jsonEditor.copied","Copied"):s("inspector.playground.a11y.copyResponse","Copy {{step}} response",{step:p}),children:e.jsx(F,{name:i?"Check":"CopySimple",size:"sm"})}),t.httpStatus&&!Number.isNaN(h)&&e.jsx(ye,{code:h}),e.jsx(M,{variant:"ghost",size:"icon",className:"size-8",onClick:E,"aria-label":o?s("inspector.playground.a11y.collapseResponse","Collapse {{step}} response",{step:p}):s("inspector.playground.a11y.expandResponse","Expand {{step}} response",{step:p}),children:e.jsx(F,{name:o?"CaretUp":"CaretDown",size:"sm"})})]})]}),o&&b&&e.jsx("pre",{className:"mt-4 overflow-auto rounded-md bg-muted/40 p-4 font-mono text-xs text-foreground",style:{lineHeight:"20px"},children:b})]}):e.jsx(e.Fragment,{})}function oc(t){if(t&&typeof t=="object"){const s=t.response?.data;if(s&&typeof s.message=="string"&&s.message)return s.message}if(t instanceof Error&&t.message)return t.message}function ac({steps:t,status:s,onReset:n,error:o,className:r}){const{t:i}=A(),l=s==="idle",c=s==="completed",d=s==="error",u=t.filter(m=>m.response||m.errorMessage);return e.jsxs("div",{"data-testid":"devx-playground-execution-panel",className:P("flex flex-col overflow-hidden rounded-lg border border-border bg-card",r),children:[e.jsx("div",{className:"flex items-center justify-between border-b border-border px-6 py-4",children:e.jsx("p",{className:"text-base font-semibold text-foreground",children:i("inspector.playground.execution.title")})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-6",children:l?e.jsxs("div",{className:"flex flex-col items-center gap-4 roun
11ded-md bg-muted/40 px-6 py-12",children:[e.jsx("div",{className:"flex size-12 items-center justify-center rounded-md border border-input bg-background shadow-xs",children:e.jsx(F,{name:"TestTube",className:"size-6 text-muted-foreground"})}),e.jsxs("div",{className:"flex max-w-[328px] flex-col items-center gap-2",children:[e.jsx("p",{className:"text-center text-base font-semibold text-foreground",children:i("inspector.playground.execution.emptyTitle")}),e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:i("inspector.playground.execution.emptyDescription")})]})]}):e.jsxs("div",{className:"flex flex-col gap-6",children:[o&&d&&e.jsx(bn,{variant:"destructive",icon:"WarningCircle",title:i("inspector.playground.execution.errorTitle","Flow failed"),children:oc(o)??i("inspector.playground.execution.networkError")}),e.jsx("div",{className:"flex flex-col gap-3",children:t.map((m,p)=>e.jsx(tc,{step:m,index:p},m.id))}),(c||d)&&u.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(W,{}),e.jsxs("div",{className:"devx-fade-in flex items-center justify-between",style:{animationDelay:"120ms"},children:[e.jsx("p",{className:"text-base font-semibold text-foreground",children:i("inspector.playground.execution.apiResponse")}),e.jsx(M,{variant:"outline",size:"sm",startIcon:"ArrowCounterClockwise",onClick:n,children:i("inspector.playground.execution.reset")})]}),e.jsx("div",{className:"flex flex-col gap-4",children:u.map((m,p)=>e.jsx("div",{className:"devx-fade-in",style:{animationDelay:`${200+p*120}ms`},children:e.jsx(nc,{step:m})},m.id))})]})]})})]})}const rc="{{account-id}}",ic="{{merchant-customer-id}}";function cc(t){return typeof t!="string"||t===rc||!t?Ut():t}function lc(){const t=Math.random().toString(36).slice(2,8);return`cust_test_${Date.now()}_${t}`}const dc=new Set(["cust_test_001"]);function uc(t){return typeof t!="string"||!t||t===ic||dc.has(t)?lc():t}const mc="{{playground-email}}",pc=new Set(["[email protected]"]);function hc(){const t=Math.random().toString(36).slice(2,8);return`playground+${Date.now()}_${t}@example.com`}function xc(t){return typeof t!="string"||!t||t===mc||pc.has(t)?hc():t}const Ke=[{id:"create-customer",name:"inspector.playground.execution.createCustomer"},{id:"create-payment",name:"inspector.playground.execution.createPayment"}];function fc(){return Ke.map(t=>({id:t.id,name:t.name,status:"pending"}))}const vn={status:"idle",steps:[],currentStepIndex:-1};function gc(t,s){switch(s.type){case"START":return{status:"running",steps:fc().map((o,r)=>r===0?{...o,status:"running"}:o),currentStepIndex:0,error:void 0};case"SET_STEPS":return{...t,steps:s.steps};case"STEP_RUNNING":return{...t,currentStepIndex:s.index,steps:t.steps.map((n,o)=>o===s.index?{...n,status:"running"}:n)};case"STEP_COMPLETE":return{...t,steps:t.steps.map((n,o)=>o===s.index?{...n,status:s.stepStatus,httpStatus:s.httpStatus,response:s.response,errorMessage:s.errorMessage,durationMs:s.durationMs}:n)};case"COMPLETED":return{...t,status:"completed"};case"ERROR":return{...t,status:"error",error:s.error,steps:[]};case"RESET":return vn;default:return t}}function bc(t,s){const[n,o]=a.useReducer(gc,vn),r=a.useRef([]),i=a.useRef(t),l=a.useRef(s),c=Go(),d=a.useRef(c.mutateAsync),u=a.useRef(0);i.current=t,l.current=s,d.current=c.mutateAsync,a.useEffect(()=>()=>{r.current.forEach(clearTimeout)},[]);const m=a.useCallback(()=>{r.current.forEach(clearTimeout),r.current=[]},[]),p=a.useCallback(async()=>{m(),o({type:"START"});const x=++u.current;try{const w=i.current,b=l.current,y=JSON.parse(b.customer||"{}"),E=JSON.parse(b.payment||"{}"),g={...y,merchant_customer_id:uc(y.merchant_customer_id),email:xc(y.email)},f={flow_type:"DIRECT",config:{capture:!0},customer:g,payment_method:E.payment_method||{type:"CARD"},country:E.country||"US",amount:E.amount||{currency:"USD",value:1e3},account_id:cc(E.account_id),payment_description:w.paymentStatus},N=await d.current({payload:f});if(x!==u.current)return;const C=N.steps??[];if(C.length>0){const T=Ke[Ke.length-1],I=C.map((S,z)=>{const k=Ke[z]??T;return{id:k.id,name:k.name,status:"pending"}});o({type:"SET_STEPS",steps:I})}if(C.length===0){o({type:"COMPLETED"});return}C.forEach((T,I)=>{const S=setTimeout(()=>{o({type:"STEP_RUNNING",index:I})},I*300),z=setTimeout(()=>{o({type:"STEP_COMPLETE",index:I,httpStatus:T.http_status?`${T.http_status}`:void 0,stepStatus:T.status==="SUCCESS"?"success":"error",response:T.response??void 0,errorMessage:T.error_message??void 0,durationMs:T.duration_ms}),I===C.length-1&&o({type:"COMPLETED"})},I*300+150);r.current.push(S,z)})}catch(w){if(x!==u.current)return;o({type:"ERROR",error:w})}},[m]),h=a.useCallback(()=>{m(),u.current++,o({type:"RESET"})},[m]);return{status:n.status,steps:n.steps,error:n.error,run:p,reset:h}}function yc(){const t={};for(const s of gn)t[s.id]=s.defaultBody;return t}function jc({onRequestClose:t}){const{isTesting:s}=Ie(),n=!!Ut(),o=Vs(),r=J()?o?.name:void 0,[i,l]=a.useState(zi),[c,d]=a.use
11State(yc),[u,m]=a.useState({}),{status:p,steps:h,error:x,run:w,reset:b}=bc(i,c),y=Object.values(u).some(Boolean),E=a.useCallback((N,C)=>{d(T=>({...T,[N]:C}))},[]),g=a.useCallback((N,C)=>{m(T=>({...T,[N]:C}))},[]),f=a.useCallback(()=>{y||w()},[y,w]);return e.jsxs("div",{className:"flex flex-col",children:[e.jsx($i,{config:i,onChange:l,onRun:f,status:p,isTesting:s,hasAccount:n,accountName:r}),e.jsx(Wi,{onRequestClose:t}),e.jsxs("div",{className:"grid grid-cols-[5fr_3fr] gap-6 py-6",children:[e.jsx("div",{className:"flex min-w-0 flex-col gap-6","data-testid":"devx-playground-guide",children:gn.map(N=>e.jsx(Zi,{step:N,value:c[N.id]||"",onChange:C=>E(N.id,C),onValidationChange:C=>g(N.id,C)},N.id))}),e.jsx("div",{className:"sticky top-6 flex max-h-[calc(100dvh-112px)] min-w-0 flex-col self-start",children:e.jsx(ac,{steps:h,status:p,onReset:b,error:x,className:"h-full"})})]})]})}const ft="health";function vc(){return a.useMemo(()=>[{id:"health",labelKey:"devx.health",render:()=>e.jsx(Da,{})},{id:"authentication",labelKey:"devx.authentication",render:()=>e.jsx(mr,{})},{id:"webhooks",labelKey:"devx.webhooks",render:()=>e.jsx(Ti,{})},{id:"api-logs",labelKey:"devx.apiLogs",render:()=>e.jsx(Ui,{})},{id:"playground",labelKey:"devx.playground",render:()=>e.jsx(jc,{})}],[])}function wc(){const{t}=A(),s=gt(),{tabId:n}=to(),o=vc(),r=Math.max(0,o.findIndex(c=>c.id===(n??ft)));so([{label:t(o[r].labelKey)}]);const i=o.map(c=>({id:c.id,label:t(c.labelKey),content:c.render()})),l=c=>{no("tab.selected",{section:oo(),tab:o[c].id}),s(`/developers/${o[c].id}`)};return e.jsxs("div",{className:"flex flex-col gap-6","data-testid":"developers-page",children:[e.jsx("h1",{className:"text-3xl font-semibold leading-[1.1] tracking-tight text-foreground",children:t("sections.developers")}),e.jsx(Le,{tabs:i,navTabsClassName:"gap-2",contentClassName:"mt-10",defaultTab:r,keepMounted:!0,onChange:l})]})}function pl(){return ao([{path:"/",element:e.jsx(Wt,{to:ft,replace:!0})},{path:"/:tabId",element:e.jsx(Xo,{children:e.jsx(ro,{timezone:"user-stored",children:e.jsx(wc,{})})})},{path:"*",element:e.jsx(Wt,{to:`/developers/${ft}`,replace:!0})}])}export{ft as DEVELOPERS_DEFAULT_TAB,wc as DevelopersPage,pl as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.