import{maybeConvertAmount}from"../../functions/currency";window.addEventListener("scAddedToCart",(function(n){var i,o,d,t,e,l,u;if(!(null===window||void 0===window?void 0:window.fbq))return;const r=n.detail;if(!(null===(i=null==r?void 0:r.price)||void 0===i?void 0:i.product))return;const c=null===(o=null==r?void 0:r.price)||void 0===o?void 0:o.product,v=(null===(t=null===(d=null==c?void 0:c.product_collections)||void 0===d?void 0:d.data)||void 0===t?void 0:t.map((n=>n.name)))||[];window.fbq("track","AddToCart",{...v.length?{content_category:v.join(", ")}:{},content_ids:[c.id],content_name:(null==c?void 0:c.name)+((null===(e=null==r?void 0:r.variant_options)||void 0===e?void 0:e.length)?` - ${null==r?void 0:r.variant_options.join(" / ")}`:""),content_type:"product",contents:[{id:c.id,quantity:r.quantity}],currency:null===(l=null==r?void 0:r.price)||void 0===l?void 0:l.currency,value:maybeConvertAmount((null==r?void 0:r.total_amount)||0,(null===(u=null==r?void 0:r.price)||void 0===u?void 0:u.currency)||"USD")})})),window.addEventListener("scCheckoutInitiated",(function(n){var i,o,d,t;if(!(null===window||void 0===window?void 0:window.fbq))return;const e=n.detail;window.fbq("track","InitiateCheckout",{content_ids:null===(i=(null==e?void 0:e.line_items.data)||[])||void 0===i?void 0:i.map((n=>n.id)),contents:null===(o=(null==e?void 0:e.line_items.data)||[])||void 0===o?void 0:o.map((n=>({id:n.id,quantity:n.quantity}))),currency:null==e?void 0:e.currency,num_items:(null===(t=null===(d=null==e?void 0:e.line_items)||void 0===d?void 0:d.data)||void 0===t?void 0:t.length)||0,value:maybeConvertAmount(null==e?void 0:e.total_amount,(null==e?void 0:e.currency)||"USD")})})),window.addEventListener("scCheckoutCompleted",(function(n){var i,o,d;if(!(null===window||void 0===window?void 0:window.fbq))return;const t=n.detail;window.fbq("track","Purchase",{content_ids:null===(i=null==t?void 0:t.items)||void 0===i?void 0:i.map((n=>n.item_id)),content_name:"Purchase",content_type:"product",contents:null===(o=null==t?void 0:t.items)||void 0===o?void 0:o.map((n=>({id:n.item_id,quantity:n.quantity}))),currency:null==t?void 0:t.currency,num_items:null===(d=null==t?void 0:t.items)||void 0===d?void 0:d.length,value:maybeConvertAmount(null==t?void 0:t.total_amount,(null==t?void 0:t.currency)||"USD")})})),window.addEventListener("scTrialStarted",(function(n){(null===window||void 0===window?void 0:window.fbq)&&n.detail.forEach((n=>{var i,o,d;window.fbq("track","StartTrial",{currency:null===(i=n.price)||void 0===i?void 0:i.currency,value:maybeConvertAmount((null===(o=n.price)||void 0===o?void 0:o.amount)||0,(null===(d=n.price)||void 0===d?void 0:d.currency)||"USD")})}))})),window.addEventListener("scSubscriptionStarted",(function(n){(null===window||void 0===window?void 0:window.fbq)&&n.detail.forEach((n=>{var i,o,d;window.fbq("track","Subscribe",{currency:null===(i=n.price)||void 0===i?void 0:i.currency,value:maybeConvertAmount((null===(o=n.price)||void 0===o?void 0:o.amount)||0,(null===(d=n.price)||void 0===d?void 0:d.currency)||"USD")})}))})),window.addEventListener("scPaymentInfoAdded",(function(n){if(!(null===window||void 0===window?void 0:window.fbq))return;const i=n.detail;window.fbq("track","AddPaymentInfo",{content_category:"Payment Info Added",currency:null==i?void 0:i.currency})}));