import{b$ as g,bX as p,c0 as C,bS as S,bY as y,b_ as R,c1 as v,c2 as _,c3 as A,c4 as b,c5 as I}from"./entry.CN2Y04_u.js";import{a as O}from"./useGoogleAnalyticsEvents.BjklE9zr.js";import{u as P,a as U,b as G}from"./useOrderCreatingProcessStore.DVanT9zH.js";import{u as M,a as k,b as D}from"./useServiceNavigationStore.BtRDRM8t.js";import{u as L}from"./useUserStore.492Akic_.js";import{b as T}from"./useCustomerAddressesStore.BubvVfaA.js";import"./swiper-vue.C4DZEECA.js";import"./mapShippingMethod.BJu4nhsV.js";import"./mapAddress.D1onrkry.js";const w=()=>{const e=M(),r=k(),o=D(),{useServiceNavigation:t}=g();return{refreshNavigation:async()=>Promise.all([e.loadNavigationElements({depth:3}),r.loadNavigationElements({depth:3}),t&&o.loadNavigationElements({depth:3})])}},H=()=>{const{beginCheckout:e,purchase:r,addToCart:o,signUp:t,login:c,viewCart:l,removeFromCart:d}=O(),n=S(),m=p(),h=C(),u=g();n.subscribe({key:"ADD_TO_CART",handler:o}),n.subscribe({key:"USER_LOGIN",handler:s=>{const a=h.config.analytics.sendUserIdInGoogleAnalytics?s.user.id:void 0;c({method:s.method??"",userId:a})}}),n.subscribe({key:"ORDER_PLACED",handler:({order:s})=>r(s)}),n.subscribe({key:"USER_REGISTER",handler:s=>{const a=h.config.analytics.sendUserIdInGoogleAnalytics?s.customer.id:void 0;t({method:"",userId:a})}}),n.subscribe({key:"REMOVE_FROM_CART",handler:({lineItem:s})=>{d(s)}}),m.afterEach(({fullPath:s})=>{s.includes(u.pagePaths.CART)&&l(),s.includes(u.pagePaths.CHECKOUT)&&e()})};function F(e){const r=new URL(window.location.href),o=new URLSearchParams(r.search);o.set("orderId",e),r.search=o.toString(),history.replaceState({},document.title,r.toString())}const z=async()=>{const{subscribe:e,broadcast:r}=S(),o=L(),t=y(),c=R(),l=v(),d=P(),n=U(),m=G(),h=_(),u=g(),s=T(),{redirectAfterLogin:a}=A();e({key:"USER_LOGIN",handler:()=>{Promise.all([o.fetchCustomer(),t.refreshCart()]);const{path:i}=b();i.includes(u.pagePaths.LOGIN)&&a()}}),e({key:"USER_LOGOUT",handler:()=>{s.clearAddresses(),Promise.all([t.refreshCart(),o.clearUser()])}}),e({key:"ON_DOMAIN_CHANGE",handler:async({domain:i})=>{r("ON_DOMAIN_CHANGE_START",null);const{refreshNavigation:f}=w(),E=I(),N=C();await Promise.all([l.changeLocale(i.language.locale.code),f(),t.refreshCart(),E.fetchCmsComponents(N.config.dynamicCmsCategoryId)]),r("ON_DOMAIN_CHANGE_END",null)}}),e({key:"USER_REGISTER",handler:()=>{t.refreshCart()}}),e({key:"ORDER_PLACED",handler:({order:{id:i}})=>{F(i),t.refreshCart()}}),e({key:"ACCOUNT_REMOVED",handler:()=>{Promise.all([t.refreshCart(),o.clearUser()])}}),e({key:"ON_CURRENCY_CHANGE",handler:()=>{t.refreshCart(),h.refresh(),d.fetchPaymentMethods(),n.fetchShippingMethods()}}),e({key:"ON_ACTIVE_SHIPPING_OR_BILLING_ADDRESS_CHANGE",handler:()=>{d.fetchPaymentMethods(),n.fetchShippingMethods()}}),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"||m.isProcessing||(c.refresh(),t.refreshCart())}),H()};export{z as eventRunner};
