(()=>{"use strict";const e=window.snapchatAdsTrackingData;let n=function(e){return e.PAGE_VIEW="PAGE_VIEW",e.VIEW_CONTENT="VIEW_CONTENT",e.ADD_CART="ADD_CART",e.START_CHECKOUT="START_CHECKOUT",e}({});const t=(n,t)=>{if("function"!=typeof snaptr)throw new Error("Function snaptr not implemented.");window.snaptr("track",n,{...t,integration:e.integration,ip_address:e.user_ip})},o=n=>{var t;return e.pixel_data.products[n.id]&&(n.prices=(t=e.pixel_data.products[n.id].price,{price:Math.round(t*10**e.pixel_data.currency_minor_unit),currency_minor_unit:e.pixel_data.currency_minor_unit})),n},i=(e,o=1,i=null)=>{const{id:r,price:c}=((e,n)=>{const t={id:e.id,quantity:n};return e?.prices?.price&&(t.price=parseInt(e.prices.price,10)/10**e.prices.currency_minor_unit),t})(e,o),a={item_ids:[r],number_items:parseInt(o,10),price:c};i&&(a.event_id=i,a.client_dedup_id=i),t(n.ADD_CART,a)};function r(n=""){return`${e.prefix}${n}`}function c(n,t={}){"string"==typeof n&&n&&"object"==typeof t&&fetch(`${e.ajax_url}`,{method:"POST",credentials:"same-origin",keepalive:!0,body:new URLSearchParams({action:r(n.toLowerCase()),payload:JSON.stringify(t),security:e.capi_nonce})})}function a(e,n){document.defaultView.addEventListener("DOMContentLoaded",function(){e.forEach(e=>{document.querySelectorAll(e).forEach(e=>{e.addEventListener("click",n)})})})}function d(){return"function"!=typeof wp_has_consent||wp_has_consent("marketing")}function _(){if("undefined"==typeof performance)return!0;if(performance.getEntriesByType){const e=performance.getEntriesByType("navigation");if(e.length>0){const n=e[0].type;return"navigate"===n||"back_forward"===n}}return 0===performance.navigation?.type}const u=e.is_pixel_enabled,p=e.is_conversion_enabled;d()&&function(){const e=new URL(window.location.href).searchParams.get("sc_click_id");e&&(document.cookie=`ScCid=${encodeURIComponent(e)}; path=/;`)}(),document.addEventListener("DOMContentLoaded",()=>{d()?(a([".single_add_to_cart_button"],n=>{const t=document.querySelector(`[name=${e.event_id_el_name}]`).value;u&&function(e,n=""){const t=e.target.closest("form.cart");if(!t)return;const r=t.querySelector("[name=add-to-cart]");if(!r)return;const c=t.querySelector("[name=variation_id]"),a=t.querySelector("[name=quantity]"),d=o({id:parseInt(c?c.value:r.value,10)});i(d,a?parseInt(a.value,10):1,n)}(n,t)}),a([".add_to_cart_button:not(.product_type_variable):not(.product_type_grouped):not(.wc-block-components-product-button__button)",'[data-block-name="woocommerce/product-button"] > .add_to_cart_button:not(.product_type_variable):not(.product_type_grouped)'],e=>{const t=window.crypto.randomUUID();u&&function(e,n=""){const t=e.currentTarget.dataset,r=o({id:t.product_id});i(r,t.quantity||1,n)}(e,t);const r=e.currentTarget.dataset;p&&r?.product_id&&c(n.ADD_CART,{event_id:t,product_id:r.product_id,quantity:1})}),(()=>{if(_()&&e.VIEW_CONTENT){const o=window.crypto.randomUUID(),i={...e.VIEW_CONTENT,event_id:o,client_dedup_id:o};e.is_pixel_enabled&&t(n.VIEW_CONTENT,i),e.is_conversion_enabled&&c(n.VIEW_CONTENT,i)}})(),(()=>{if(_()&&e.START_CHECKOUT){const o=window.crypto.randomUUID(),i={...e.START_CHECKOUT,event_id:o,client_dedup_id:o};e.is_pixel_enabled&&t(n.START_CHECKOUT,i),e.is_conversion_enabled&&c(n.START_CHECKOUT,i)}})(),(()=>{if(_()&&e.PAGE_VIEW){const o=window.crypto.randomUUID(),i={event_id:o,client_dedup_id:o};e.is_pixel_enabled&&t(n.PAGE_VIEW,i),e.is_conversion_enabled&&c(n.PAGE_VIEW,i)}})()):console.info("[Snapchat] Marketing consent denied. Tracking skipped.")}),document.addEventListener("wp_listen_for_consent_change",e=>{"allow"===e.detail.marketing&&window.location.reload()}),"function"==typeof jQuery&&jQuery(document).on("found_variation","form.cart",function(n,t){(n=>{n?.variation_id&&(e.pixel_data.products[n.variation_id]={price:n.display_price})})(t)})})();