import{k as r}from"./p-a7fc1e02.js";import{L as o,v as a}from"./p-d0993bb9.js";import{j as t}from"./p-e7e129ac.js";import{u as i}from"./p-e00ec007.js";function n(n){const e=o(),l=new URLSearchParams(window.location.search),s=null==l?void 0:l.get("_saasquatch"),{registrationFormState:c,setRegistrationFormState:d}=i(),[m,{loading:u}]=a(),[f,v]=r("");return{states:{loading:u,error:null==c?void 0:c.error,registrationFormState:c},callbacks:{submit:async r=>{var o;v("");let a=r.target.getFormControls(),i=r.detail.formData,l={};null==a||a.map((r=>{if(!r.name)return;const o=r.name,a=r.value;if(t.set(i,o,a),r.required&&!a&&t.set(l,o,n.requiredFieldErrorMessage),"function"==typeof r.validationError){const i=(0,r.validationError)({control:r,key:o,value:a});i&&t.set(l,o,i)}}));const u={firstName:i.firstName,lastName:i.lastName,email:i.email,locale:e,...(null==n?void 0:n.includeCookies)&&s?{cookies:s}:{}};try{const r=await m(u);if(r instanceof Error)throw r;d({...c,loading:!1,error:"",validationErrors:{}})}catch(r){(null===(o=null==r?void 0:r.message)||void 0===o?void 0:o.includes("is not valid"))?d({...c,loading:!1,error:"",validationErrors:{email:n.invalidEmailErrorMessage}}):d("fraud_error"===(null==r?void 0:r.name)?{...c,loading:!1,error:"FRAUD"}:{...c,loading:!1,error:n.networkErrorMessage,validationErrors:{}})}}}}}export{n as u}