import{a as i,j as H,w as T,o as q,K as P,c as u,h as C,i as p,q as r,O as o,P as G,e as n,y as x,H as J,t as Q,l as X,p as A,u as Y,n as Z,d as s,v as h,F as ee,B as le,S as oe}from"./vendor-core.B6UiYhU_.js";import{I as S,E as se,s as B}from"./vendor-primevue.BN-meDW0.js";import{_ as te,a as ae,b as ne,f as ie,d as M}from"./index.B8XI8FQW.js";import{b as re}from"./vendor-utils.CO3CyGpV.js";import{M as ue}from"./MobileTopBar.BnL78WPy.js";import{M as ce}from"./MobileBottomNav.Cp8OR33w.js";import"./vendor-export.BWjBvx7Z.js";const de={key:1,class:"stats-header"},pe={class:"actions"},ve={key:2,class:"mobile-controls-bar"},ge={class:"logs-title"},fe={key:1,class:"auto-refresh-indicator"},be={key:0,class:"logs-path"},me={key:0,class:"loading-container"},ye={key:1,class:"empty-logs"},ke={class:"logs-content"},he={__name:"ServerLogsView",setup(we){const z=re.create({baseURL:"/roa2web/api/system",headers:{"Content-Type":"application/json"}});z.interceptors.request.use(t=>{const e=localStorage.getItem("access_token");return e&&(t.headers.Authorization=`Bearer ${e}`),t});const N=G(),v=i([]),w=i(!1),y=i(null),d=i("backend-stderr"),_=i(""),b=i(100),c=i(!1),$=i(5),L=i(null),k=i({logs_path:null,file_exists:!0,file_size_kb:null});let V=null;const m=i(window.innerWidth<768),j=H(()=>[{icon:"pi pi-refresh",label:"Actualizează",tooltip:"Actualizează"},{icon:"pi pi-download",label:"Export",tooltip:"Export Loguri"}]),O=t=>{t.icon==="pi pi-refresh"?g():t.icon==="pi pi-download"&&W()},U=()=>{m.value=window.innerWidth<768},W=()=>{if(v.value.length===0)return;const t=v.value.join(` `),e=new Blob([t],{type:"text/plain"}),a=URL.createObjectURL(e),l=document.createElement("a");l.href=a,l.download=`server-logs-${d.value}-${new Date().toISOString().slice(0,10)}.txt`,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(a)},E=[{label:"Errors (stderr)",value:"backend-stderr"},{label:"Info (stdout)",value:"backend-stdout"}],I=[{label:"50 lines",value:50},{label:"100 lines",value:100},{label:"200 lines",value:200},{label:"500 lines",value:500}],g=async()=>{var t,e,a;w.value=!0,y.value=null;try{const l={file:d.value,lines:b.value};_.value&&(l.filter=_.value),console.log("[ServerLogs] Fetching logs from:",z.defaults.baseURL+"/logs",l);const f=await z.get("/logs",{params:l});console.log("[ServerLogs] Response:",f.data),v.value=f.data.lines||[],k.value={logs_path:f.data.logs_path||null,file_exists:f.data.file_exists??!0,file_size_kb:f.data.file_size_kb??null},await Z(),L.value&&(L.value.scrollTop=L.value.scrollHeight)}catch(l){console.error("[ServerLogs] Failed to load logs:",l),console.error("[ServerLogs] Error details:",(t=l.response)==null?void 0:t.data,l.message),y.value=((a=(e=l.response)==null?void 0:e.data)==null?void 0:a.detail)||l.message||"Failed to load logs - check console for details"}finally{w.value=!1}},D=t=>{const e=t.toLowerCase(),a={display:"block",padding:"3px 8px",borderRadius:"2px",fontFamily:"'Consolas', 'Monaco', 'Courier New', monospace",fontSize:"0.8125rem",lineHeight:"1.6"};return e.includes("error")||e.includes("exception")||e.includes("failed")?{...a,color:"#b91c1c",backgroundColor:"rgba(185, 28, 28, 0.1)",fontWeight:"600"}:e.includes("warning")||e.includes("warn")?{...a,color:"#b45309",backgroundColor:"rgba(180, 83, 9, 0.1)",fontWeight:"500"}:e.includes("success")||e.includes("completed")?{...a,color:"#047857",backgroundColor:"rgba(4, 120, 87, 0.1)"}:{...a,color:"#000000",backgroundColor:"rgba(0, 0, 0, 0.02)"}},F=()=>{c.value=!c.value,c.value?K():R()},K=()=>{R(),V=setInterval(()=>{g()},$.value*1e3)},R=()=>{V&&(clearInterval(V),V=null)};return T(d,()=>{g()}),T(b,()=>{g()}),q(()=>{window.addEventListener("resize",U),g()}),P(()=>{window.removeEventListener("resize",U),R()}),(t,e)=>{const a=X("tooltip");return s(),u("div",{class:Y(["server-logs-view",{"mobile-layout":m.value}])},[m.value?(s(),C(ue,{key:0,title:"Loguri Server","show-back":!0,actions:j.value,onBackClick:e[0]||(e[0]=l=>o(N).push("/settings")),onActionClick:O},null,8,["actions"])):p("",!0),m.value?p("",!0):(s(),u("div",de,[e[7]||(e[7]=n("h1",null,[n("i",{class:"pi pi-file-edit"}),x(" Server Logs ")],-1)),n("div",pe,[r(o(S),{modelValue:d.value,"onUpdate:modelValue":e[1]||(e[1]=l=>d.value=l),options:E,optionLabel:"label",optionValue:"value",placeholder:"Select log file",class:"log-file-select"},null,8,["modelValue"]),r(o(se),{modelValue:_.value,"onUpdate:modelValue":e[2]||(e[2]=l=>_.value=l),placeholder:"Filter (e.g., ocr, error)",class:"filter-input",onKeyup:J(g,["enter"])},null,8,["modelValue"]),r(o(S),{modelValue:b.value,"onUpdate:modelValue":e[3]||(e[3]=l=>b.value=l),options:I,optionLabel:"label",optionValue:"value",class:"lines-select"},null,8,["modelValue"]),r(o(B),{label:"Refresh",icon:"pi pi-refresh",onClick:g,loading:w.value},null,8,["loading"]),r(o(B),{label:"Auto",icon:c.value?"pi pi-pause":"pi pi-play",severity:c.value?"warning":"secondary",onClick:F},null,8,["icon","severity"])])])),m.value?(s(),u("div",ve,[r(o(S),{modelValue:d.value,"onUpdate:modelValue":e[4]||(e[4]=l=>d.value=l),options:E,optionLabel:"label",optionValue:"value",placeholder:"Log file",class:"mobile-log-select"},null,8,["modelValue"]),r(o(S),{modelValue:b.value,"onUpdate:modelValue":e[5]||(e[5]=l=>b.value=l),options:I,optionLabel:"label",optionValue:"value",class:"mobile-lines-select"},null,8,["modelValue"]),Q(r(o(B),{icon:c.value?"pi pi-pause":"pi pi-play",severity:c.value?"warning":"secondary",onClick:F,class:"mobile-auto-btn"},null,8,["icon","severity"]),[[a,c.value?"Stop Auto":"Start Auto",void 0,{bottom:!0}]])])):p("",!0),y.value?(s(),C(o(ae),{key:3,severity:"error",closable:!0,onClose:e[6]||(e[6]=l=>y.value=null)},{default:A(()=>[x(h(y.value),1)]),_:1})):p("",!0),r(o(ne),{class:"logs-card"},{title:A(()=>[n("div",ge,[n("span",null,h(d.value==="backend-stderr"?"Errors & Warnings":"Info Logs"),1),r(o(M),{value:`${v.value.length} lines`,severity:"info"},null,8,["value"]),k.value.file_size_kb!==null?(s(),C(o(M),{key:0,value:`${k.value.file_size_kb} KB`,severity:"secondary",class:"ml-2"},null,8,["value"])):p("",!0),c.value?(s(),u("span",fe,[e[8]||(e[8]=n("i",{class:"pi pi-spin pi-sync"},null,-1)),x(" Auto-refresh: "+h($.value)+"s ",1)])):p("",!0)]),k.value.logs_path?(s(),u("div",be,[n("small",null,[e[9]||(e[9]=n("i",{class:"pi pi-folder"},null,-1)),x(" "+h(k.value.logs_path),1)])])):p("",!0)]),content:A(()=>[w.value&&v.value.length===0?(s(),u("div",me,[r(o(ie)),e[10]||(e[10]=n("p",null,"Loading logs...",-1))])):v.value.length===0?(s(),u("div",ye,[...e[11]||(e[11]=[n("i",{class:"pi pi-inbox"},null,-1),n("p",null,"No log entries found",-1)])])):(s(),u("div",{key:2,class:"logs-container",ref_key:"logsContainer",ref:L},[n("pre",ke,[(s(!0),u(ee,null,le(v.value,(l,f)=>(s(),u("code",{key:f,style:oe(D(l))},h(l),5))),128))])],512))]),_:1}),m.value?(s(),C(ce,{key:4})):p("",!0)],2)}}},Re=te(he,[["__scopeId","data-v-4383ab53"]]);export{Re as default}; //# sourceMappingURL=ServerLogsView.CpW2zGtt.js.map