import{maybeConvertAmount}from"../../functions/currency";import{trackEvent}from"../../functions/google";window.addEventListener("scSearched",(i=>{var o;trackEvent("search",{search_term:null===(o=i.detail)||void 0===o?void 0:o.searchString})})),window.addEventListener("scProductViewed",(i=>{var o,n,l,e,t,d,v,u,c,r,a,m;const s=i.detail;trackEvent("view_item",{value:maybeConvertAmount((null===(o=s.price)||void 0===o?void 0:o.amount)||0,(null===(n=s.price)||void 0===n?void 0:n.currency)||"USD"),currency:null===(l=s.price)||void 0===l?void 0:l.currency,items:[{item_id:null==s?void 0:s.id,item_name:null==s?void 0:s.name,currency:null===(e=null==s?void 0:s.price)||void 0===e?void 0:e.currency,discount:(null==s?void 0:s.discount_amount)?maybeConvertAmount(null==s?void 0:s.discount_amount,null===(t=null==s?void 0:s.price)||void 0===t?void 0:t.currency):0,price:maybeConvertAmount(null===(d=null==s?void 0:s.price)||void 0===d?void 0:d.amount,null===(v=null==s?void 0:s.price)||void 0===v?void 0:v.currency),quantity:(null==s?void 0:s.quantity)||1,...(null===(u=null==s?void 0:s.variant_options)||void 0===u?void 0:u.length)?{item_variant:null==s?void 0:s.variant_options.map((i=>i.name)).join(" / ")}:{},...(null===(r=null===(c=null==s?void 0:s.product_collections)||void 0===c?void 0:c.data)||void 0===r?void 0:r.length)?{item_category:null===(m=null===(a=null==s?void 0:s.product_collections)||void 0===a?void 0:a.data)||void 0===m?void 0:m.map((i=>i.name)).join(", ")}:{}}]})})),window.addEventListener("scProductsViewed",(i=>{var o;const n=i.detail;trackEvent("view_item_list",{...(null==n?void 0:n.collectionId)?{item_list_id:n.collectionId}:{},item_list_name:n.pageTitle,items:null===(o=null==n?void 0:n.products)||void 0===o?void 0:o.map((i=>{var o,l,e,t;return{item_id:null==i?void 0:i.id,item_name:null==i?void 0:i.name,...(null===(l=null===(o=null==i?void 0:i.product_collections)||void 0===o?void 0:o.data)||void 0===l?void 0:l.length)?{item_category:null===(t=null===(e=null==i?void 0:i.product_collections)||void 0===e?void 0:e.data)||void 0===t?void 0:t.map((i=>i.name)).join(", ")}:{},...(null==n?void 0:n.collectionId)?{item_list_id:n.collectionId}:{},item_list_name:n.pageTitle}}))})}));