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