import{c as e,s as t,u as n}from"./logo-sunshine-45-B0-ae2pw.js";import{t as r}from"./Navbar-chCsCvbA.js";import{t as i}from"./monitor-DmWyPDob.js";import{t as a}from"./x-CpWEt1F2.js";import{t as o}from"./fetch_utils-4pUjSOEQ.js";var s=t(`forward`,[[`path`,{d:`m15 17 5-5-5-5`,key:`nf172w`}],[`path`,{d:`M4 18v-2a4 4 0 0 1 4-4h12`,key:`jmiej9`}]]),c=t(`hash`,[[`line`,{x1:`4`,x2:`20`,y1:`9`,y2:`9`,key:`4lhtct`}],[`line`,{x1:`4`,x2:`20`,y1:`15`,y2:`15`,key:`vyu0kd`}],[`line`,{x1:`10`,x2:`8`,y1:`3`,y2:`21`,key:`1ggp8o`}],[`line`,{x1:`16`,x2:`14`,y1:`3`,y2:`21`,key:`weycgp`}]]),l=t(`user-round-search`,[[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M2 21a8 8 0 0 1 10.434-7.62`,key:`1yezr2`}],[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`path`,{d:`m22 22-1.9-1.9`,key:`1e5ubv`}]]),u=n({components:{Navbar:r,Forward:s,Hash:c,Monitor:i,UserRoundSearch:l,X:a},inject:[`i18n`],data(){return{name:``,pendingPairings:[],pin:``,refreshTimer:null,selectedPairingId:``,status:null}},mounted(){this.loadPendingPairings(),this.refreshTimer=window.setInterval(()=>this.loadPendingPairings(),2e3)},beforeUnmount(){window.clearInterval(this.refreshTimer)},methods:{async loadPendingPairings(){try{let e=await o(`./api/pin`,{method:`GET`});if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();this.pendingPairings=t.pairings||[],this.pendingPairings.some(e=>e.id===this.selectedPairingId)||(this.selectedPairingId=this.pendingPairings.length===1?this.pendingPairings[0].id:``)}catch(e){console.error(`Failed to load pending pairing requests`,e),this.status={type:`danger`,message:this.i18n.t(`pin.load_failure`)}}},async registerDevice(){if(this.status=null,!this.selectedPairingId){this.status={type:`danger`,message:this.i18n.t(`pin.select_pairing_required`)};return}let e=JSON.stringify({pairing_id:this.selectedPairingId,pin:this.pin,name:this.name});(await(await o(`./api/pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:e})).json()).status===!0?(this.status={type:`success`,message:this.i18n.t(`pin.pair_success`)},this.pin=``,this.name=``):this.status={type:`danger`,message:this.i18n.t(`pin.pair_failure`)},await this.loadPendingPairings()},async cancelSelectedPairing(){if(!this.selectedPairingId)return;let e=await(await o(`./api/pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pairing_id:this.selectedPairingId})})).json();this.status=e.status===!0?{type:`success`,message:this.i18n.t(`pin.cancel_success`)}:{type:`danger`,message:this.i18n.t(`pin.cancel_failure`)},await this.loadPendingPairings()}}});e(u);