import{a as q}from"./DCp3GJQW.js";import{_ as D}from"./CLsTGSNv.js";import{_ as O}from"./DWMhLzME.js";import{_ as F}from"./B2vj_HiW.js";import{_ as G}from"./C2BUFUls.js";import{s as J,_ as K}from"./bW-720fM.js";import{_ as Q}from"./DKIXA6Zt.js";import{_ as W}from"./CnlcD-w9.js";import{u as X}from"./m0N__S0x.js";import{l as Y,af as U,K as Z,J as ee,i as a,k as i,ah as r,v as V,a5 as t,U as d,C as te,N as s,g as oe,h as S,f as l,a0 as u,j as c}from"./D7LY3N47.js";import{_ as le}from"./DlAUqK2U.js";import"./DL7l9XXk.js";import"./CYtbVgsc.js";import"./DqW9UKXb.js";const se={class:"logs-page"},ne={class:"flex items-center justify-between gap-3 flex-wrap"},ae={class:"text-xs text-gray-500 mt-1"},ie={key:0,class:"ml-2 text-amber-600"},re={key:1,class:"ml-2 text-gray-500"},ue={key:0},de={class:"flex items-center gap-2"},me={class:"controls"},ce={class:"autopoll"},pe={key:1,class:"meta"},fe={key:0},_e={key:1},ge={key:2,class:"empty"},ve={class:"empty-sub"},ye={key:3,class:"empty"},xe={key:0,class:"empty-sub"},be={key:1,class:"empty-sub"},he={class:"text-sm text-gray-600"},ke={class:"flex justify-end gap-2"},Se=Y({__name:"logs",setup(we){const T=X(),o=d(null),w=d(!1),g=d(""),v=d(""),p=d(""),y=d(1e3),j=[{label:"200",value:200},{label:"500",value:500},{label:"1,000",value:1e3},{label:"5,000",value:5e3},{label:"10,000",value:1e4}],x=d(!0),f=d(!1),b=d(!1),L=d(null);let C=null,h=null;async function k(n={}){w.value=!0,g.value="";try{const e=new URLSearchParams;e.set("limit",String(y.value)),p.value&&e.set("q",p.value);const _=`/api/logs?${e.toString()}`;o.value=await T(_),n.keepScroll||(await te(),M())}catch(e){g.value=e instanceof Error?e.message:String(e)}finally{w.value=!1}}function M(){const n=L.value;n&&(n.scrollTop=n.scrollHeight)}async function P(){b.value=!0;try{await T("/api/logs",{method:"DELETE"}),f.value=!1,await k()}catch(n){g.value=n instanceof Error?n.message:String(n)}finally{b.value=!1}}U(v,n=>{h&&clearTimeout(h),h=setTimeout(()=>{p.value=n},300)}),U([p,y],()=>{k()});function B(){E(),x.value&&(C=J(()=>{typeof document<"u"&&document.visibilityState!=="visible"||k({keepScroll:!0})},5e3))}function E(){C&&(clearInterval(C),C=null)}return U(x,B),Z(()=>{k(),B()}),ee(()=>{E(),h&&clearTimeout(h)}),(n,e)=>{const _=q,$=D,z=O,N=F,A=G,H=K,I=Q,R=W;return s(),a("div",se,[i(I,null,{header:r(()=>[l("div",ne,[l("div",null,[e[6]||(e[6]=l("h1",{class:"text-lg font-semibold"},"Logs",-1)),l("p",ae,[l("code",null,u(t(o)?.path||"—"),1),t(o)&&!t(o).exists?(s(),a("span",ie,"not found")):t(o)?(s(),a("span",re,[c(u(t(o).total.toLocaleString())+" line(s) total",1),t(o).truncated?(s(),a("span",ue,", tailing last "+u(t(o).limit.toLocaleString()),1)):S("",!0)])):S("",!0)])]),l("div",de,[i(_,{color:"gray",variant:"ghost",size:"sm",loading:t(w),disabled:t(w),onClick:k},{default:r(()=>[...e[7]||(e[7]=[c(" Refresh ",-1)])]),_:1},8,["loading","disabled"]),i(_,{color:"red",variant:"soft",size:"sm",disabled:!t(o)?.exists||t(o)?.total===0||t(b),onClick:e[0]||(e[0]=m=>f.value=!0)},{default:r(()=>[...e[8]||(e[8]=[c(" Clear log ",-1)])]),_:1},8,["disabled"])])])]),default:r(()=>[t(g)?(s(),oe($,{key:0,color:"red",variant:"soft",title:t(g),class:"mb-3"},null,8,["title"])):S("",!0),l("div",me,[i(N,{label:"Search",class:"search-group"},{default:r(()=>[i(z,{modelValue:t(v),"onUpdate:modelValue":e[1]||(e[1]=m=>V(v)?v.value=m:null),placeholder:"Case-insensitive substring filter…",icon:"i-heroicons-magnifying-glass",loading:t(v)!==t(p)},null,8,["modelValue","loading"])]),_:1}),i(N,{label:"Tail lines",class:"tail-group"},{default:r(()=>[i(A,{modelValue:t(y),"onUpdate:modelValue":e[2]||(e[2]=m=>V(y)?y.value=m:null),modelModifiers:{number:!0},options:j},null,8,["modelValue"])]),_:1}),l("div",ce,[i(H,{modelValue:t(x),"onUpdate:modelValue":e[3]||(e[3]=m=>V(x)?x.value=m:null),label:"Auto-refresh (5s)"},null,8,["modelValue"])])]),t(o)?(s(),a("div",pe,[t(p)?(s(),a("span",fe," Showing "+u(t(o).shown.toLocaleString())+" match(es) in last "+u(Math.min(t(o).total,t(o).limit).toLocaleString())+" line(s) ",1)):(s(),a("span",_e," Showing last "+u(t(o).shown.toLocaleString())+" line(s) ",1))])):S("",!0),t(o)&&!t(o).exists?(s(),a("div",ge,[e[11]||(e[11]=l("p",{class:"empty-title"},"Log file does not exist yet",-1)),l("p",ve,[e[9]||(e[9]=c(" aidev creates it on first run. Once ",-1)),l("code",null,u(t(o).path),1),e[10]||(e[10]=c(" exists, lines will appear here. ",-1))])])):t(o)&&t(o).lines.length===0?(s(),a("div",ye,[e[12]||(e[12]=l("p",{class:"empty-title"},"No matching lines",-1)),t(p)?(s(),a("p",xe," Nothing in the last "+u(t(o).limit.toLocaleString())+" lines matches “"+u(t(p))+"”. ",1)):(s(),a("p",be," The log file is empty. "))])):t(o)?(s(),a("pre",{key:4,ref_key:"viewer",ref:L,class:"viewer"},[l("code",null,u(t(o).lines.join(`
`)),1)],512)):S("",!0)]),_:1}),i(R,{modelValue:t(f),"onUpdate:modelValue":e[5]||(e[5]=m=>V(f)?f.value=m:null)},{default:r(()=>[i(I,null,{header:r(()=>[...e[13]||(e[13]=[l("h3",{class:"text-base font-semibold"},"Clear log file?",-1)])]),footer:r(()=>[l("div",ke,[i(_,{variant:"ghost",color:"gray",disabled:t(b),onClick:e[4]||(e[4]=m=>f.value=!1)},{default:r(()=>[...e[16]||(e[16]=[c(" Cancel ",-1)])]),_:1},8,["disabled"]),i(_,{color:"red",loading:t(b),onClick:P},{default:r(()=>[...e[17]||(e[17]=[c(" Clear log ",-1)])]),_:1},8,["loading"])])]),default:r(()=>[l("p",he,[e[14]||(e[14]=c(" This truncates ",-1)),l("code",null,u(t(o)?.path),1),e[15]||(e[15]=c(" to zero bytes. The file itself stays in place. This cannot be undone. ",-1))])]),_:1})]),_:1},8,["modelValue"])])}}}),Ae=le(Se,[["__scopeId","data-v-d2744000"]]);export{Ae as default};
