import{C as $}from"./Container-ZHtGcXZO.js";import{ay as B,J as r,i as b,L as E,a3 as S,b6 as N,aI as R,aA as v,aG as n,o as a,bg as z,E as f,bW as j,M as V,bh as y,aN as i,aU as A,c3 as D,az as _,aB as C,b8 as F,aL as M,aS as O,aP as x,R as P,_ as G}from"./index-BRUnowC8.js";import{V as H}from"./VSwitch-Dcs-7m3i.js";import{V as J}from"./VAlert-DQxypmdN.js";import"./index-kQIztB-E.js";import"./VSelectionControl-Co1cRcmS.js";const W={class:"d-flex flex-column flex-sm-row align-start align-sm-center ga-2 w-100"},q={class:"d-flex flex-wrap ga-2"},K={key:0,class:"pa-8 text-center"},Q={class:"mt-4"},X={key:1,class:"pa-8 text-center"},Y={class:"text-error"},Z={key:2,class:"pa-4 text-center"},ee={class:"log-content"},h=150,te=B({__name:"ServerLogs",setup(ae){const c=r(""),m=r(!0),w=r(!1),d=r(""),p=r(!0),u=r(null);let o=null;const k=b(()=>{const e=c.value.split(`
`);return e.length>h?e.slice(-h).join(`
`):c.value}),L=b(()=>c.value.split(`
`).length>h),T=()=>{u.value&&P(()=>{u.value&&(u.value.scrollTop=u.value.scrollHeight)})},g=async(e=!1)=>{try{e?w.value=!0:m.value=!0,d.value="";const t=await fetch(`${x.baseUrl}/music-assistant.log`);if(!t.ok)throw new Error(`Failed to fetch logs: ${t.statusText}`);const s=await t.text(),l=c.value;c.value=s,(!e||s!==l)&&setTimeout(()=>T(),100)}catch(t){d.value=t.message||"Failed to load server logs",console.error("Error loading logs:",t)}finally{m.value=!1,w.value=!1}},U=()=>{g(!0)},I=async()=>{try{const t=await(await fetch(`${x.baseUrl}/music-assistant.log`)).blob(),s=window.URL.createObjectURL(t),l=document.createElement("a");l.href=s,l.download="music-assistant.log",document.body.appendChild(l),l.click(),document.body.removeChild(l),window.URL.revokeObjectURL(s)}catch(e){console.error("Error downloading log:",e)}};return E(p,e=>{e?o=setInterval(()=>{g(!0)},5e3):o&&(clearInterval(o),o=null)}),S(async()=>{await g(!1),p.value&&(o=setInterval(()=>{g(!0)},5e3))}),N(()=>{o&&clearInterval(o)}),(e,t)=>(v(),R($,null,{default:n(()=>[a(O,{class:"mb-4",elevation:"0",variant:"flat"},{default:n(()=>[a(z,{class:"text-subtitle-1 font-weight-bold py-3"},{default:n(()=>[f("div",W,[a(H,{modelValue:p.value,"onUpdate:modelValue":t[0]||(t[0]=s=>p.value=s),color:"primary",density:"compact","hide-details":"",label:e.$t("settings.auto_refresh_log")},null,8,["modelValue","label"]),a(j,{class:"d-none d-sm-block"}),f("div",q,[a(V,{color:"primary",variant:"text",loading:w.value,"prepend-icon":"mdi-refresh",size:"small",onClick:U},{default:n(()=>[y(i(e.$t("settings.reload")),1)]),_:1},8,["loading"]),a(V,{color:"primary",variant:"elevated","prepend-icon":"mdi-download",size:"small",onClick:I},{default:n(()=>[y(i(e.$t("settings.download_log")),1)]),_:1})])])]),_:1}),a(A),a(D,{class:"pa-0"},{default:n(()=>[m.value?(v(),_("div",K,[a(F,{indeterminate:"",color:"primary"}),f("div",Q,i(e.$t("loading")),1)])):d.value?(v(),_("div",X,[a(M,{icon:"mdi-alert-circle",color:"error",size:"48",class:"mb-4"}),f("div",Y,i(d.value),1)])):L.value?(v(),_("div",Z,[a(J,{type:"info",variant:"tonal"},{default:n(()=>[y(i(e.$t("settings.log_truncated",[h])),1)]),_:1})])):C("",!0),!m.value&&!d.value?(v(),_("div",{key:3,ref_key:"logContainer",ref:u,class:"log-container"},[f("pre",ee,i(k.value),1)],512)):C("",!0)]),_:1})]),_:1})]),_:1}))}}),ce=G(te,[["__scopeId","data-v-30a4366c"]]);export{ce as default};
