const smStore = '2xoeaz93e6';let bhrCart={cart:"",contactId:"",eventId:"",cartCreationTime:""};const salesmanagoAppUrl="https://salesmanago.eu.ngrok.io/",loginEmailSelector="#login_email",guestCheckoutFormId="checkout-customer-guest",typeEmailSelector='input[type="email"]',registerSelector='input[data-field-type="EmailAddress"]',getClientPath="front/getClient",upsertCartPath="front/cart",bcStorefrontApi="/api/storefront/carts",bcAddToCartQuery="?action=add",bcCartPath="/cart.php",subscribeAction="subscribe";let smInterval;function delayedOnloadFunction(){for(let t=0;t=0&&document.links[t].addEventListener("click",askForCart);window.location.pathname.indexOf(bcCartPath)>=0&&setInterval(askForCart,15e3),clearInterval(smInterval)}function askForCart(t){request("",bcStorefrontApi,verifyCart,!1,window.location.origin,"GET")}function verifyCart(t){let e=bhrCart.cart;void 0!==t[0]&&"undefined"!==t[0]&&(bhrCart.cart?(addCartEvent(t[0]),e!==bhrCart.cart&&addCart()):(addCartEvent(t[0]),addCart()))}function loginUser(t){request({client:t.currentTarget.querySelector("#login_email").value,store:smStore},getClientPath,setClient)}function registrationForm(t){request({client:t.currentTarget.querySelector(registerSelector).value,store:smStore},getClientPath,setClient)}function guestCheckoutForm(t){request({client:t.currentTarget.querySelector(typeEmailSelector).value,store:smStore},getClientPath,setClient)}function newsletterForm(t){request({client:t.currentTarget.querySelector(typeEmailSelector).value,store:smStore},getClientPath,setClient)}function addCart(){if(checkAuthUser()){if(""===bhrCart.cartCreationTime){let t=new Date;bhrCart.cartCreationTime=Math.round(t.getTime()/1e3)}request({data:JSON.stringify(bhrCart),store:smStore},"front/cart",addEventId)}}function addEventId(t){if(bhrCart.eventId!==t.fields.eventId){bhrCart.eventId=t.fields.eventId;let e=new Date;bhrCart.cartCreationTime=Math.round(e.getTime()/1e3)}saveCart()}function clearCart(){bhrCart.cart="",bhrCart.cartCreationTime="",bhrCart.eventId="",saveCart()}function addCartEvent(t){bhrCart.cart=btoa(encodeURIComponent(JSON.stringify(t)))}function setClient(t){deleteCookie("smclient","",1,document.location.host),clearCart(),setCookie("smclient",t.fields.contactId,_smclt||0,document.location.host),checkAuthUser()}function checkAuthUser(){return!(!getCookie("smclient")||bhrCart.contactId!==getCookie("smclient"))||(getCookie("smclient")?(bhrCart.contactId=getCookie("smclient"),saveCart(),!0):!!bhrCart.contactId&&(setCookie("smclient",bhrCart.contactId,_smclt||0,document.location.host),!0))}function saveCart(){localStorage.setItem("bhrCart",JSON.stringify(bhrCart))}function fetchCart(){let t=localStorage.getItem("bhrCart");t&&(bhrCart=JSON.parse(t))}function getCookie(t){let e=document.cookie.match(new RegExp(t+"=([^;]+)"));return!!e&&e[1]}function setCookie(t,e,r,n){let o=new Date,a="";o.setTime(o.getTime()+24*r*60*60*1e3),a="expires="+o.toUTCString(),document.cookie=t+"="+e+";"+a+";domain="+n+";path=/"}function deleteCookie(t,e,r,n){let o=new Date,a="";o.setTime(o.getTime()-24*r*60*60*1e3),a="expires="+o.toUTCString(),document.cookie=t+"="+e+";"+a+";domain="+n+";path=/"}function transformRequest(t){let e=[];return Object.keys(t).forEach((function(r){e.push(encodeURIComponent(r)+"="+encodeURIComponent(t[r]))})),e.join("&")}function request(t,e,r,n=!1,o=salesmanagoAppUrl,a="POST"){let i=new XMLHttpRequest;i.open(a,o+e,-1!=navigator.userAgent.indexOf("Chrome")),i.setRequestHeader("Content-type","application/x-www-form-urlencoded"),i.onreadystatechange=function(){if(4===i.readyState&&200===i.status){let t=JSON.parse(i.responseText);r(t,n)}else n&&n.target.submit()},t?i.send(transformRequest(t)):i.send()}document.onreadystatechange=()=>{fetchCart(),smInterval=setInterval(delayedOnloadFunction,1e3)};