/*! Actions - Tue, 12 Mar 2024 16:58:14 GMT */ "use strict";(self.webpackChunkom_api_js=self.webpackChunkom_api_js||[]).push([[0],{3965:function(t,i,e){e.r(i),e.d(i,{default:function(){return r}});var s=e(7075),n=e(2888);function o(t,i,e){return(i=function(t){var i=function(t,i){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var s=e.call(t,i||"default");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===i?String:Number)(t)}(t,"string");return"symbol"==typeof i?i:String(i)}(i))in t?Object.defineProperty(t,i,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[i]=e,t}class h{constructor(t,i){o(this,"on",(()=>{(0,n.each)(this.elements,((t,i)=>{(0,n.inArray)(this.event,this.callable)?(0,n.on)(i,this.event+".omAction."+this.C.id,(()=>{i._omns&&i._omns[this.event+".omAction."+this.C.id]&&(this.element=i,this.trigger())})):i.omAction=this}))})),o(this,"off",(()=>{(0,n.each)(this.elements,((t,i)=>{(0,n.inArray)(this.event,this.callable)&&(0,n.off)(i,this.event+".omAction."+this.C.id)}))})),o(this,"manual",(t=>{(0,n.inArray)(t,this.elements)&&(this.element=t,this.trigger())})),o(this,"trigger",(()=>{this.actionScripts().then((()=>{this[this.type]()}))})),o(this,"actionScripts",(()=>new Promise((t=>{let i=document.createElement("div");i.innerHTML=this.C.Dtr.replaceCustomVars(this.scripts);let e=i.getElementsByTagName("script"),s=(0,n.keys)(e).map((t=>{let i=e[t];return this.scripts=this.scripts.replace(i.outerHTML,""),new Promise((t=>{if(i.src&&i.src.length)(0,n.addScript)(i.src,!0,(()=>{t()}),(()=>{t()}));else{var e=document.createElement("script");e.type="text/javascript",e.text=i.innerHTML,this.C.contain.appendChild(e),t()}}))}));i.innerHTML=this.scripts,this.C.contain.appendChild(i),e||t(),Promise.all(s).then((()=>{t()}))})))),o(this,"view",(()=>{(0,n.trigger)(document,"Action.view",{Action:this,Campaign:this.C}),this.C.views[this.options.name]?(this.track(),this.C.changeView(this.options.name),this.cleanup()):s.Z.error("Cannot change views, the "+this.options.name+" view does not exist.")})),o(this,"close",(()=>{(0,n.trigger)(document,"Action.close",{Action:this,Campaign:this.C}),this.C.settings.visible||this.C.settings.actionClose?(this.C.settings.actionClose||this.track(),this.C.startClose(),this.cleanup()):s.Z.error("The campaign is not open, so it cannot be closed.")})),o(this,"redirect",(()=>{if((0,n.trigger)(document,"Action.redirect",{Action:this,Campaign:this.C}),!this.options.url)return s.Z.error("Cannot redirect. A redirect URL has not been set."),void this.C.startClose();this.options.url=this.parseUrl(this.options.url),this.completeRedirect=!0,(0,n.trigger)(document,"Action.redirect.before",{Action:this,Campaign:this.C}),this.completeRedirect&&(this.track(),this.cleanup(),this.C.Timeouts.set((()=>{this.handleClose(),window.location.href=this.options.url}),500))})),o(this,"email",(()=>{if((0,n.trigger)(document,"Action.email",{Action:this,Campaign:this.C}),!this.options.email)return s.Z.error("Cannot open email client. A mailto address has not been set."),void this.C.startClose();this.options.email=this.sanitize(this.options.email),(0,n.startsWith)(this.options.email,"mailto:")||(this.options.email="mailto:"+this.options.email),this.completeEmail=!0,(0,n.trigger)(document,"Action.email.before",{Action:this,Campaign:this.C}),this.completeEmail&&(this.track(),this.cleanup(),this.handleClose(),window.location.href=this.options.email)})),o(this,"call",(()=>{if((0,n.trigger)(document,"Action.call",{Action:this,Campaign:this.C}),!this.options.phone)return s.Z.error("Cannot call. A phone number has not been set."),void this.C.startClose();this.options.phone=this.sanitize(this.options.phone),0>this.options.phone.indexOf("tel:")&&0>this.options.phone.indexOf("sms:")&&(this.options.phone="tel:"+this.options.phone),this.track(),this.cleanup(),this.handleClose(),window.location.href=this.options.phone})),o(this,"copy",(()=>{if((0,n.trigger)(document,"Action.copy",{Action:this,Campaign:this.C}),!this.options.copy)return void s.Z.error("Cannot copy text. No text to copy has been set.");const t=this.element.innerHTML;try{const t=document.createElement("textarea");t.value=this.C.Dtr.replaceCustomVars(this.options.copy),t.setAttribute("readonly",""),t.style.position="fixed",t.style.left="-100%",t.style.top="-100%",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),this.element.innerHTML=(0,n.__)("Copied!")}catch(t){this.element.innerHTML=(0,n.__)("Copy Failed"),s.Z.error(t)}this.C.Timeouts.set((()=>{this.element.innerHTML=t}),1e3),this.track(),this.cleanup(),this.handleClose()})),o(this,"window",(()=>{if((0,n.trigger)(document,"Action.window",{Action:this,Campaign:this.C}),!this.options.url)return s.Z.error("Cannot open a new window. A valid URL has not been set."),void this.C.startClose();this.options.url=this.parseUrl(this.options.url),this.track(),this.cleanup(),this.handleClose(),window.open(this.options.url,"_blank")})),o(this,"refresh",(()=>{this.completeRefresh=!0,(0,n.trigger)(document,"Action.refresh",{Action:this,Campaign:this.C}),this.completeRefresh&&(this.track(),this.C.Timeouts.set((()=>{this.C.startClose(),this.cleanup(),window.location.reload()}),500))})),o(this,"restart",(()=>{if((0,n.trigger)(document,"Action.restart",{Action:this,Campaign:this.C}),this.C.options.countdown){this.C.Countdown.initiated=!1;let t=this.C.Countdown.finished.indexOf(this.element);-1!==t&&this.C.Countdown.finished.splice(t,1)}})),o(this,"noaction",(()=>{(0,n.trigger)(document,"Action.noaction",{Action:this,Campaign:this.C}),this.track(),this.cleanNoAction&&this.cleanup()})),o(this,"parseUrl",(t=>(t=this.sanitize(this.C.Dtr.replaceCustomVars(t)),this.options.pass&&(0,n.each)(this.C.Optin.data.fields,((i,e)=>{"comments"!==i&&("meta"===i&&(0,n.isObject)(e)?(0,n.each)(e,((i,e)=>{t=(0,n.addQueryArg)(t,"om_"+i,e)})):t=(0,n.addQueryArg)(t,"om_"+i,e))})),t))),o(this,"sanitize",(t=>t.replace(new RegExp("&","g"),"&").replace(new RegExp("&","g"),"&"))),o(this,"track",(()=>{this.options.track&&!this.C.Optin.spam&&this.C.Analytics.conversion()})),o(this,"cleanup",(()=>{this.options.track&&(this.C.settings.success=!0),this.C.cleanup()})),o(this,"handleClose",(()=>{if(this.options.close)return this.C.startClose();this.C.Timeouts.set((()=>{this.C.Form.removeLoad()}),500)})),this.actions=t,this.data=i,this.C=t.C,this.id=i.id||null,this.selector=i.selector||null,this.element=null,this.elements=null,this.event=i.event||"click",this.scripts=i.scripts||"",this.options=i.options||{},this.type=i.type||"",this.types=["view","redirect","email","refresh","close","window","restart","call","copy","noaction"],this.callable=["click","submit","omWpformsSuccess"],this.cleanNoAction=!1}init(){if((0,n.trigger)(document,"Action.init",{Action:this,Campaign:this.C}),!(0,n.inArray)(this.type,this.types))throw'The expected type "'+this.type+'" is not a valid type.';this.elements=(0,n.querySelectorAll)(this.selector),this.elements.length?this.on():this.actions.missing.push(this.selector)}}class r{constructor(t){this.C=t,this.actions=[],this.missing=[],(0,n.each)(t.actions,((t,i)=>{this.actions.push(new h(this,i))}))}init(){(0,n.trigger)(document,"Actions.init",{Actions:this,Campaign:this.C}),(0,n.each)(this.actions,((t,i)=>i.init()))}off(){(0,n.trigger)(document,"Actions.off",{Actions:this,Campaign:this.C}),(0,n.each)(this.actions,((t,i)=>i.off()))}}}}]);