/*! Optin - Tue, 12 Mar 2024 16:58:14 GMT */ "use strict";(self.webpackChunkom_api_js=self.webpackChunkom_api_js||[]).push([[19],{4984:function(t,e,i){i.r(e),i.d(e,{default:function(){return p}});var s=i(9213),r=i(7075),n=i(3583),o=i(7624),a=i(2888);function h(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var s=i.call(t,e||"default");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class p{constructor(t){h(this,"post",(()=>{(0,a.trigger)(document,"Optin.post",{Optin:this,Campaign:this.C});const t=(new s.Z).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)))})),h(this,"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&&r.Z.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")}))})),h(this,"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||r.Z.error(t),e&&e.errors&&r.Z.error(e.errors),this.C.Form.showOptinErrors()})),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 r.Z.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=["comments","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)?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}),n.Z.get("_mkto_trk")&&(this.data.mkto=n.Z.get("_mkto_trk")),n.Z.get("hubspotutk")&&(this.data.hutk=n.Z.get("hubspotutk")),n.Z.get("__ss_tk")&&(this.data.sstk=n.Z.get("__ss_tk"));const s=n.Z.get(/^visitor_id\d{5,8}$/m);if(s&&(this.data.pvid=s),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[o.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()))}));this.post()}}}}}]);