var __assign=this&&this.__assign||function(){__assign=Object.assign||function(r){for(var e,t=1,a=arguments.length;t<a;t++){e=arguments[t];for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n))r[n]=e[n]}return r};return __assign.apply(this,arguments)};var __awaiter=this&&this.__awaiter||function(r,e,t,a){function n(r){return r instanceof t?r:new t((function(e){e(r)}))}return new(t||(t=Promise))((function(t,o){function i(r){try{l(a.next(r))}catch(r){o(r)}}function s(r){try{l(a["throw"](r))}catch(r){o(r)}}function l(r){r.done?t(r.value):n(r.value).then(i,s)}l((a=a.apply(r,e||[])).next())}))};var __generator=this&&this.__generator||function(r,e){var t={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},a,n,o,i;return i={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(i[Symbol.iterator]=function(){return this}),i;function s(r){return function(e){return l([r,e])}}function l(i){if(a)throw new TypeError("Generator is already executing.");while(t)try{if(a=1,n&&(o=i[0]&2?n["return"]:i[0]?n["throw"]||((o=n["return"])&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;if(n=0,o)i=[i[0]&2,o.value];switch(i[0]){case 0:case 1:o=i;break;case 4:t.label++;return{value:i[1],done:false};case 5:t.label++;n=i[1];i=[0];continue;case 7:i=t.ops.pop();t.trys.pop();continue;default:if(!(o=t.trys,o=o.length>0&&o[o.length-1])&&(i[0]===6||i[0]===2)){t=0;continue}if(i[0]===3&&(!o||i[1]>o[0]&&i[1]<o[3])){t.label=i[1];break}if(i[0]===6&&t.label<o[1]){t.label=o[1];o=i;break}if(o&&t.label<o[2]){t.label=o[2];t.ops.push(i);break}if(o[2])t.ops.pop();t.trys.pop();continue}i=e.call(r,t)}catch(r){i=[6,r];n=0}finally{a=o=0}if(i[0]&5)throw i[1];return{value:i[0]?i[1]:void 0,done:true}}};import{k as useState}from"./dom-context-hooks.module-50442785.js";import{L,v as vn}from"./index.module-b23fdad8.js";import{j as jsonpointer}from"./jsonpointer-388a7082.js";import{u as useRegistrationFormState}from"./useRegistrationFormState-2c090c38.js";function useInstantAccessRegistration(r){var e=this;var t=L();var a=new URLSearchParams(window.location.search);var n=a===null||a===void 0?void 0:a.get("_saasquatch");var o=useRegistrationFormState(),i=o.registrationFormState,s=o.setRegistrationFormState;var l=vn(),u=l[0],c=l[1],f=c.loading,v=c.errors,d=c.data;var g=useState(""),_=g[0],m=g[1];var p=function(a){return __awaiter(e,void 0,void 0,(function(){var e,o,l,c,f,v,d;return __generator(this,(function(g){switch(g.label){case 0:m("");o=a.target.getFormControls();l=a.detail.formData;c={};o===null||o===void 0?void 0:o.map((function(e){if(!e.name)return;var t=e.name;var a=e.value;jsonpointer.set(l,t,a);if(e.required&&!a){jsonpointer.set(c,t,r.requiredFieldErrorMessage)}if(typeof e.validationError==="function"){var n=e.validationError;var o=n({control:e,key:t,value:a});if(o)jsonpointer.set(c,t,o)}}));f=__assign({firstName:l.firstName,lastName:l.lastName,email:l.email,locale:t},(r===null||r===void 0?void 0:r.includeCookies)&&n?{cookies:n}:{});g.label=1;case 1:g.trys.push([1,3,,4]);return[4,u(f)];case 2:v=g.sent();if(v instanceof Error){throw v}s(__assign(__assign({},i),{loading:false,error:"",validationErrors:{}}));return[3,4];case 3:d=g.sent();if((e=d===null||d===void 0?void 0:d.message)===null||e===void 0?void 0:e.includes("is not valid")){s(__assign(__assign({},i),{loading:false,error:"",validationErrors:{email:r.invalidEmailErrorMessage}}))}else if((d===null||d===void 0?void 0:d.name)==="fraud_error"){s(__assign(__assign({},i),{loading:false,error:"FRAUD"}))}else{s(__assign(__assign({},i),{loading:false,error:r.networkErrorMessage,validationErrors:{}}))}return[3,4];case 4:return[2]}}))}))};return{states:{loading:f,error:i===null||i===void 0?void 0:i.error,registrationFormState:i},callbacks:{submit:p}}}export{useInstantAccessRegistration as u};