import{i as A,u as M,q as f,x as S,aj as $,c as p,A as V,b as r,p as o,F as g,a as s,w as v,al as F,aB as k,ak as K,o as u,am as L,n as P,a0 as N,O as z}from"./entry-25c4be3.js";import{g as I,e as T,o as j,i as E,_ as h,j as D,d as H,k as Y}from"./passwordModalStore-25c4be3.js";const x=""+new URL("locked-bar-25c4be3.png",import.meta.url).href,_=""+new URL("connect-cable-25c4be3.png",import.meta.url).href,R={"data-id":"page-login",class:"w-full min-h-[calc(100vh-2rem)] flex flex-col items-center justify-center gap-6"},W={class:"w-full flex flex-col items-center gap-2"},q={class:"flex justify-end"},Q=A({__name:"login",setup(G){M({title:"🔒 BUSY Bar Virtual LAN",meta:[{name:"description",content:"[Locked] Control your BUSY Bar in the browser"}]});const t=I(),a=T(),l=j(),y=f(!0),i=f(!1),d=f(!1);async function b(){if(!i.value){i.value=!0;try{l.apiKey=t.passwordModel.current,a.busyBar.setApiKey(l.apiKey),await a.fetchDeviceName(!0),await k("/",{external:!0})}catch(w){w?.status===403?(l.apiKey=null,t.passwordModel.current="",t.passwordModel.currentWrong=!0):await E(w,"Failed to unlock Virtual LAN")}i.value=!1}}async function m(){l.apiKey&&a.busyBar.setApiKey(l.apiKey);try{await a.fetchDeviceName(!0),await k("/")}catch{await a.fetchHttpAPIAccess()}setTimeout(()=>{y.value=!1},500)}return S(async()=>{await m(),window.addEventListener("device-reconnected",m)}),$(()=>window.removeEventListener("device-reconnected",m)),(w,e)=>{const c=K,B=H,U=h,C=D;return u(),p("div",R,[o(y)?V("",!0):(u(),p(g,{key:0},[o(a).httpAPIAccess?.mode==="disabled"?(u(),p(g,{key:0},[e[8]||(e[8]=s("div",{class:"text-xl font-medium"},"HTTP API disabled over Wi-Fi",-1)),e[9]||(e[9]=s("img",{src:x,class:"w-[300px] my-4"},null,-1))],64)):(u(),p(g,{key:1},[e[10]||(e[10]=s("div",{class:"text-xl font-medium"},"Virtual LAN is locked",-1)),e[11]||(e[11]=s("img",{src:x,class:"w-[328px] mb-4 mt-2"},null,-1)),e[12]||(e[12]=s("div",null,"Enter your password to unlock",-1)),r(U,{class:"w-full",error:o(t).currentPasswordValidation},{default:v(()=>[L((u(),P(B,{modelValue:o(t).passwordModel.current,"onUpdate:modelValue":[e[1]||(e[1]=n=>o(t).passwordModel.current=n),e[2]||(e[2]=n=>o(t).passwordModel.currentWrong=!1)],name:"current-password",size:"xl",variant:"soft",type:o(t).passwordModel.showCurrent?"text":"password",placeholder:"Password",onKeyup:e[3]||(e[3]=N(n=>o(i)?null:b(),["enter"]))},{trailing:v(()=>[r(c,{icon:o(t).passwordModel.showCurrent?"i-bi-eye":"i-bi-eye-shut",variant:"ghost",color:"neutral",square:"",class:"rounded-full",ui:{leadingIcon:"size-6 text-muted"},onClick:e[0]||(e[0]=n=>o(t).passwordModel.showCurrent=!o(t).passwordModel.showCurrent)},null,8,["icon"])]),_:1},8,["modelValue","type"])),[[o(Y),"##########"]])]),_:1},8,["error"]),s("div",W,[r(c,{"data-id":"page-login-unlock-button",label:"Unlock",color:"neutral",size:"lg",block:"",loading:o(i),onClick:e[4]||(e[4]=n=>b())},null,8,["loading"]),r(c,{"data-id":"page-login-forgot-password-button",label:"Forgot password?",color:"neutral",variant:"ghost",size:"lg",block:"",onClick:e[5]||(e[5]=n=>d.value=!0)})])],64))],64)),r(C,{open:o(d),"onUpdate:open":e[7]||(e[7]=n=>F(d)?d.value=n:null),"data-id":"modal-forgot-password",title:"Forgot your password?",description:"A forgotten password cannot be recovered but only reset using a wired connection. Connect your BUSY Bar with a USB cable to reset the password. ",ui:{description:"hidden",header:"hidden",body:"p-0 sm:p-0 overflow-visible",close:"hidden"}},{body:v(()=>[s("div",{class:"flex flex-col gap-6 p-6 bg-no-repeat",style:z(`background-image: url(${o(_)}); background-size: 150%; background-position: center`)},[e[13]||(e[13]=s("div",{class:"text-xl font-medium"},"Forgot your password?",-1)),e[14]||(e[14]=s("div",{class:"h-50"},null,-1)),e[15]||(e[15]=s("div",{class:"text-center"},"A forgotten password cannot be recovered but only reset using a wired connection. Connect your BUSY Bar with a USB cable to reset the password.",-1)),s("div",q,[r(c,{color:"neutral",label:"Got it",size:"lg",class:"min-w-20 justify-center",onClick:e[6]||(e[6]=n=>d.value=!1)})])],4)]),_:1},8,["open"])])}}});export{Q as default};
