import{j as a,r as b}from"./vendor-react-Bf71BWbF.js";import{aM as B,u as L,a2 as O,a as R,aB as P,dF as T,B as W,dG as q,bw as k,dH as C,aG as H,a0 as N,a1 as G,aq as I,a5 as J,ay as _,bq as V,dI as K,cQ as Q,dJ as U,aE as F,aC as E,aD as z,b2 as X,T as Y,cw as Z,aF as ee,E as te}from"./index-CXHBmSa5.js";import{F as se}from"./FactStrip-BgQ_tYB6.js";import{u as ae,h as re,C as oe,t as ne}from"./layout-BRLew_nj.js";import{D as le}from"./Table-D0NFHHNQ.js";import{A as ie}from"./ActionGroup-90AzAQje.js";import{d as ce,e as ge}from"./files-BxEOxSF8.js";import{r as ue}from"./recorder-DlDpPhd4.js";import"./useGridSelectionCheckbox-BV96yL-N.js";import"./Virtualizer--Vfl8O3n.js";import"./ListLayout-CPapuywx.js";function de({label:e,rows:s,columns:r}){const n=B(),{ref:t,tip:m,show:l,hide:p}=ae();return a.jsxs("div",{className:"rp-heatmap rp-chart-hover",ref:t,onPointerLeave:p,role:"group","aria-label":e,"aria-describedby":n,style:{"--cols":r.length},children:[s.map(o=>{const c=Math.max(...o.counts);return a.jsxs("div",{className:"row",children:[a.jsx("div",{className:"head",children:o.label}),a.jsx("div",{className:"cells",children:o.counts.map((v,x)=>a.jsx("span",{className:"cell t"+re(v,c),style:{"--tone":o.color},onPointerMove:u=>l(u,[o.titles[x]]),role:"img","aria-label":o.titles[x]},x))})]},o.id)}),r.length>0&&a.jsxs("div",{className:"row times","aria-hidden":"true",children:[a.jsx("div",{className:"head"}),a.jsxs("div",{className:"ends",children:[a.jsx("span",{children:r[0]}),r.length>2&&a.jsx("span",{children:r[Math.floor(r.length/2)]}),r.length>1&&a.jsx("span",{children:r[r.length-1]})]})]}),a.jsx(oe,{tip:m})]})}const S=new WeakMap;function $(e){let s=S.get(e);return s===void 0&&S.set(e,s=Date.parse(e.ts)),s}const M=["error","warn","info","debug","trace"];function pe(e,s,r,n=24){const t=r?M.indexOf(r):M.length-1,m=M.filter((g,f)=>s.includes(g)&&f<=t),l=e.map($).filter(Number.isFinite);if(!l.length)return{rows:m.map(g=>({level:g,counts:[]})),buckets:[],width:0,busiest:null};const p=Math.min(...l),o=Math.max(...l),c=ne(p,o,n),v=c.length>1?c[1]-c[0]:Math.max(o-p,6e4),x=new Map(m.map(g=>[g,new Array(c.length).fill(0)])),u=new Array(c.length).fill(0),j=new Array(c.length).fill(0);for(const g of e){const f=$(g),y=x.get(g.level);if(!y||!Number.isFinite(f))continue;const w=Math.min(c.length-1,Math.floor((f-c[0])/v));y[w]++,u[w]++,g.level==="error"&&j[w]++}const i=g=>g.reduce((f,y,w)=>y>g[f]?w:f,0),h=j.reduce((g,f)=>g+f,0),d=i(h?j:u);return{rows:m.map(g=>({level:g,counts:x.get(g)})),buckets:c,width:v,busiest:{start:c[d],count:h?j[d]:u[d],errors:h}}}function me({records:e,offered:s,minimum:r,setMinimum:n}){const t=L(),m=O[R()],l=P(),p=b.useMemo(()=>pe(e,s,r),[e,s,r]),o=b.useMemo(()=>new Intl.DateTimeFormat(m,{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}),[m]),c=b.useCallback(i=>`${o.format(i)}–${o.format(i+p.width)}`,[o,p.width]),v=b.useMemo(()=>{const i=Object.keys(T).map(h=>{const d=t(T[h]);return[h,{text:d,label:a.jsxs(W,{quiet:!0,small:!0,className:h===r?"current":void 0,label:t(h===r?"log.chart.current":"log.chart.minimum",{level:d}),onPress:()=>n(h),children:[h===r&&a.jsx(q,{}),d]})}]});return new Map(i)},[r,n,t]),x=b.useMemo(()=>{const i={error:l.negative,warn:l.notice,info:l.info,debug:l.subtle,trace:l.muted},h=p.buckets.map(c);return{columns:p.buckets.map(d=>o.format(d)),rows:p.rows.map(d=>{const{text:g,label:f}=v.get(d.level);return{id:d.level,color:i[d.level],label:f,counts:d.counts,titles:d.counts.map((y,w)=>t("log.chart.cell",{time:h[w],level:g,n:y}))}})}},[p,c,o,v,l,t]);if(!e.length)return null;const u=p.busiest,j=u?u.errors?[{label:t("log.chart.errors"),value:t("log.chart.count",{n:u.errors}),icon:a.jsx(k,{}),tone:"negative"},{label:t("log.chart.peakErrors"),icon:a.jsx(C,{}),tint:"c1",value:c(u.start),caption:t("log.chart.count",{n:u.count})}]:[{label:t("log.chart.errors"),value:t("log.chart.count",{n:0}),icon:a.jsx(k,{}),tint:"c5"},{label:t("log.chart.peak"),icon:a.jsx(C,{}),tint:"c1",value:c(u.start),caption:t("log.chart.count",{n:u.count})}]:[];return a.jsxs("div",{className:"rp-chart-page",children:[a.jsx(se,{facts:j}),a.jsx(H,{title:t("log.chart.title"),note:t("log.chart.sample",{n:e.length}),children:a.jsx(de,{label:t("log.chart.title"),columns:x.columns,rows:x.rows})})]})}const D=["trace","debug","info","warn","error"],he={trace:"muted",debug:"neutral",info:"info",warn:"warn",error:"err"},A=new WeakMap;function fe(e,s,r){const n=A.get(e);if(n&&n.locale===s)return n.row;const t={id:e.id,timestamp:I(e.ts,s),iso:e.ts,levelText:N(T,e.level,r),tone:he[e.level],target:e.target,gap:!1,message:e.message+(e.fields?" "+Object.entries(e.fields).map(([m,l])=>`${m}=${typeof l=="string"?l:JSON.stringify(l)}`).join(" "):"")};return A.set(e,{locale:s,row:t}),t}function xe(e,s,r,n,t,m=new Set,l){const p=o=>!!l&&D.indexOf(o){const c=fe(o,n,t);return m.has(o)?[{...c,id:`gap ${o.id}`,timestamp:"",iso:"",levelText:"",target:"",gap:!0,message:t("log.gap")},c]:[c]}),levels:s.map(o=>({id:o,label:p(o)?t("log.levelNotRecorded",{level:N(T,o,t)}):N(T,o,t)})),recordedText:l?t("log.recorded",{level:N(T,l,t)}):null,exportBase:`${r||"engine"}-log`}}function be(e,s,r){return r(ue(e,s,{forbidden:"log.emptyForbidden",off:"log.emptyNotRecorded",filtered:"log.emptyFiltered",empty:"log.empty"}))}function ve(e,s,r,n,t,m,l){return s?{tone:"err",text:l("log.disconnected")}:r?{tone:"neutral",text:l("log.paused",{n:n>t?`${G(t,m)}+`:n})}:{tone:e?"ok":"warn",text:l(e?"log.connected":"log.reconnecting")}}function je(e,s=[]){return s.includes(e)?e:s.includes("info")?"info":s[0]}function we(e,s,r){return[...e].reverse().flatMap(n=>{const t=`${n.ts} ${n.level.toUpperCase().padEnd(5)} ${n.target} ${n.message}${n.fields?" "+JSON.stringify(n.fields):""}`;return s.has(n)?[t,r("log.gap")]:[t]}).join(` `)+` `}const ye=[];function Te(){const e=L(),s=O[R()],r=J(),n=_(),[t,m]=b.useState("info"),l=b.useCallback(f=>m(f),[]),[p,o]=b.useState(""),[c,v]=b.useState(!1),x=V(p.trim()),u=r.data?.resources.logs,j=je(t,u?.levels),i=K({level:j,target:x,paused:c}),h=Q(r.data?.resources.runtime_settings.available??!1).data,d=h?.log.level,g=b.useMemo(()=>xe(i.records,u?.levels??[],n.data?.engine.name,s,e,i.gaps,d),[i.records,i.gaps,u,n.data,s,e,d]);return{...g,empty:be(h?.recording?.logs,!!x,e),status:ve(i.connected,!!i.error,c,i.pending,U,s,e),records:i.records,offered:u?.levels??ye,level:j??"",setLevel:l,target:p,setTarget:o,paused:c,setPaused:v,error:r.error??i.error,loading:!r.error&&!i.error&&!i.connected&&!i.records.length,clear:i.clear,retry:r.error?r.refetch:i.retry,export:()=>ce(ge(g.exportBase,"txt"),we(i.records,i.gaps,e),"text/plain;charset=utf-8")}}function Oe(){const e=L(),s=Te(),r=b.useMemo(()=>[{id:"ts",label:e("ui.time"),minWidth:200,grow:0,drop:2,render:t=>!t.gap&&a.jsx(F,{className:"rp-code",text:t.iso,children:t.timestamp})},{id:"level",label:e("log.level"),minWidth:90,grow:0,drop:3,render:t=>!t.gap&&a.jsx(E,{small:!0,tone:t.tone,children:t.levelText})},{id:"target",label:e("log.target"),minWidth:160,grow:0,drop:1,render:t=>a.jsx("span",{className:"rp-code",children:t.target})},{id:"message",label:e("log.message"),minWidth:280,grow:3,isRowHeader:!0,render:t=>a.jsx(F,{children:t.message})}],[e]),n=b.useCallback(t=>a.jsx(z,{inline:!0,items:t.gap?[[e("log.message"),t.message]]:[[e("ui.time"),t.timestamp],[e("log.level"),t.levelText],[e("log.target"),t.target],[e("log.message"),t.message]]}),[e]);return a.jsxs("div",{className:"rp-page",children:[a.jsxs("div",{className:"rp-toolbar",children:[a.jsx(X,{side:!0,label:e("log.level"),value:s.level,onChange:s.setLevel,items:s.levels}),a.jsx(Y,{search:!0,label:e("log.target"),value:s.target,width:240,placeholder:e("log.targetPlaceholder"),onChange:s.setTarget}),a.jsx(Z,{isSelected:s.paused,onChange:s.setPaused,children:e("log.pause")}),a.jsx(E,{small:!0,tone:s.status.tone,children:s.status.text}),s.recordedText&&a.jsx("span",{className:"rp-label",children:s.recordedText}),a.jsx("span",{className:"rp-grow"}),a.jsx(ie,{actions:[{id:"clear",label:e("log.clear"),isDisabled:!s.rows.length,onAction:s.clear},{id:"export",label:e("log.export"),icon:a.jsx(ee,{}),isDisabled:!s.rows.length,onAction:s.export}]})]}),a.jsx(te,{error:s.error,onRetry:s.retry}),a.jsx(me,{records:s.records,offered:s.offered,minimum:s.level,setMinimum:s.setLevel}),a.jsx(le,{label:e("nav.logs"),stream:!0,rows:s.rows,height:640,loading:s.loading,empty:s.empty,cols:r,detail:n})]})}export{Oe as Logs};