(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[863],{954:(e,t,s)=>{"use strict";s.d(t,{c:()=>l});var n=s(3119);class l{connect(){this.closed||(this.ws=new WebSocket(this.url),this.ws.onopen=()=>{this.retry=0,this.emit("open",null)},this.ws.onmessage=e=>{try{let t=JSON.parse(e.data);"string"==typeof t.type&&this.emit(t.type,t)}catch(e){}},this.ws.onclose=()=>{this.emit("close",null),this.closed||setTimeout(()=>this.connect(),Math.min(3e4,500*Math.pow(2,this.retry++)))},this.ws.onerror=()=>this.emit("error",null))}send(e){var t;(null==(t=this.ws)?void 0:t.readyState)===WebSocket.OPEN&&this.ws.send(JSON.stringify(e))}on(e,t){let s=this.handlers.get(e);return s||(s=new Set,this.handlers.set(e,s)),s.add(t),()=>null==s?void 0:s.delete(t)}close(){var e;this.closed=!0,null==(e=this.ws)||e.close(),this.ws=null}emit(e,t){let s=this.handlers.get(e);null==s||s.forEach(e=>e(t))}constructor(e){this.ws=null,this.handlers=new Map,this.retry=0,this.closed=!1;let t=(0,n.yq)("/ws");this.url=e?"".concat(t,"?sessionId=").concat(encodeURIComponent(e)):t}}},3119:(e,t,s)=>{"use strict";s.d(t,{hI:()=>i,yq:()=>o});var n,l,r,a,c=s(5704);let i={controlPlaneUrl:null!=(n=c.env.NEXT_PUBLIC_CONTROL_PLANE_URL)?n:"http://localhost:8080",serverCoreUrl:null!=(l=c.env.NEXT_PUBLIC_SERVER_CORE_URL)?l:"http://localhost:4533",r2Url:null!=(r=c.env.NEXT_PUBLIC_R2_URL)?r:"https://pub-8c12e933ae274e2d8176d39ee91fa8c3.r2.dev",latestVersion:null!=(a=c.env.NEXT_PUBLIC_LATEST_VERSION)?a:"latest"};function o(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/ws",t=new URL(i.controlPlaneUrl);return t.protocol="https:"===t.protocol?"wss:":"ws:",t.pathname=e,t.toString()}},6372:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>u});var n=s(5155),l=s(2115),r=s(63),a=s(2834),c=s(3119),i=s(954),o=s(8497);function u(){let e=(0,r.useRouter)(),t=(0,o.w)(e=>e.setSession),[s,u]=(0,l.useState)(null),[h,d]=(0,l.useState)(null),[m]=(0,l.useState)(()=>"web-"+Math.random().toString(36).slice(2,12));return(0,l.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await fetch("".concat(c.hI.controlPlaneUrl,"/auth/device"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:m})});if(!t.ok)throw Error("start failed");let s=await t.json();e||u(s)}catch(t){e||d(t.message)}})(),()=>{e=!0}},[m]),(0,l.useEffect)(()=>{if(!s)return;let n=new i.c(m),l=n.on("auth_granted",s=>{t(s.access_token,m),e.push("/control")});return n.connect(),()=>{l(),n.close()}},[s,m,t,e]),(0,l.useEffect)(()=>{if(!s)return;let n=null,l=!1,r=async()=>{if(!l){try{let n=await fetch("".concat(c.hI.controlPlaneUrl,"/auth/device/token"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:s.device_code})});if(n.ok){let s=await n.json();t(s.access_token,m),e.push("/control");return}let l=await n.json();if(l.error&&"authorization_pending"!==l.error)return void d(l.error)}catch(e){d(e.message)}n=setTimeout(r,1e3*s.interval)}};return n=setTimeout(r,1e3*s.interval),()=>{l=!0,n&&clearTimeout(n)}},[s,e,m,t]),(0,n.jsx)("main",{className:"min-h-screen grid place-items-center px-6",children:(0,n.jsxs)("div",{className:"max-w-md w-full text-center space-y-6",children:[(0,n.jsxs)("h1",{className:"text-2xl font-light",children:["Parear ",(0,n.jsx)("span",{className:"text-accent",children:"esta tela"})]}),h&&(0,n.jsxs)("p",{className:"text-red-400",children:["Erro: ",h]}),!s&&!h&&(0,n.jsx)("p",{className:"text-muted",children:"Gerando codigo..."}),s&&(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsx)("div",{className:"bg-white p-4 rounded-xl inline-block",children:(0,n.jsx)(a.h,{value:s.verification_uri_complete,size:240,level:"M"})}),(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)("p",{className:"text-muted text-sm",children:"Escaneie com o celular ou abra:"}),(0,n.jsx)("p",{className:"font-mono text-sm break-all",children:s.verification_uri_complete})]}),(0,n.jsx)("div",{className:"text-3xl font-mono tracking-[0.4em] text-accent","data-testid":"user-code",children:s.user_code})]})]})})}},8497:(e,t,s)=>{"use strict";s.d(t,{F:()=>l,w:()=>r});var n=s(5988);let l=(0,n.vt)(e=>({isPlaying:!1,currentTrack:null,queue:[],volume:.7,setPlaying:t=>e({isPlaying:t}),setCurrent:t=>e({currentTrack:t}),setCurrentTrack:t=>e({currentTrack:t}),setQueue:t=>e({queue:t}),setVolume:t=>e({volume:Math.max(0,Math.min(1,t))})})),r=(0,n.vt)(e=>({accessToken:null,sessionId:null,setSession:(t,s)=>e({accessToken:t,sessionId:s}),clear:()=>e({accessToken:null,sessionId:null})}))},9204:(e,t,s)=>{Promise.resolve().then(s.bind(s,6372))}},e=>{e.O(0,[240,441,255,358],()=>e(e.s=9204)),_N_E=e.O()}]);