/*! Optin - Wed, 16 Apr 2025 23:03:24 GMT */ "use strict";(self.webpackChunkom_api_js=self.webpackChunkom_api_js||[]).push([[18],{1845:function(t,e,i){i.r(e),i.d(e,{default:function(){return h}});var s=i(187),r=i(499),n=i(1441),o=i(5728),a=i(3824);class h{constructor(t){this.C=t,this.sendTags=!0,this.submitting=!1,this.preview=this.C.preview,this.spam=!1,this.data={referrer:window.location.href,userAgent:(0,a.getUserAgent)(),previous:(0,a.referrer)(),fields:{},tags:{},site:this.C.Sites.current().id,page:{title:document.title,url:window.location.href},dymprompted:null},this.ak=null}init(){if((0,a.trigger)(document,"Optin.init",{Optin:this,Campaign:this.C}),this.preview)return void s.A.warn("This is just a preview of the campaign and cannot be submitted.");if(this.submitting)return;if(this.C.Form.showLoad(),!this.C.Form.validate())return void this.C.Form.showValidateErrors();this.submitting=!0,this.C.options.gamified&&this.C.GamifiedWheel.spin();const t=["email","name","phone","user-segments","FieldsElement--privacyText-checkbox"],e={},i={};(0,a.each)(this.C.Form.inputs,((s,r)=>{let n=r.getAttribute("name"),o=r.getAttribute("type"),a="";if(!n)return;n=n.replace(`${this.C.ns}-`,"");const h=t.includes(n)||this.C.Form.isHoneypotField(r)?e:i;switch(o){case"checkbox":case"radio":if(r.checked)if(a=r.value.trim(),h[n])if("user-segments"===n)if("object"==typeof h[n])h[n][s]=a;else{let t=h[n];h[n]={},h[n][s-1]=t,h[n][s]=a}else Array.isArray(h[n])||(h[n]=[h[n]]),h[n].push(a);else h[n]=a;break;default:h[n]=r.value.trim()}})),this.C.Dym.hasBeenPrompted()&&(this.data.dymprompted=!0),(0,a.empty)(e)||(this.data.fields=e),(0,a.empty)(i)||(this.data.fields.meta=i),this.C.Tags.fields({...e,...i}),r.A.get("_mkto_trk")&&(this.data.mkto=r.A.get("_mkto_trk")),r.A.get("hubspotutk")&&(this.data.hutk=r.A.get("hubspotutk")),r.A.get("__ss_tk")&&(this.data.sstk=r.A.get("__ss_tk"));const o=r.A.get(/^visitor_id\d{5,8}$/m);if(o&&(this.data.pvid=o),this.sendTags&&(this.data.tags=this.C.Dtr.getCustomVariables()),(0,a.trigger)(document,"Optin.init.submit",{Optin:this,Campaign:this.C}),this.completeSubmission=!0,(0,a.trigger)(document,"Optin.init.beforeSubmission",{Optin:this,Campaign:this.C}),this.completeSubmission){let t=window[n.GLOBAL_OM].scripts.recaptcha.object;if(this.C.Form.recaptcha()&&t)return t.ready((()=>{t.execute(this.C.Sites.current().settings.recaptchaSiteKey,{action:"om_optin"}).then((t=>{this.data.recaptcha=t})).then((()=>this.post())).catch((()=>{}))}));this.post()}}post=()=>{(0,a.trigger)(document,"Optin.post",{Optin:this,Campaign:this.C});const t=(new o.A).post((0,a.getUrl)(this.C.defaults,"optin",this.C.id),this.data);this.ak&&t.setHeader("X-OptinMonster-ApiKey",this.ak),t.send().then((t=>this.success(t))).catch((t=>this.error(t)))};success=t=>{let e=JSON.parse(t.response);if(!e||(0,a.empty)(e))return e={response:{error:"An unexpected error occurred, please try again later."}},this.error(e);if(e&&e.error)return this.error(t);e&&e.errors&&s.A.error(e.errors),203===t.status&&(this.spam=!0);const i=this.C.options.gamified?this.C.GamifiedWheel.initPromise():Promise.resolve();return this.submitting=!1,(0,a.trigger)(document,"Optin.success",{Optin:this,Campaign:this.C,response:e}),this.C.cleanup(),i.then((()=>{(0,a.trigger)(this.C.Form.submit,"submit")})).catch((()=>{}))};error=t=>{const e=t.response?JSON.parse(t.response):null;let i=e?e.message||e.error:null;(0,a.trigger)(document,"Optin.error",{Optin:this,Campaign:this.C,response:i||t,responseObj:e}),this.C.Form.removeLoad(),this.C.options.gamified&&this.C.GamifiedWheel.initPromise(),this.submitting=!1,this.C.Dym.parseOptinResponse(e),this.data.dymprompted=null,this.C.Form.errors.optin=i||"An unexpected error occurred. Please try again later.",i||s.A.error(t),e&&e.errors&&s.A.error(e.errors),this.C.Form.showOptinErrors()}}}}]);