(()=>{var B=Object.defineProperty;var J=(o,t,e)=>t in o?B(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var r=(o,t,e)=>(J(o,typeof t!="symbol"?t+"":t,e),e);var M={campaigns:[],configuration:{debug:!1,token:"Rx8sIcDJitv4ejoBoJJqXQfS18FQljipTeXVAPAt731defeb",url:"https://identity.paymonix.com"}},f=M;var l=class{static setDebug(t=!1){l.debug=t}static log(t,...e){l.debug&&console.log(t,...e)}static setCookie(t,e,s){let a=l.getDomain(),n=s?"; expires="+s.toUTCString():"";document.cookie=`${t}=${e}${n}; path=/; domain=${a}; Secure; SameSite=None`}static getCookie(t){let s=`; ${document.cookie}`.split(`; ${t}=`);return s.length===2?s.pop().split(";").shift():null}static getDomain(){let t=window.location.hostname,e=t.split(".");return e.length>2?"."+e.slice(-2).join("."):e.length===2?"."+t:t}static setLocalStorage(t,e){localStorage.setItem("PMXIP_"+t,JSON.stringify(e))}static getLocalStorage(t){return JSON.parse(localStorage.getItem("PMXIP_"+t))}static isValidEmail(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}static trigger3dParty(){let t=this.getLocalStorage("session"),e=t.email;if(!this.isValidEmail(e||"")){l.log("Email is empty or incorrect format. Skipping identification event.");return}if(t.is_3d_party_user)l.log("Customer already defined as 3d party user. Skipping identification event.");else{l.log("Triggering identification event.");let s=window._learnq=window._learnq||[];typeof s.isIdentified=="function"&&!s.isIdentified()&&s.push(["identify",{$email:e,source:"PMXID"}]),t.is_3d_party_user=!0,l.setLocalStorage("session",t)}}static isKlaviyoUser(){let t=window._learnq=window._learnq||[];return!!(typeof t.isIdentified=="function"&&t.isIdentified())}static hasDebugParam(){return window.location.search.includes("debug")}},c=l;r(c,"debug",!1),r(c,"ONE_YEAR",Date.now()+365*24*60*60*1e3),r(c,"ONE_MONTH",Date.now()+30*24*60*60*1e3),r(c,"ONE_DAY",Date.now()+24*60*60*1e3),r(c,"ONE_HOUR",Date.now()+60*60*1e3),r(c,"ONE_MINUTE",Date.now()+60*1e3);var i=c;var g=class{constructor(t){this.type=t}execute(t,e){return i.log("Operator type "+this.type+" execution:",[t,e]),this.executeByType(t,e)}executeByType(t,e){switch(this.type){case"equal":return t.getByName()===e;case"not_equal":return t.getByName()!==e;case">":return t.getByName()>e;case"<":return t.getByName()<e;case">=":return t.getByName()>=e;case"<=":return t.getByName()<=e;case"contains":return t.getByName().includes(e);case"not_contains":return!t.getByName().includes(e);case"is_empty":return typeof t.getByName()==null||t.getByName()==="";case"is_not_empty":return typeof t.getByName()!==null&&t.getByName()!=="";default:return!0}}},w=g;var y=class{constructor(t){this.name=t}getByName(){let t=i.getLocalStorage("session");switch(this.name){case"email":return t&&t.email?t.email:"";case"current_page":return window.location.href;case"time_on_site":return(Date.now()-(t.initDate??Date.now()))/1e3;case"visits_count":return t&&t.visits_count?t.visits_count:1;default:return new Error("Attribute not found")}}},v=y;var x=class{constructor(t){this.rawJson=t,this.attribute=new v(this.rawJson.attribute),this.operator=new w(this.rawJson.operator),this.value=this.rawJson.value}execute(){i.log("RULE EXECUTION: ",[this.attribute.name,this.operator.type,this.value]);let t=this.operator.execute(this.attribute,this.value);return i.log("RULE RESULT: ",t),t}},u=x;var p=class{constructor(t){this.rawJson=t,this.condition=this.rawJson.group,this.rules=[],this.initRules()}initRules(){this.rawJson.rules.forEach(t=>{t.group?this.rules.push(new p(t)):this.rules.push(new u(t))})}execute(){switch(this.condition??null){case"or":return this.executeOr();case"and":return this.executeAnd();case"not":return this.executeNot();default:return!1}}executeOr(){let t=!1;return this.rules.forEach(e=>{e.execute()&&(t=!0)}),t}executeAnd(){let t=!0;return this.rules.forEach(e=>{e.execute()||(t=!1)}),t}executeNot(){let t=!1;return this.rules.forEach(e=>{e.execute()&&(t=!1)}),t}},E=p;var k=class{constructor(t){this.type=t.type,this.value=t.value}activate(t){switch(i.log("Activator type "+this.type+" triggered with value "+this.value),this.type){case"time":this.activateTime(t);break;case"scroll":this.activateScroll(t)}}activateTime(t){setTimeout(t,parseInt(this.value)*1e3)}activateScroll(t){let e=parseInt(this.value);isNaN(e)||window.addEventListener("scroll",function(){let s=document.documentElement.scrollHeight-window.innerHeight,a=e/100*s;i.log("Scroll event triggered",{scrollY:window.scrollY,targetScroll:a,percentage:e}),window.scrollY>=a&&!window.pmxip?.scrollExecuted&&(window.pmxip.scrollExecuted=!0,t())})}},S=k;var b=class{constructor(t,e){this.raw=t,this.id=e,this.type=t.type??null,this.place=t.place??null,this.value=t.value??null,this.html='<div class="klaviyo-form-'+this.id+'"></div>'}position(){switch(this.type){case"inline":this.inline(this.place);break;case"inline_blur":this.inline(this.place,function(...t){let s=t[0].parentNode.children,a=!1;for(let n=0;n<s.length;n++)s[n]!==t[0]&&a&&!s[n].className.includes("klaviyo-form-")?(s[n].style.filter="blur(5px)",s[n].style.pointerEvents="none",s[n].classList.add("pmxip-blurred")):s[n]===t[0]&&(a=!0)});break;case"full_page":this.lock();break;default:i.log("Unknown position type",this.type)}}removeEffects(t=!1){let e=document.getElementsByClassName("pmxip-blurred");Array.from(e).forEach(function(s){s.style.filter="none",s.style.pointerEvents="auto",s.classList.remove("pmxip-blurred")}),document.getElementById("pmxip-overlay")?.remove(),t&&document.getElementsByClassName("klaviyo-form-"+t)[0]?.remove()}lock(){let t=document.getElementById("pmxip-overlay");t&&t.remove();let e=document.createElement("div");e.id="pmxip-overlay",e.style.position="fixed",e.style.top="0",e.style.left="0",e.style.width="100%",e.style.height="100%",e.style.backgroundColor="rgba(0, 0, 0, 0.2)",e.style.backdropFilter="blur(6px)",e.style.webkitBackdropFilter="blur(6px)",e.style.zIndex="9999";let s=document.createElement("div");s.style.display="flex",s.style.justifyContent="center",s.style.flexDirection="column",s.style.position="fixed",s.style.width="50%",s.style.height="50%",s.style.left="50%",s.style.top="50%",s.style.transform="translate(-50%, -50%)",s.style.backgroundColor="rgb(255, 255, 255)",s.style.boxShadow="rgba(0, 0, 0, 0.3) 0px 2px 10px",s.style.padding="20px",s.style.overflow="auto",s.innerHTML=this.html,e.appendChild(s),document.body.appendChild(e)}inline(t,e=null){let s=document.querySelectorAll("p");switch(t){case"after_p":s[parseInt(this.value)-1].insertAdjacentHTML("afterend",this.html),typeof e=="function"&&e(s[parseInt(this.value)-1]);break;case"before_p":s[parseInt(this.value)-1].insertAdjacentHTML("beforebegin",this.html),typeof e=="function"&&e(s[parseInt(this.value)-1]);break;case"id":document.getElementById(this.value).insertAdjacentHTML("afterend",this.html);break;case"class":document.getElementsByClassName(this.value)[0].insertAdjacentHTML("afterend",this.html);break;default:break}}},_=b;var N=class{constructor(t){this.type=t.type,this.raw=t}execute(){let t=new S(this.raw.activation??{});switch(this.type){case"show_form":i.log("Show form action triggered. Form id: ",this.raw.value);let e=new _(this.raw.position??{},this.raw.value),s=this.raw.value;t.activate(function(){e.position(),window._klOnsite=window._klOnsite||[],window._klOnsite.push(["openForm",s]),window.addEventListener("klaviyoForms",function(n){n.detail.type==="submit"&&(e.removeEffects(n.detail.formId??null),window.pmxip.scrollExecuted=!1)})});break;case"alert":i.log("Alert action triggered.");let a=this.raw.value;t.activate(function(){alert(a??"Alert action triggered without text parameter")});break;default:i.log("Unknown action type",this.type)}}},C=N;var I=class{constructor(t){this.raw=t,this.actions=[],this.initActions()}initActions(){this.raw.forEach(t=>{this.actions.push(new C(t))}),i.log("Actions initiated: ",this.actions)}execute(){this.actions.forEach(t=>{t.execute()})}},P=I;var A=class{constructor(t){this.rawJson=t,this.rules=[],this.name=this.rawJson.name,this.needsParam=this.rawJson.needs_get_param,this.meta=this.rawJson.meta,this.actions=this.rawJson.actions,this.rawJson.rules&&this.prepareRules(this.rawJson.rules),i.log(this.name+": ",this.rules)}prepareRules(t){if(!!t)try{t.forEach(e=>{e.group?this.rules.push(new E(e)):this.rules.push(new u(e))})}catch(e){i.log("Error preparing rules",e)}}start(){if(this.needsParam&&!i.hasDebugParam()){i.log("Get parameter not set. Skip campaign execution for campaign: ",this.name);return}i.log("Starting campaign",this.name);let t=!0;this.rules.forEach(e=>{e.execute()||(t=!1)}),t?this.process():i.log("Campaign "+this.name+" not processed")}process(){i.log("Processing campaign action",this),new P(this.actions).execute()}},O=A;var T=class{constructor(t){this.rawJson=t,this.collection=[]}init(){i.log("CampaignsCollection initialization",this.rawJson),this.rawJson.forEach(t=>{this.collection.push(new O(t))})}start(){i.log("Starting campaigns",this.collection),this.collection.forEach(t=>{i.log("Starting campaign",t),t.start()})}},L=T;var U=class{initUrl="/api/v4/session/init";pushUrl="/api/v4/session/push-email";constructor(t){this.baseUrl=t.url,this.token=t.token}init(){i.log("Api Client initialization request"),this.sendRequest({url:this.baseUrl+this.initUrl,method:"POST",body:{token:this.token,session_token:i.getCookie("pmxip_session_token")??!1}}).then(t=>{if(i.log("Api Client response",t),t.status==="success"){i.log("Session initialized successfully",t),i.setCookie("pmxip_session_token",t.data.session_token,new Date(i.ONE_MINUTE*30));let e=t.data;e.initDate=Date.now(),i.setLocalStorage("session",e),document.dispatchEvent(h.EVENT_SESSION_SET)}else i.setLocalStorage("session",!1),i.log("Session initialization failed",t)})}pushEmail(t){i.log("Pushing email: "+t),this.sendRequest({url:this.baseUrl+this.pushUrl,method:"POST",body:{token:this.token,session_token:i.getCookie("pmxip_session_token")??!1,email:t}}).then(e=>{if(e.status==="success"){i.log("Email pushed successfully");return}i.log("Error pushing email. Response: ",e)})}async sendRequest(t){return t.body.token=this.token,await(await fetch(t.url,{method:t.method,headers:{"Content-Type":"application/json"},body:JSON.stringify(t.body)})).json()}},D=U;var d=class{constructor(t){if(this.config=t,this.token=this.config.configuration.token,i.setDebug(this.config.configuration.debug),!this.config.configuration)throw new Error("No configuration found for PMXIP Client");this.apiClient=new D(this.config.configuration)}init(){try{this.initCampaigns(),this.initSession()}catch(t){i.log("Error initializing PMXIP",t);return}i.log("PMXIP initialized",this.config)}initCampaigns(){if(this.config.campaigns.length>0){this.campaigns=new L(this.config.campaigns),this.campaigns.init();return}this.campaigns=!1}initSession(){let t=i.getLocalStorage("session"),e=i.getCookie("pmxip_session_token");i.log("Session cookie: ",e),t&&e?(i.log("Cookie and session found in local storage",t),document.dispatchEvent(d.EVENT_SESSION_SET)):this.apiClient.init()}startCampaigns(){if(i.isKlaviyoUser()){i.log("Klaviyo user detected. Skipping campaigns.");return}else i.trigger3dParty();this.campaigns&&this.campaigns.start()}push(t){this.apiClient?this.apiClient.pushEmail(t):i.log("No ApiClient found to push email")}},m=d;r(m,"EVENT_SESSION_SET",new CustomEvent("pmxipSessionInitiated",{detail:{message:"Session set.",timestamp:Date.now(),session:i.getLocalStorage("session")}}));var h=m;document.addEventListener("pmxipSessionInitiated",function(o){window.pmxip.startCampaigns()});document.addEventListener("DOMContentLoaded",function(){document.addEventListener("click",function(o){let t=o.target.dataset.pmxfocus??!1;o.target.tagName==="INPUT"&&!t&&(o.target.setAttribute("data-pmxfocus","true"),o.target.addEventListener("blur",function(e){let s=e.target.value;i.log("Input blur triggered with value: "+s),i.isValidEmail(s)&&(i.log("Email validity proved. Pushing email."),window.pmxip.push(s))}))}),window.pmxip?console.warn("pmxip is already initialized on the window object."):(window.pmxip=new h(f),window.pmxip.init())});})();
