import{Q as w,a as y}from"./QTabs-DDPi3I4f.js";import{_ as k,M as c,a as m,w as d,Z as L,H as g,R as f,o as r,$ as u,O as h,P as p,c as b,av as _,K as T,a1 as x}from"./app-DzAYC6xy.js";import{Q as S,a as V}from"./QTabPanels-BoyjPjzt.js";import{d as A}from"./utils-wZ-HUk39.js";import"./QResizeObserver-AIPqLUpr.js";import"./rtl-DFPa-2ov.js";import"./externalHosting.js";import"./use-panel-BY-6Lf7y.js";import"./touch-BjYP5sR0.js";import"./selection-vu7NfHfB.js";import"./use-render-cache-DLxPkVnQ.js";const E={name:"Logs",data(){return{ACTION:g,RESOURCE:f,threshold:0,isAtTop:!1,autoScroll:!0,searchText:"",activeTab:"unlimited",logTabs:[{name:"unlimited",icon:"all_inclusive",label:"Unlimited",perm:"READ"},{name:"game",icon:"sports_esports",label:"Game",perm:"GAME"},{name:"player",icon:"sports_martial_arts",label:"Player",perm:"PLAYER"},{name:"dev",icon:"code",label:"Dev",perm:"DEV"},{name:"web",icon:"language",label:"Web",perm:"WEB"}],logData:{unlimited:[],game:[],player:[],dev:[],web:[]}}},watch:{isAtTop(e){e&&this.fetchLogs(this.activeTab)},activeTab(e,t){this.handleSocketRoom(e,t)}},computed:{filteredLogs(){return this.logData[this.activeTab].filter(e=>e.toLowerCase().includes(this.searchText.toLowerCase()))},allowedLogTabs(){return this.logTabs.filter(e=>this.can(g.GAME.LOGS[e.perm],f.GAME))}},methods:{can:A,handleScroll(e){this.isAtTop=e.target.scrollTop<=this.threshold},async handleSocketRoom(e,t=null){t&&this.$socket.emit("room::leave",`logs-${t}`),this.logData[t]=[],await this.fetchLogs(e);const o=this.$refs[e][0];o.scrollTop=o.scrollHeight,this.$socket.emit("room::join",`logs-${e}`)},async fetchLogs(e){await this.$axios.post("/api/logs",{type:e,fromline:this.logData[e][0]}).then(t=>{const o=t.data.logs;Array.isArray(o)&&o.forEach(s=>this.logData[this.activeTab].unshift(s)),this.$nextTick(async()=>{const s=this.$refs[e][0];if(s?.scrollHeight===s?.clientHeight&&o.length===50){if(await this.fetchLogs(this.activeTab),!this.autoScroll)return;s.scrollTop=s.scrollHeight}})})},updateLogs(e){this.logData[e.type].push(e.newLine),this.$nextTick(()=>{if(!this.autoScroll)return;const t=this.$refs[e.type][0];t.scrollTop=t.scrollHeight})}},async mounted(){await this.handleSocketRoom(this.activeTab),this.sockets.subscribe("logs::update",this.updateLogs),this.$socket.emit("room::join",`logs-${this.activeTab}`)},beforeUnmount(){this.sockets.unsubscribe("logs::update"),this.$socket.emit("room::leave",`logs-${this.activeTab}`)}},D={class:"row q-pa-sm"},$={class:"row"},Q={class:"q-mb-sm row items-center"},R={class:"text-caption q-mx-auto text-center text-sub"};function C(e,t,o,s,l,n){return r(),c("div",D,[m(L,{class:"logs-card full-width"},{default:d(()=>[u("div",$,[m(w,{modelValue:l.activeTab,"onUpdate:modelValue":t[0]||(t[0]=a=>l.activeTab=a),class:"text-main full-width row justify-center","indicator-color":"primary","active-color":"primary"},{default:d(()=>[(r(!0),c(h,null,p(n.allowedLogTabs,a=>(r(),b(y,{key:a.name,name:a.name,icon:a.icon,label:a.label},null,8,["name","icon","label"]))),128))]),_:1},8,["modelValue"]),m(S,{modelValue:l.activeTab,"onUpdate:modelValue":t[4]||(t[4]=a=>l.activeTab=a),animated:"","transition-prev":"fade","transition-next":"fade",class:"full-width logs-panel"},{default:d(()=>[(r(!0),c(h,null,p(n.allowedLogTabs,a=>(r(),b(V,{key:a.name+"_panel",name:a.name,class:"overflow-hidden"},{default:d(()=>[u("div",Q,[m(_,{modelValue:l.autoScroll,"onUpdate:modelValue":t[1]||(t[1]=i=>l.autoScroll=i),label:"Auto Scroll"},null,8,["modelValue"]),u("div",R,T(e.$t("components.logs.loadMore")),1)]),u("div",{class:"q-pa-sm log-container",ref_for:!0,ref:a.name,onScroll:t[2]||(t[2]=(...i)=>n.handleScroll&&n.handleScroll(...i))},[(r(!0),c(h,null,p(n.filteredLogs,(i,v)=>(r(),c("code",{style:{display:"block"},key:`${a.name}_${v}`},T(i),1))),128))],544),m(x,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",dense:"",class:"full-width",square:"",modelValue:l.searchText,"onUpdate:modelValue":t[3]||(t[3]=i=>l.searchText=i),label:e.$t("general.search")},null,8,["modelValue","label"])]),_:2},1032,["name"]))),128))]),_:1},8,["modelValue"])])]),_:1})])}const W=k(E,[["render",C],["__scopeId","data-v-3451c964"]]);export{W as default};
