import{c as i,a as d,i as p}from"./createLucideIcon-mjjtyxlm.js";import{N as g}from"./Navbar-BpjUb_C-.js";import{a as o}from"./fetch_utils-DBmgNZKq.js";import{T as f,S as m,C as v}from"./trash-2-YONst-Qs.js";import{R as C}from"./rotate-ccw-DTIrC0O4.js";import{D as y}from"./download-30STmUeh.js";import{C as T,T as I,a as L}from"./Notification-CBHXi2s1.js";/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const x=i("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const S=i("chevron-up",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const A=i("chevrons-down",[["path",{d:"m7 6 5 5 5-5",key:"1lc07p"}],["path",{d:"m7 13 5 5 5-5",key:"1d48rs"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const E=i("chevrons-up",[["path",{d:"m17 11-5-5-5 5",key:"e8nh98"}],["path",{d:"m17 18-5-5-5 5",key:"2avn1x"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const B=i("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const P=i("copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/**
 * @license lucide-vue-next v1.0.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const b=i("refresh-cw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]),k=d({components:{Navbar:g,AlertCircle:L,AlertTriangle:I,Check:v,CheckCircle:T,ChevronDown:x,ChevronUp:S,ChevronsDown:A,ChevronsUp:E,Copy:P,Download:y,RefreshCw:b,RotateCcw:C,Search:m,Trash2:f,XCircle:B},data(){return{clients:[],closeAppPressed:!1,closeAppStatus:null,ddResetPressed:!1,ddResetStatus:null,logsCopied:!1,logs:"Loading...",logFilter:null,logInterval:null,restartPressed:!1,showApplyMessage:!1,platform:"",controllerEnabled:!1,unpairAllPressed:!1,unpairAllStatus:null,vigembus:{installed:!1,version:"",version_compatible:!1,packaged_version:""},vigemBusInstallPressed:!1,vigemBusInstallStatus:null,vigemBusInstallError:null,currentLogIndex:-1,logLines:[]}},computed:{actualLogs(){if(!this.logFilter)return this.logs;const e=this.logFilter.toLowerCase();return this.logs.split(`
`).filter(t=>t.toLowerCase().includes(e)).join(`
`)},parsedLogEntries(){const e=this.actualLogs||"",t=/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\]:/g,n=[],s=Array.from(e.matchAll(t));if(s.length===0){const r=e.trimEnd();return r?[{index:0,raw:r,level:"Info",cssClass:"log-line-info"}]:[]}for(let r=0;r<s.length;r++){const c=s[r].index,u=r+1<s.length?s[r+1].index:e.length,l=e.slice(c,u).trimEnd();if(!l)continue;let a="Info",h="log-line-info";/\]:\s*Fatal:/i.test(l)?(a="Fatal",h="log-line-fatal"):/\]:\s*(Error|Critical):/i.test(l)?(a="Error",h="log-line-error"):/\]:\s*Warning:/i.test(l)?(a="Warning",h="log-line-warning"):/\]:\s*Debug:/i.test(l)&&(a="Debug",h="log-line-debug"),n.push({index:n.length,raw:l,level:a,cssClass:h})}return n},highlightedLogs(){const e=t=>t.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#39;");return this.parsedLogEntries.map(t=>{const n=e(t.raw),r=t.index===this.currentLogIndex?" log-entry-selected":"";return`<span data-entry-index="${t.index}" data-log-level="${t.cssClass}" class="${t.cssClass}${r}">${n}</span>`}).join(`
`)},errorWarningEntries(){return this.parsedLogEntries.filter(e=>e.level==="Warning"||e.level==="Error"||e.level==="Fatal").map(e=>e.index)},hasNextLog(){const e=this.errorWarningEntries;return e.length===0?!1:this.currentLogIndex===-1?!0:e.some(t=>t>this.currentLogIndex)},hasPrevLog(){const e=this.errorWarningEntries;return e.length===0||this.currentLogIndex===-1?!1:e.some(t=>t<this.currentLogIndex)}},created(){this._logsCopyTimeout=null,fetch("/api/config").then(e=>e.json()).then(e=>{this.platform=e.platform,this.controllerEnabled=e.controller!=="disabled",this.platform==="windows"&&this.controllerEnabled&&this.refreshViGEmBusStatus()}),this.logInterval=setInterval(()=>{this.refreshLogs()},5e3),this.refreshLogs(),this.refreshClients()},beforeDestroy(){clearInterval(this.logInterval)},methods:{refreshLogs(){fetch("./api/logs").then(e=>e.text()).then(e=>{this.logs=e})},closeApp(){this.closeAppPressed=!0,o("./api/apps/close",{method:"POST",headers:{"Content-Type":"application/json"}}).then(e=>e.json()).then(e=>{this.closeAppPressed=!1,this.closeAppStatus=e.status,setTimeout(()=>{this.closeAppStatus=null},5e3)})},unpairAll(){this.unpairAllPressed=!0,o("./api/clients/unpair-all",{method:"POST",headers:{"Content-Type":"application/json"}}).then(e=>e.json()).then(e=>{this.unpairAllPressed=!1,this.unpairAllStatus=e.status,setTimeout(()=>{this.unpairAllStatus=null},5e3),this.refreshClients()})},unpairSingle(e){o("./api/clients/unpair",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({uuid:e})}).then(()=>{this.showApplyMessage=!0,this.refreshClients()})},toggleClient(e,t){fetch("./api/clients/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({uuid:e,enabled:t})}).then(()=>{this.refreshClients()})},refreshClients(){fetch("./api/clients/list").then(e=>e.json()).then(e=>{document.querySelector("#client-list"),e.status===!0&&e.named_certs&&e.named_certs.length?this.clients=e.named_certs.sort((t,n)=>t.name.toLowerCase()>n.name.toLowerCase()||t.name===""?1:-1):this.clients=[]})},clickedApplyBanner(){this.showApplyMessage=!1},copyLogs(){navigator.clipboard.writeText(this.actualLogs).then(()=>{this._logsCopyTimeout&&clearTimeout(this._logsCopyTimeout),this.logsCopied=!0,this._logsCopyTimeout=setTimeout(()=>{this.logsCopied=!1},2e3)}).catch(e=>{console.error("Failed to copy logs:",e)})},restart(){this.restartPressed=!0,setTimeout(()=>{this.restartPressed=!1},5e3),o("./api/restart",{method:"POST",headers:{"Content-Type":"application/json"}})},ddResetPersistence(){this.ddResetPressed=!0,o("/api/reset-display-device-persistence",{method:"POST",headers:{"Content-Type":"application/json"}}).then(e=>e.json()).then(e=>{this.ddResetPressed=!1,this.ddResetStatus=e.status,setTimeout(()=>{this.ddResetStatus=null},5e3)})},refreshViGEmBusStatus(){fetch("/api/vigembus/status").then(e=>e.json()).then(e=>{this.vigembus={installed:e.installed||!1,version:e.version||"",version_compatible:e.version_compatible||!1,packaged_version:e.packaged_version}}).catch(e=>{console.error("Failed to fetch ViGEmBus status:",e)})},installViGEmBus(){this.vigemBusInstallPressed=!0,this.vigemBusInstallStatus=null,this.vigemBusInstallError=null,o("/api/vigembus/install",{method:"POST",headers:{"Content-Type":"application/json"}}).then(e=>e.json()).then(e=>{this.vigemBusInstallPressed=!1,this.vigemBusInstallStatus=e.status,!e.status&&e.error&&(this.vigemBusInstallError=e.error),setTimeout(()=>{this.vigemBusInstallStatus=null,this.vigemBusInstallError=null},1e4),this.refreshViGEmBusStatus()}).catch(e=>{this.vigemBusInstallPressed=!1,this.vigemBusInstallStatus=!1,this.vigemBusInstallError=e.message,setTimeout(()=>{this.vigemBusInstallStatus=null,this.vigemBusInstallError=null},1e4)})},navigateToLog(e){const t=this.errorWarningEntries;if(t.length===0)return;let n;if(e==="next")if(this.currentLogIndex===-1)n=t[0];else{const s=t.filter(r=>r>this.currentLogIndex);if(s.length===0)return;n=s[0]}else if(e==="prev"){if(this.currentLogIndex===-1)return;const s=t.filter(r=>r<this.currentLogIndex);if(s.length===0)return;n=s[s.length-1]}else return;this.currentLogIndex=n,this.$nextTick(()=>{const s=this.$refs.logsContainer;if(!s)return;const r=s.querySelector(`[data-entry-index="${n}"]`);if(!r)return;const c=s.getBoundingClientRect(),l=r.getBoundingClientRect().top-c.top;s.scrollTop=s.scrollTop+l-c.height*.15})},scrollLogsTo(e){const t=this.$refs.logsContainer;if(t){if(this.currentLogIndex=-1,e==="top"){t.scrollTo({top:0,behavior:"smooth"});return}e==="bottom"&&t.scrollTo({top:t.scrollHeight,behavior:"smooth"})}}}});p(k);
