1import{r,j as e}from"./vendor-chartjs-DAQApR3A.js";import{h as T}from"./monitoringApi-BiwSHvvt.js";import{B as w}from"./types-DyrcxsOr.js";import{b as A}from"./index-VXtZNIH-.js";import"./adminAuth-CHjczaih.js";import"./vendor-recharts-KyLwo51t.js";import"./vendor-maps-DjSiDsVE.js";const p="__all__";function G(){const[C]=A(),E=C.get("job")||p,[a,B]=r.useState(E),[o,k]=r.useState(""),[d,m]=r.useState([]),[g,v]=r.useState(null),[u,L]=r.useState(!1),[y,S]=r.useState(!1),[h,f]=r.useState(null),j=r.useRef(void 0),x=r.useCallback(async(t,n,l=!1,N)=>{l?S(!0):(L(!0),m([]),v(null)),f(null);try{if(t===p){const i=(await Promise.all(w.map(s=>T(s,{search:n||void 0,limit:50}).then(b=>({...b,events:b.events.map($=>({...$,log_stream:s}))})).catch(()=>({events:[],next_token:null,job_name:s}))))).flatMap(s=>s.events);i.sort((s,b)=>b.timestamp.localeCompare(s.timestamp)),m(l?s=>[...s,...i]:i),v(null)}else{const c=await T(t,{search:n||void 0,next_token:l?N??void 0:void 0,limit:200});c.error&&f(c.error);const i=c.events.map(s=>({...s,log_stream:s.log_stream||t}));m(l?s=>[...s,...i]:i),v(c.next_token)}}catch(c){f(c instanceof Error?c.message:"Failed to load logs")}finally{L(!1),S(!1)}},[]);r.useEffect(()=>{k(""),x(a,"")},[a,x]),r.useEffect(()=>(clearTimeout(j.current),j.current=setTimeout(()=>{x(a,o)},400),()=>clearTimeout(j.current)),[o,a,x]);const F=()=>{g&&x(a,o,!0,g)},J=t=>{try{return new Date(t).toLocaleString()}catch{return t}},M=t=>t?w.includes(t)?t:t.split("/")[0]||t:"â",R=t=>o?t.split(new RegExp(`(${o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi")).map((l,N)=>l.toLowerCase()===o.toLowerCase()?e.jsx("mark",{style:{background:"#f59e0b60",color:"inherit",borderRadius:"2px"},children:l},N):l):t,_=a===p;return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold",style:{color:"var(--text-primary)"},children:"Log Viewer"}),e.jsx("p",{className:"text-sm mt-1",style:{color:"var(--text-secondary)"},children:"Browse and search batch job logs"})]}),e.jsxs("div",{className:"flex gap-3 mb-6 flex-wrap",children:[e.jsxs("select",{value:a,onChange:t=>B(t.target.value),className:"px-4 py-2 rounded-lg text-sm",style:{background:"var(--bg-secondary)",border:"1px solid var(--border)",color:"var(--text-primary)"},children:[e.jsx("option",{value:p,children:"All Jobs"}),w.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsxs("div",{className:"flex-1 min-w-[200px] relative",children:[e.jsx("input",{type:"text",value:o,onChange:t=>k(t.target.value),placeholder:"Filter logs...",className:"w-full px-4 py-2 rounded-lg text-sm",style:{background:"var(--bg-secondary)",border:"1px solid var(--border)",color:"var(--text-primary)"}}),u&&o&&e.jsx("i",{className:"bi bi-arrow-clockwise animate-spin absolute right-3 top-2.5",style:{color:"var(--text-muted)"}})]})]}),h&&e.jsxs("div",{className:"p-4 rounded-lg mb-6 text-sm",style:{background:"#ef444420",color:"#ef4444",border:"1px solid #ef444440"},children:[e.jsx("i",{className:"bi bi-exclamation-triangle mr-2"}),h]}),u&&d.length===0&&!h&&e.jsxs("div",{className:"p-12 rounded-xl text-center",style:{background:"var(--bg-secondary)",border:"1px solid var(--border)"},children:[e.jsx("i",{className:"bi bi-arrow-clockwise animate-spin text-2xl mb-3 block",style:{color:"var(--text-muted)"}}),e.jsxs("p",{className:"text-sm",style:{color:"var(--text-muted)"},children:["Loading logs",a!==p?` for ${a}`:"","..."]})]}),d.length===0&&!u&&!h&&e.jsxs("div",{className:"p-12 rounded-xl text-center",style:{background:"var(--bg-secondary)",border:"1px solid var(--border)"},children:[e.jsx("i",{className:"bi bi-terminal text-4xl mb-3 block",style:{color:"var(--text-muted)"}}),e.jsx("p",{className:"text-lg font-medium mb-2",style:{color:"var(--text-primary)"},children:"No logs found"}),e.jsx("p",{className:"text-sm",style:{color:"var(--text-muted)"},children:o?"Try a different search term.":"No log events in the last 24 hours."})]}),d.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:e.jsxs("span",{className:"text-sm",style:{color:"var(--text-muted)"},children:[d.length," events loaded",u&&e.jsx("i",{className:"bi bi-arrow-clockwise animate-spin ml-2"})]})}),e.jsx("div",{className:"rounded-xl overflow-auto max-h-[600px]",style:{background:"var(--bg-secondary)",border:"1px solid var(--border)"},children:e.jsxs("table",{className:"w-full text-xs",style:{fontFamily:'"SF Mono", "Fira Code", monospace'},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{borderBottom:"1px solid var(--border)"},children:[e.jsx("th",{className:"text-left px-3 py-2 sticky top-0",style:{background:"var(--bg-secondary)",color:"var(--text-muted)",width:"180px"},children:"Timestamp"}),_&&e.jsx("th",{className:"text-left px-3 py-2 sticky top-0",style:{background:"var(--bg-secondary)",color:"var(--text-muted)",width:"160px"},children:"Service"}),e.jsx("th",{className:"text-left px-3 py-2 sticky top-0",style:{background:"var(--bg-secondary)",color:"var(--text-muted)"},children:"Message"})]})}),e.jsx("tbody",{children:d.map((t,n)=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border)"},children:[e.jsx("td",{className:"px-3 py-1.5 whitespace-nowrap align-top",style:{color:"var(--text-muted)"},children:J(t.timestamp)}),_&&e.jsx("td",{className:"px-3 py-1.5 whitespace-nowrap align-top",style:{color:"var(--accent)"},children:M(t.log_stream)}),e.jsx("td",{className:"px-3 py-1.5",style:{color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:R(t.message)})]},n))})]})}),g&&e.jsx("div",{className:"mt-4 text-center",children:e.jsx("button",{onClick:F,disabled:y,className:"px-6 py-2 rounded-lg text-sm font-medium",style:{background:"var(--bg-tertiary)",color:"var(--text-secondary)",border:"1px solid var(--border)",opacity:y?.7:1},children:y?e.jsxs(e.Fragment,{children:[e.jsx("i",{className:"bi bi-arrow-clockwise animate-spin mr-2"}),"Loading..."]}):e.jsxs(e.Fragment,{children:[e.jsx("i",{className:"bi bi-plus-circle mr-2"}),"Load More"]})})})]})]})}export{G as OperationsLogs};
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.