LogsTab-DyXsGK2-.js raw
1 import{r,b as d,j as t,B as j,c as C,t as u}from"./index-DfKg850Q.js";const k=["trace","debug","info","warn","error","fatal"];function F(a){switch(a==null?void 0:a.toUpperCase()){case"TRC":case"TRACE":return"bg-gray-500 text-white";case"DBG":case"DEBUG":return"bg-cyan-600 text-white";case"INF":case"INFO":return"bg-green-600 text-white";case"WRN":case"WARN":return"bg-yellow-500 text-black";case"ERR":case"ERROR":return"bg-red-600 text-white";case"FTL":case"FATAL":return"bg-red-900 text-white";default:return"bg-green-600 text-white"}}function A(){const[a,o]=r.useState([]),[n,m]=r.useState(!1),[g,h]=r.useState(!0),[N,p]=r.useState(0),[f,L]=r.useState("info"),[y,x]=r.useState("info"),[b,v]=r.useState(""),l=r.useRef(0),w=r.useRef(null),i=r.useCallback(async(e=!1)=>{if(!n){m(!0),v(""),e&&(l.current=0,o([]));try{const s=await d.getLogs(String(l.current),100),c=s.logs||[];o(e?c:S=>[...S,...c]),p(s.total||0),h(s.has_more||!1),l.current+=c.length}catch(s){v(s instanceof Error?s.message:"Failed to load logs")}finally{m(!1)}}},[n]);r.useEffect(()=>{i(!0),d.getLogLevel().then(e=>{L(e),x(e)})},[]),r.useEffect(()=>{const e=w.current;if(!e)return;const s=new IntersectionObserver(c=>{c[0].isIntersecting&&g&&!n&&i(!1)},{threshold:.1});return s.observe(e),()=>s.disconnect()},[g,n,i]);const E=async e=>{if(x(e),e!==f)try{await d.setLogLevel(e),L(e),u.success(`Log level set to ${e}`)}catch(s){x(f),u.error(`Failed to set log level: ${s instanceof Error?s.message:String(s)}`)}},R=async()=>{if(confirm("Clear all logs?"))try{await d.clearLogs(),o([]),p(0),h(!1),l.current=0,u.success("Logs cleared")}catch(e){u.error(`Failed: ${e instanceof Error?e.message:String(e)}`)}};return t.jsxs("div",{className:"p-4 space-y-3 w-full",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsx("h3",{className:"text-lg font-semibold",children:"Logs"}),t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("label",{className:"text-sm text-muted-foreground",children:"Level:"}),t.jsx("select",{value:y,onChange:e=>E(e.target.value),className:"rounded-md border bg-card px-2 py-1 text-sm",children:k.map(e=>t.jsx("option",{value:e,children:e},e))}),t.jsx(j,{variant:"outline",size:"sm",onClick:R,disabled:n||a.length===0,children:"Clear"}),t.jsx(j,{size:"sm",onClick:()=>i(!0),disabled:n,children:n?"Loading...":"Refresh"})]})]}),b&&t.jsx("div",{className:"rounded-md bg-destructive/10 text-destructive p-3 text-sm",children:b}),t.jsxs("div",{className:"text-xs text-muted-foreground",children:["Showing ",a.length," of ",N," logs (Level: ",f,")"]}),t.jsxs("div",{className:"space-y-1",children:[a.length===0&&!n?t.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No logs available."}):a.map((e,s)=>t.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-card px-3 py-2 font-mono text-xs",children:[t.jsx("span",{className:"text-muted-foreground whitespace-nowrap shrink-0",children:e.timestamp?new Date(e.timestamp).toLocaleString():""}),t.jsx("span",{className:C("rounded px-1.5 py-0.5 text-center font-bold uppercase shrink-0 min-w-[3.5em]",F(e.level)),children:e.level}),e.file&&t.jsxs("span",{className:"text-muted-foreground/50 shrink-0",children:[e.file,":",e.line]}),t.jsx("span",{className:"flex-1 break-all",children:e.message})]},s)),t.jsx("div",{ref:w,className:"text-center py-4 text-xs text-muted-foreground",children:n?"Loading more...":g?"Scroll for more":a.length>0?"End of logs":""})]})]})}export{A as default};
2