import{cW as T,cX as P,cY as d,bV as S,bY as x,bS as L,bZ as N}from"./entry.BO-DrBF4.js";import{k as p}from"./swiper-vue.DBZVrmDl.js";var _=(t=>(t.DEFAULT="Email & password",t.SSO="SSO",t))(_||{});const F={fromLineItemToCommonItems:t=>(Array.isArray(t)?t:[t]).map(e=>T.isPbxLineItem(e)?q(e):R(e)).flat(),fromOrderToPurchaseEvent:t=>{var e;const r=t.price.calculatedTaxes.map(c=>c.tax)??[];return{transaction_id:t.id,currency:(e=t.currency)==null?void 0:e.isoCode,value:t.amountTotal,tax:P(r),shipping:t.shippingTotal,items:U(t.lineItems??[])}}},h=t=>{var r,e;return(e=(r=t.find(({group:c})=>c.toLowerCase().includes("size")))==null?void 0:r.customFields)==null?void 0:e.pbx_pbx2_attribute_value_name},w=t=>{const{pbx_pbx2_product_family_id:r,pbx_pbx2_product_family_name:e}=t;return e??r},q=t=>t.children.map(r=>{var e;return l({price:((e=r.price)==null?void 0:e.unitPrice)??-1,item:r,quantity:t.quantity})}),R=t=>{const{price:r,label:e,id:c}=t;return{item_id:c,price:(r==null?void 0:r.unitPrice)??-1,item_name:e??"",quantity:t.quantity,item_category:null}},V=t=>{const{unitPrice:r,label:e,quantity:c,productId:n}=t;return{item_id:n,price:r,item_name:e??"",quantity:c,item_category:null}},U=t=>{const r=[];return t.forEach(e=>{d.isSwOrderLineItem(e)&&r.push(V(e)),d.isPbxChildOrderLineItem(e)&&r.push(l({price:e.unitPrice,item:e,quantity:e.quantity}))}),r},l=({price:t,item:r,quantity:e})=>{const{label:c,payload:n}=r;return{item_id:n.customFields.pbx_pbx2_project_uuid,item_category:w(n.customFields),price:t,quantity:e,item_category3:h(n.options),item_name:c??""}},k=t=>t.children.map(r=>{var e;return{price:t.price.unitPrice,item_id:t.id,quantity:t.quantity,item_name:r.label,item_category:t.productFamilyId??"",item_category3:(e=r.options.find(({attrName:c})=>c.toUpperCase()==="size"))==null?void 0:e.attrValue}}),D=t=>({item_id:t.id,item_name:t.label,price:t.price.unitPrice,quantity:t.quantity,item_category:null});class s{static fromAppLineItem(...r){return r.map(e=>e.productType==="pbx_product"?k(e):D(e)).flat()}}var i=(t=>(t.ADD_TO_CART="add_to_cart",t.BEGIN_CHECKOUT="begin_checkout",t.PURCHASE="purchase",t.LOGIN="login",t.SIGN_UP="sign_up",t.VIEW_CART="view_cart",t.REMOVE_FORM_CART="remove_from_cart",t.PAGE_VIEW="page_view",t))(i||{});const G=()=>{const t=S(),r=p(()=>{var n;return!!((n=t.sessionContext)!=null&&n.analytics.active)}),e=p(()=>{var n;return((n=t.sessionContext)==null?void 0:n.analytics.trackingId)||""}),c=p(()=>{var n;return!!((n=t.sessionContext)!=null&&n.analytics.trackOrders)});return{isActive:r,trackingId:e,trackOrders:c}},z=()=>{const t=x(),r=L(),e=N(),{trackOrders:c}=G(),n={method:_.DEFAULT},o=a=>{r.broadcast("ON_ANALYTICS_EVENT_SEND",a)},y=({productId:a,quantity:u})=>{const m=t.cartItems.find(({id:O})=>O===a),f=s.fromAppLineItem({...m,quantity:u}),g={value:m.price.unitPrice*m.quantity,items:f,currency:e.activeCurrency.isoCode};o({eventName:i.ADD_TO_CART,payload:g})},C=a=>{if(!c.value)return;const u=F.fromOrderToPurchaseEvent(a);o({eventName:i.PURCHASE,payload:u})},I=async()=>{await t.waitForInitCart();const a=t.getCart();o({eventName:i.VIEW_CART,payload:{items:s.fromAppLineItem(...t.cartItems),value:a.price.totalPrice,currency:e.activeCurrency.isoCode}})},v=async()=>{await t.waitForInitCart();const a=t.getCart();o({eventName:i.BEGIN_CHECKOUT,payload:{currency:e.activeCurrency.isoCode,items:s.fromAppLineItem(...t.cartItems),value:a.price.totalPrice}})},b=async a=>o({eventName:i.REMOVE_FORM_CART,payload:{currency:e.activeCurrency.isoCode,value:a.price.unitPrice*a.quantity,items:s.fromAppLineItem(a)}}),E=a=>o({eventName:i.SIGN_UP,payload:a}),A=a=>o({eventName:i.LOGIN,payload:a});return{addToCart:y,beginCheckout:v,purchase:C,signUp:(a=n)=>E(a),login:(a=n)=>A(a),viewCart:I,removeFromCart:b,pageView:a=>{o({eventName:i.PAGE_VIEW,payload:{page_title:a}})},subscribe:a=>{r.subscribe({key:"ON_ANALYTICS_EVENT_SEND",handler:a})}}};export{z as a,G as u};
