import{C as I}from"./Container-C7yRkeCv.js";import{az as B,J as r,i as y,L as E,a3 as R,ax as S,aF as z,aG as v,aH as n,o as a,bF as F,E as f,cn as N,M as V,aV as b,aW as i,bi as j,cw as D,aP as _,aK as x,by as H,bp as M,cc as O,bg as P,bc as C,R as A,_ as G}from"./index-D2rF_80D.js";import{V as J}from"./VSwitch-DnBzHYGj.js";import"./index-kQIztB-E.js";import"./VSelectionControl-BHjDOTFl.js";const K={class:"d-flex flex-column flex-sm-row align-start align-sm-center ga-2 w-100"},W={class:"d-flex flex-wrap ga-2"},q={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 s=null;const k=y(()=>{const e=c.value.split(`
`);return e.length>h?e.slice(-h).join(`
`):c.value}),L=y(()=>c.value.split(`
`).length>h),T=()=>{u.value&&A(()=>{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(`${C.baseUrl}/music-assistant.log`);if(!t.ok)throw new Error(`Failed to fetch logs: ${t.statusText}`);const o=await t.text(),l=c.value;c.value=o,(!e||o!==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)},$=async()=>{try{const t=await(await fetch(`${C.baseUrl}/music-assistant.log`)).blob(),o=window.URL.createObjectURL(t),l=document.createElement("a");l.href=o,l.download="music-assistant.log",document.body.appendChild(l),l.click(),document.body.removeChild(l),window.URL.revokeObjectURL(o)}catch(e){console.error("Error downloading log:",e)}};return E(p,e=>{e?s=setInterval(()=>{g(!0)},5e3):s&&(clearInterval(s),s=null)}),R(async()=>{await g(!1),p.value&&(s=setInterval(()=>{g(!0)},5e3))}),S(()=>{s&&clearInterval(s)}),(e,t)=>(v(),z(I,null,{default:n(()=>[a(P,{class:"mb-4",elevation:"0",variant:"flat"},{default:n(()=>[a(F,{class:"text-subtitle-1 font-weight-bold py-3"},{default:n(()=>[f("div",K,[a(J,{modelValue:p.value,"onUpdate:modelValue":t[0]||(t[0]=o=>p.value=o),color:"primary",density:"compact","hide-details":"",label:e.$t("settings.auto_refresh_log")},null,8,["modelValue","label"]),a(N,{class:"d-none d-sm-block"}),f("div",W,[a(V,{color:"primary",variant:"text",loading:w.value,"prepend-icon":"mdi-refresh",size:"small",onClick:U},{default:n(()=>[b(i(e.$t("settings.reload")),1)]),_:1},8,["loading"]),a(V,{color:"primary",variant:"elevated","prepend-icon":"mdi-download",size:"small",onClick:$},{default:n(()=>[b(i(e.$t("settings.download_log")),1)]),_:1})])])]),_:1}),a(j),a(D,{class:"pa-0"},{default:n(()=>[m.value?(v(),_("div",q,[a(H,{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(O,{type:"info",variant:"tonal"},{default:n(()=>[b(i(e.$t("settings.log_truncated",[h])),1)]),_:1})])):x("",!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)):x("",!0)]),_:1})]),_:1})]),_:1}))}}),ie=G(te,[["__scopeId","data-v-30a4366c"]]);export{ie as default};
