(()=>{"use strict";const t=window.wp.i18n,i=window.wp.hooks,e="gtmkit-woocommerce-google-analytics",c="experimental__woocommerce_blocks",n=(t,i)=>{window[window.gtmkit_settings.datalayer_name].push({ecommerce:null}),window[window.gtmkit_settings.datalayer_name].push({event:t,...i}),!0===window.gtmkit_settings.console_log&&console.log(`Pushing event ${t}`)},a=()=>{if(!0===window.gtmkit_data.wc.add_shipping_info.fired)return;const t={ecommerce:{currency:window.gtmkit_data.wc.currency,value:window.gtmkit_data.wc.cart_value,shipping_tier:window.gtmkit_data.wc.chosen_shipping_method,items:window.gtmkit_data.wc.cart_items}};n("add_shipping_info",t),window.gtmkit_data.wc.add_shipping_info.fired=!0},o=()=>{if(!0===window.gtmkit_data.wc.add_payment_info.fired)return;const t={ecommerce:{currency:window.gtmkit_data.wc.currency,value:window.gtmkit_data.wc.cart_value,payment_type:window.gtmkit_data.wc.chosen_payment_method,items:window.gtmkit_data.wc.cart_items}};n("add_payment_info",t),window.gtmkit_data.wc.add_payment_info.fired=!0},d=(t,i="")=>{const e=t.extensions.gtmkit.item;return i&&(e.item_list_name=i),e},r=(t,i)=>{!0===window.gtmkit_settings?.console_log&&console.error(`GTM Kit: Error in ${t} handler`,i)};(0,i.addAction)(`${c}-checkout-set-selected-shipping-rate`,e,(({shippingRateId:t})=>{try{if(window.gtmkit_data.wc.chosen_shipping_method=t,0===window.gtmkit_settings.wc.add_shipping_info.config||!1===window.gtmkit_data.wc.is_checkout)return;2===window.gtmkit_settings.wc.add_shipping_info.config&&a()}catch(t){r("set-selected-shipping-rate",t)}})),(0,i.addAction)(`${c}-checkout-set-active-payment-method`,e,(({value:t})=>{try{if(window.gtmkit_data.wc.chosen_payment_method=t,0===window.gtmkit_settings.wc.add_payment_info.config)return;2===window.gtmkit_settings.wc.add_payment_info.config&&o()}catch(t){r("set-active-payment-method",t)}})),(0,i.addAction)(`${c}-checkout-submit`,e,(()=>{try{0!==window.gtmkit_settings.wc.add_shipping_info.config&&a(),0!==window.gtmkit_settings.wc.add_payment_info.config&&o()}catch(t){r("checkout-submit",t)}})),(0,i.addAction)(`${c}-cart-set-item-quantity`,e,(({product:t,quantity:i=1})=>{try{if(t.quantity<i){const e=i-t.quantity,c=JSON.parse(t.extensions.gtmkit.item);c.quantity=e;const a={ecommerce:{currency:window.gtmkit_data.wc.currency,value:t.prices.sale_price/100*e,items:[c]}};n("add_to_cart",a)}else{const e=t.quantity-i,c=JSON.parse(t.extensions.gtmkit.item);c.quantity=e;const a={ecommerce:{currency:window.gtmkit_data.wc.currency,value:t.prices.sale_price/100*e,items:[c]}};n("remove_from_cart",a)}}catch(t){r("cart-set-item-quantity",t)}})),(0,i.addAction)(`${c}-cart-remove-item`,e,(({product:t,quantity:i})=>{try{const e=JSON.parse(t.extensions.gtmkit.item),c={ecommerce:{currency:window.gtmkit_data.wc.currency,value:t.prices.sale_price/100*i,items:[e]}};n("remove_from_cart",c)}catch(t){r("cart-remove-item",t)}})),(0,i.addAction)(`${c}-cart-add-item`,e,(({product:t,quantity:i=1})=>{try{const e=t.extensions.gtmkit.item,c={ecommerce:{currency:window.gtmkit_data.wc.currency,value:t.prices.sale_price/100*i,items:[e]}};n("add_to_cart",c)}catch(t){r("cart-add-item",t)}}));const s=[];(0,i.addAction)(`${c}-product-list-render`,e,(({products:i,listName:e=(0,t.__)("Product List","gtm-kit")})=>{try{if(0===i.length||!0===window.gtmkit_data.wc.is_cart)return;if(1===window.gtmkit_settings.wc.view_item_list.config&&Object.values(window.gtmkit_data.wc.blocks).includes("filter-wrapper")){if(s.includes(e))return;s.push(e)}const t={ecommerce:{items:i.map(((t,i)=>({...d(t,e),index:i})))}};n("view_item_list",t)}catch(t){r("product-list-render",t)}})),(0,i.addAction)(`${c}-product-view-link`,e,(({product:t,listName:i=""})=>{try{const e={ecommerce:{item_list_name:i,items:[d(t,i)]}};n("select_item",e)}catch(t){r("product-view-link",t)}})),(0,i.addAction)(`${c}-product-search`,e,(({searchTerm:t})=>{try{n("search",{search_term:t})}catch(t){r("product-search",t)}}))})();