import{a7 as e,aV as a,aL as s,aX as l,aP as t,a as o,Q as n,T as r,g as i,bw as u,a2 as c,h as d,o as m,Y as g,a4 as f,a5 as p,Z as b,a0 as v,u as y}from"./index.3938ccd1.js";import{Q as S}from"./QPage.62812de7.js";import{u as h}from"./use-quasar.63a27b45.js";import{user as w,getModbusRegisterSettings as j}from"./common.0a9f0488.js";import{a as k}from"./api.bf47c78e.js";import"./index.d11c4764.js";var x=e({name:"QInnerLoading",props:{...a,...s,showing:Boolean,color:String,size:{type:[String,Number],default:"42px"},label:String,labelClass:String,labelStyle:[String,Array,Object]},setup(e,{slots:a}){const s=i(),c=l(e,s.proxy.$q),{transitionProps:d,transitionStyle:m}=t(e),g=o((()=>"q-inner-loading q--avoid-card-border absolute-full column flex-center"+(!0===c.value?" q-inner-loading--dark":""))),f=o((()=>"q-inner-loading__label"+(void 0!==e.labelClass?` ${e.labelClass}`:"")));function p(){return!0===e.showing?n("div",{class:g.value,style:m.value},void 0!==a.default?a.default():function(){const a=[n(u,{size:e.size,color:e.color})];return void 0!==e.label&&a.push(n("div",{class:f.value,style:e.labelStyle},[e.label])),a}()):null}return()=>n(r,d.value,p)}});const _={key:1},q={__name:"LoginPage",setup(e){const a=c(),s=h(),l=d(null),t=d(!1);return m((()=>{new WebSocket({}.API_WS_URL).onmessage=({data:e})=>{var o;if("hello"===(e=JSON.parse(e)).type){l.value=e.cid;const a={}.API_URL+"/login?cid="+l.value;k.post("login",{json:{url:a}})}else if("token"===e.type){t.value=!0,w.value=e.user,localStorage.setItem("user",JSON.stringify(w.value)),k.post("user",{json:{token:e.token,id:e.user.id,name:e.user.name}}),s.cookies.set("token",e.token,{expires:360,sameSite:"Strict",secure:!0}),"OFFLINE"===(null==(o=j())?void 0:o.syncData)&&s.notify({message:"Offline mode enabled, data will not be synced, you can change that from settings.",color:"warning",timeout:0,actions:[{label:"Dismiss",color:"white",handler:()=>{}}]});const l=a.currentRoute.value.query.redirect||"/apps-library";a.replace({path:l})}}})),(e,a)=>(g(),f(S,{class:"flex items-center justify-center"},{default:p((()=>[t.value?(g(),b("div",_,"Logged in as "+v(y(w).name),1)):(g(),f(x,{key:0,showing:!0,label:"Waiting for the login in the browser window...","label-class":"text-teal","label-style":"font-size: 1.1em"}))])),_:1}))}};export{q as default};
