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,openBlock as o,resolveComponent as s,unref as c,withCtx as l}from"/vue.js";var u=Object.assign({name:`nc-register`},{__name:`nc-register`,setup(u){let d=a(`state`),f=d.rec;f.logged_in=e.loggedIn();let p=e.isWebauthnSupported();function m(){return/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(.\w{2,3})+$/.test(f.email)}let h=t(()=>{let e=d.rec&&d.rec.login_id&&d.rec.password&&d.rec.organization_id&&d.rec.password===d.rec.password2&&m();return d.rec.create_passkey?e&&d.rec.device_name&&d.rec.device_name.length>=3:e});function g(){if(!h.value){console.debug(`🚀 *** register cancelled ~ login_id: ${d.rec.login_id}, password empty: ${d.rec.password!=``}, organization_id: ${d.rec.organization_id}`);return}let t={organization_id:f.organization_id,login_id:f.login_id,full_name:f.full_name,password:f.password,email:f.email,note:f.note};f.create_passkey&&p&&(t.create_passkey=!0,t.device_name=f.device_name),e.register(t,t=>{if(f.logged_in=e.loggedIn(),f.is_designer=e.isDesigner(),console.debug(`register() callback, logged in: ${f.logged_in}`),!t.error&&t.status===`ok`){if(f.create_passkey&&t.passkeyRegistration){let t={username:f.login_id,displayName:f.full_name||f.login_id,device_name:f.device_name};e.registerPasskey(t,e=>{e.error?console.error(`Passkey creation failed:`,e.error):console.log(`Passkey created successfully`)})}f.login_id=``,f.full_name=``,f.email=``,f.password=``,f.password2=``,f.note=``,f.create_passkey=!1,f.device_name=``}}),f.password=``,f.password2=``}return(e,t)=>{let a=s(`nc-label-dropdown`),u=s(`nc-form-field`),d=s(`nc-label-input`),p=s(`nc-label-textarea`),_=s(`nc-translate`),v=s(`nc-button`),y=s(`nc-row`),b=s(`nc-form`);return o(),n(b,{id:`nc-register`},{default:l(()=>[i(u,null,{default:l(()=>[i(a,{hdr:`hdr.login.organization`,model:`rec.organization_id`,placeholder:`Organization`},{default:l(()=>[...t[0]||(t[0]=[r(`Organization`,-1)])]),_:1})]),_:1}),i(u,null,{default:l(()=>[i(d,{horizontal:!1,hdr:`hdr.login.login_id`,model:`rec.login_id`,placeholder:`Login id, minimum 6 characters.`,autocomplete:`username`,"input-class":c(f).login_id&&c(f).login_id.length>=6?``:`nc-register-invalid`},{default:l(()=>[...t[1]||(t[1]=[r(`Login id`,-1)])]),_:1},8,[`input-class`])]),_:1}),i(u,null,{default:l(()=>[i(d,{horizontal:!1,hdr:`hdr.login.email`,model:`rec.email`,placeholder:`Valid email address.`,autocomplete:`email`,"input-class":m()?``:`nc-register-invalid`},{default:l(()=>[...t[2]||(t[2]=[r(`Email`,-1)])]),_:1},8,[`input-class`])]),_:1}),i(u,null,{default:l(()=>[i(d,{horizontal:!1,hdr:`hdr.login.full_name`,model:`rec.full_name`,placeholder:`Full name, minimum 6 characters.`,autocomplete:`email`,"input-class":c(f).full_name&&c(f).full_name.length>=6?``:`nc-register-invalid`},{default:l(()=>[...t[3]||(t[3]=[r(`Full name`,-1)])]),_:1},8,[`input-class`])]),_:1}),i(u,null,{default:l(()=>[i(d,{horizontal:!1,hdr:`hdr.login.password`,model:`rec.password`,type:`password`,placeholder:`Password, minimum 6 characters.`,autocomplete:`current-password`,"input-class":c(f).password===c(f).password2?``:`nc-register-invalid`},{default:l(()=>[...t[4]||(t[4]=[r(`Password`,-1)])]),_:1},8,[`input-class`])]),_:1}),i(u,null,{default:l(()=>[i(d,{horizontal:!1,hdr:`hdr.login.password2`,model:`rec.password2`,type:`password`,placeholder:`Same password again, passwords must match.`,autocomplete:`current-password`,"input-class":c(f).password===c(f).password2?``:`nc-register-invalid`},{default:l(()=>[...t[5]||(t[5]=[r(`Password again`,-1)])]),_:1},8,[`input-class`])]),_:1}),i(u,null,{default:l(()=>[i(p,{hdr:`hdr.login.note`,model:`rec.note`},{default:l(()=>[...t[6]||(t[6]=[r(`Notes`,-1)])]),_:1})]),_:1}),i(y,{class:`nc-end-h`},{default:l(()=>[i(v,{disabled:!c(h),type:`submit`,onClick:g},{default:l(()=>[i(_,{model:`hdr.login.register`},{default:l(()=>[...t[7]||(t[7]=[r(`Register`,-1)])]),_:1})]),_:1},8,[`disabled`])]),_:1})]),_:1})}}});export{u as default};