(()=>{"use strict";const t=window.wp.hooks,n="mailchimp-woocommerce";let e=!1;function i(){return 0[0]!==window.$mcSite&&window.$mcSite.pixel&&0[0]!==window.$mcSite.pixel.api&&"function"==typeof window.$mcSite.pixel.api.track}function o(){return window.mcPixel&&window.mcPixel.cartId?window.mcPixel.cartId:""}function a(e,t){window.mcPixel&&t&&String(t)!==String(e)&&(window.mcPixel.parentMap||(window.mcPixel.parentMap={}),window.mcPixel.parentMap[String(e)]=String(t))}function s(t,n){e&&i()&&window.$mcSite.pixel.api.track(t,n).catch(function(e){console.error("Mailchimp Pixel Blocks: Error tracking "+t,e)})}function r(e){const t=e.prices||{},i=t.currency_minor_unit||2,r=10**i,c=t.price?parseInt(t.price,10)/r:0,n=String(e.id),s=(e.extensions||{})["mailchimp-pixel"]||{},o=s.product_id?String(s.product_id):function(e){return(window.mcPixel&&window.mcPixel.parentMap||{})[String(e)]||""}(n)||n;return a(n,o),{id:n,productId:o,title:e.name||"",price:c,currency:(t.currency_code||"").toUpperCase(),sku:e.sku||"",imageUrl:e.images&&e.images.length>0?e.images[0].src:"",productUrl:e.permalink||"",vendor:"",categories:[]}}function c(e){const t=e.prices||{},n=t.currency_minor_unit||2,s=10**n,o=t.line_total?parseInt(t.line_total,10)/s:0;return{item:r(e),quantity:e.quantity||1,price:o,currency:(t.currency_code||"").toUpperCase()}}(0,t.addAction)("experimental__woocommerce_blocks-cart-add-item",n,function(t){if(!e)return;if(window.mcPixel&&window.mcPixel._handled.addToCart)return;const i=t.product;if(!i)return;const n=function(e){const t=e.prices||{},i=t.currency_minor_unit||2,r=10**i,c=t.price?parseInt(t.price,10)/r:0,n=String(e.id),s=((e.extensions||{})["mailchimp-pixel"]||{}).product_id||e.parent,o=s?String(s):"";return a(n,o),{id:n,productId:o||n,title:e.name||"",price:c,currency:(t.currency_code||"").toUpperCase(),sku:e.sku||"",imageUrl:e.images&&e.images.length>0?e.images[0].src:"",productUrl:e.permalink||"",vendor:"",categories:(e.categories||[]).map(function(e){return e.name||""})}}(i),r=t.quantity||1;s("PRODUCT_ADDED_TO_CART",{cartId:o(),product:{item:{id:n.id,productId:n.productId,title:n.title,price:n.price,currency:n.currency,sku:n.sku},quantity:r,price:n.price*r,currency:n.currency}}),window.mcPixel&&(window.mcPixel._handled.addToCart=!0,setTimeout(function(){window.mcPixel._handled.addToCart=!1},1e3))}),(0,t.addAction)("experimental__woocommerce_blocks-cart-remove-item",n,function(t){if(!e)return;if(window.mcPixel&&window.mcPixel._handled.removeFromCart)return;const i=t.product;if(!i)return;const n=r(i),a=t.quantity||1;s("PRODUCT_REMOVED_FROM_CART",{cartId:o(),product:{item:{id:n.id,productId:n.productId,title:n.title,price:n.price,currency:n.currency,sku:n.sku},quantity:a,price:n.price*a,currency:n.currency}}),window.mcPixel&&(window.mcPixel._handled.removeFromCart=!0,setTimeout(function(){window.mcPixel._handled.removeFromCart=!1},1e3))}),(0,t.addAction)("experimental__woocommerce_blocks-checkout-render-checkout-form",n,function(t){if(!e)return;if(window.mcPixel&&window.mcPixel._handled.checkout)return;const n=t.storeCart;n&&n.cartItems&&0!==n.cartItems.length&&(s("CHECKOUT_STARTED",{checkout:function(e){const t=e.cartTotals||{},i=t.currency_minor_unit||2,n=10**i,a=(e.cartItems||[]).map(c),s=o();return{id:"checkout_"+s,cartId:s,lineItems:a,subtotalPrice:t.total_items?parseInt(t.total_items,10)/n:0,totalTax:t.total_tax?parseInt(t.total_tax,10)/n:0,totalShipping:t.total_shipping?parseInt(t.total_shipping,10)/n:0,totalPrice:t.total_price?parseInt(t.total_price,10)/n:0,currency:(t.currency_code||"").toUpperCase()}}(n)}),window.mcPixel&&(window.mcPixel._handled.checkout=!0))}),(0,t.addAction)("experimental__woocommerce_blocks-product-list-render",n,function(){e&&(window.mcPixel&&window.mcPixel._handled.category||window.mcPixel&&window.mcPixel.data&&window.mcPixel.data.category&&(s("PRODUCT_CATEGORY_VIEWED",window.mcPixel.data.category),window.mcPixel&&(window.mcPixel._handled.category=!0)))}),(0,t.addAction)("experimental__woocommerce_blocks-product-search",n,function(t){if(!e)return;if(window.mcPixel&&window.mcPixel._handled.search)return;const n=t.searchTerm||"";n&&(s("SEARCH_SUBMITTED",{query:n}),window.mcPixel&&(window.mcPixel._handled.search=!0))}),function(){let t=0;!function n(){if(i())return void setTimeout(function(){e=!0},1e3);if(t>=20)return;const s=Math.min(100*2**t,5e3);t+=1,setTimeout(n,s)}()}()})()