import{l as d}from"./vendor-DWvj1jit.js";import{z as c,A as _,B as u,C as r,g as h,L as l,E as p}from"./index-8PssKxKU.js";const{currencyCode:i}=h,v={viewItemList(t,e){c("view_item_list",{...e,items_skus:_((t??[]).map(n=>n.code)),items_count:t?.length??0})},selectItem(t,e){const n=t&&typeof t=="object"&&"productId"in t?u(t):r(t);c("select_item",{...e,items:[n]})},viewItem(t,e){c("view_item",{...e,currency:i,value:t.price?.actual?.amount,items:[r(t)]})},addItemToWishList(t,e){c("add_to_wishlist",{...e,currency:i,value:t.price?.actual?.amount,items:[r(t)]})},addItemToCart(t,e,n){const o=r(t);o.quantity=e,c("add_to_cart",{...n,currency:i,value:(t.price?.actual?.amount||0)*(e??1),items:[o]})},addItemsToCart(t,e){const n=d.sumBy(t,s=>s?.price?.actual?.amount),o=t.filter(Boolean).map(s=>r(s));c("add_to_cart",{...e,currency:i,value:n,items:o,items_count:o.length})},addBulkItemsToCart(t,e){const n=t.reduce((a,m)=>a+(m.salePrice?.amount??m.listPrice?.amount??0)*m.quantity,0),o=Math.round(n*100)/100,s=t.map((a,m)=>({index:m,item_id:a.sku,item_name:a.name,affiliation:a.vendor?.name,currency:a.salePrice?.currency?.code??a.listPrice?.currency?.code,discount:a.discountAmount?.amount,price:a.salePrice?.amount??a.listPrice?.amount,quantity:a.quantity}));c("add_to_cart",{...e,currency:i,value:o,items:s,items_count:s.length})},updateCartItem(t,e,n,o){c("update_cart_item",{...o,item_id:t,new_quantity:e,previous_quantity:n})},removeItemsFromCart(t,e){const n=d.sumBy(t,s=>s.extendedPrice?.amount),o=t.map(u);c("remove_from_cart",{...e,currency:i,value:n,items:o,items_count:o.length})},viewCart(t,e){c("view_cart",{...e,currency:i,value:t.total.amount,items:t.items.map(u),items_count:t.items.length})},clearCart(t,e){c("clear_cart",{...e,currency:i,value:t.total.amount,items:t.items.map(u),items_count:t.items.length})},beginCheckout(t,e){try{c("begin_checkout",{...e,currency:t.currency.code,value:t.total.amount,items:t.items.map(u),items_count:t.items.length,coupon:t.coupons?.[0]?.code})}catch(n){l.error(p,"beginCheckout",n)}},addShippingInfo(t,e,n){try{c("add_shipping_info",{...e,shipping_tier:n,currency:t?.shippingPrice.currency.code,value:t?.shippingPrice.amount,coupon:t?.coupons?.[0]?.code,items:t?.items.map(u),items_count:t?.items.length})}catch(o){l.error(p,"addShippingInfo",o)}},addPaymentInfo(t,e,n){try{c("add_payment_info",{...e,payment_type:n,currency:t?.currency?.code,value:t?.total?.amount,coupon:t?.coupons?.[0]?.code,items:t?.items.map(u),items_count:t?.items.length})}catch(o){l.error(p,"addPaymentInfo",o)}},purchase(t,e,n){try{c("purchase",{...n,currency:t.currency?.code,transaction_id:e,value:t.total.amount,coupon:t.coupons?.[0],shipping:t.shippingTotal?.amount,tax:t.taxTotal?.amount,items:t.items.map(u),items_count:t?.items?.length})}catch(o){l.error(p,"purchase",o)}},placeOrder(t,e){try{c("place_order",{...e,currency:t.currency?.code,value:t.total?.amount,coupon:t.coupons?.[0],shipping:t.shippingTotal.amount,tax:t.taxTotal.amount,items_count:t.items?.length})}catch(n){l.error(p,"placeOrder",n)}},search(t,e=[],n=0){c("search",{search_term:t,items_count:n,visible_items:_(e.map(o=>o.code))})},viewSearchResults(t,e){c("view_search_results",{...e,search_term:t,visible_items:_(e?.visible_items?.map(n=>n.code)??[]),results_count:e?.results_count,results_page:e?.results_page})},login(t,e){c("login",{...e,method:t})},signUp(t,e){c("sign_up",{...e,method:t})}};export{v as events};
//# sourceMappingURL=events-BEmchB_l.js.map
