import{r as e}from"./nc-main-C6OeyNBF.js";import{computed as t,createBlock as n,createTextVNode as r,createVNode as i,inject as a,onMounted as o,openBlock as s,ref as c,resolveComponent as l,toDisplayString as u,unref as d,watch as f,withCtx as p}from"/vue.js";var m=Object.assign({name:`NcLogin`},{__name:`nc-login`,setup(m){let h=a(`state`),g=h.rec,_=h.hdr,v=c(!1);g.logged_in=e.loggedIn();let y=c(e.loggedInInfo()),b=!1,x=c(!1),S=c(!1),C=c(_.login.biometric_button),w=c([]);c(!1);let T=c(``),E=t(()=>v.value===!0||h.rec&&h.rec.login_id&&h.rec.password&&h.rec.organization_id);async function D(){if(b=e.isWebauthnSupported(),b)try{if(x.value=await e.supportBiometrics(),x.value){let e=navigator.platform.toLowerCase();e.includes(`iphone`)||e.includes(`ipad`)?C.value=_.login.biometric_button_ios:e.includes(`mac`)?C.value=_.login.biometric_button_mac:e.includes(`win`)?C.value=_.login.biometric_button_windows:C.value=_.login.biometric_button}}catch(e){console.warn(`Failed to check biometric support:`,e)}}function O(e){e.getModifierState&&e.getModifierState(`CapsLock`)}function k(){let e=document.getElementById(`login_pw`);e&&e.addEventListener(`keydown`,O),e=document.getElementById(`login_id`),e?e.addEventListener(`animationstart`,()=>{v.value=!0}):setTimeout(()=>{k()},20)}o(()=>{k(),D(),setTimeout(()=>{M()},100)});function A(){let e=navigator.userAgent,t=navigator.platform.toLowerCase(),n=`Device`;t.includes(`iphone`)||e.includes(`iPhone`)?n=`iPhone`:t.includes(`ipad`)||e.includes(`iPad`)?n=`iPad`:t.includes(`mac`)?n=`Mac`:t.includes(`win`)?n=`Windows PC`:t.includes(`linux`)?n=`Linux PC`:e.includes(`Android`)&&(n=`Android`);let r=``;e.includes(`Chrome`)&&!e.includes(`Edg`)?r=`Chrome`:e.includes(`Firefox`)?r=`Firefox`:e.includes(`Safari`)&&!e.includes(`Chrome`)?r=`Safari`:e.includes(`Edg`)&&(r=`Edge`);let i=r?`${n} (${r})`:n;T.value=i,(!g.device_name||g.device_name.trim()===``)&&(g.device_name=i)}f(()=>g.login_id,()=>{P(),A()});let j=!1;function M(){if(j)return;j=!0;let e=document.getElementById(`login_id`);e&&e.focus()}function N(){e.logout(()=>{g.logged_in=e.loggedIn(),g.is_designer=e.isDesigner(),y.value=e.loggedInInfo()}),g.login_id=``,g.password=``}function P(){if(g.login_id&&b){let t={organization_id:g.organization_id,login_id:g.login_id,password:g.password};e.getPasskeyList(t,e=>{!e.error&&e.data?(S.value=e.data.length>0,w.value=e.data):(S.value=!1,w.value=[])})}}function F(){if(!E.value){console.debug(`🚀 *** login cancelled ~ login_id: ${h.rec.login_id}, password empty: ${h.rec.password!=``}, organization_id: ${h.rec.organization_id}`);return}let t={organization_id:g.organization_id,login_id:g.login_id,password:g.password};e.login(t,t=>{g.logged_in=e.loggedIn(),g.logged_in&&(g.password=``),g.is_designer=e.isDesigner(),console.debug(`login() callback, logged in: ${g.logged_in}`),!t.error&&t.status===`ok`&&(g.login_id=``),y.value=e.loggedInInfo()})}return(e,t)=>{let a=l(`nc-header`),o=l(`nc-row`),c=l(`nc-translate`),f=l(`nc-button`),m=l(`nc-form`),h=l(`nc-label-dropdown`),_=l(`nc-form-field`),v=l(`nc-label-input`),b=l(`nc-col`);return d(g).logged_in?(s(),n(m,{key:0},{default:p(()=>[i(o,{class:`nc-center-h nc-margin-top`},{default:p(()=>[i(a,{size:`medium`,model:``,style:{color:`grey`}},{default:p(()=>[r(u(d(y)),1)]),_:1})]),_:1}),i(o,{class:`nc-center-h nc-margin-top`},{default:p(()=>[i(f,{onClick:N},{default:p(()=>[i(c,{model:`hdr.login.logout`},{default:p(()=>[...t[0]||(t[0]=[r(`Logout`,-1)])]),_:1})]),_:1})]),_:1})]),_:1})):(s(),n(m,{key:1,id:`nc-login`,onKeyup:M},{default:p(()=>[i(_,null,{default:p(()=>[i(h,{horizontal:!1,hdr:`hdr.login.organization`,model:`rec.organization_id`,placeholder:`Organisaatio`},{default:p(()=>[...t[1]||(t[1]=[r(`Organization`,-1)])]),_:1})]),_:1}),i(_,null,{default:p(()=>[i(v,{class:`nc-autofill`,id:`login_id`,horizontal:!1,name:`login_id`,hdr:`hdr.login.login_id`,model:`rec.login_id`,autocomplete:`username`},{default:p(()=>[...t[2]||(t[2]=[r(`Login id`,-1)])]),_:1})]),_:1}),i(_,null,{default:p(()=>[i(v,{class:`nc-autofill`,id:`login_pw`,horizontal:!1,name:`login_pw`,hdr:`hdr.login.password`,model:`rec.password`,type:`password`,autocomplete:`current-password`},{default:p(()=>[...t[3]||(t[3]=[r(`Password`,-1)])]),_:1})]),_:1}),i(o,{class:`nc-end-h`},{default:p(()=>[i(b,{class:`nc-end-h`},{default:p(()=>[i(f,{class:`primary nc-button-wide`,id:`loginButton`,disabled:!d(E),type:`submit`,onClick:F},{default:p(()=>[i(c,{model:`hdr.login.login`},{default:p(()=>[...t[4]||(t[4]=[r(`Login`,-1)])]),_:1})]),_:1},8,[`disabled`])]),_:1})]),_:1})]),_:1}))}}});export{m as default};