async function prepareDynamicJSFor(a,b,c,d){window.CJClientApi||(window.CJClientApi={}),window.Shopify||(window.Shopify={});const e=window.cjShopifyDataCustomPixel,f="undefined"==typeof window.cjTaxExclusionFlag?d.isTaxIncluded:window.cjTaxExclusionFlag;d.isTaxIncluded=d.isTaxIncluded===f?d.isTaxIncluded:f;const g=window.location.host;if(d.isPixelConnected&&"undefined"!=typeof e&&null!==e){let c=parseCJShopifyData(JSON.parse(e)),f=await getShopifyCheckout(c,d);await processCheckoutData(f,!1,d,c,a,b),deleteCookie("cart",g)}else if(Shopify.checkout)"undefined"!=typeof cjShopifyData&&cjShopifyData?await processCheckoutData(Shopify.checkout,!0,d,cjShopifyData,a,b):console.log("cjShopifyData not found"),deleteCookie("cart",g);else{const{cjevent:a,cjdata:b}=getEventIdAndCJDataFromUrl();(a||b)&&g&&(await saveCJEventIdIntoCart(a,b,d.originDomain,g)),!localStorage.getItem("cjevent")&&g&&(window.CJClientApi.tagData=await getCJEventIdFromCart(d.originDomain,g))}const h=document.createElement("script");h.src=`https://www.mczbf.com/tags/${c}/tag.js`,h.type="text/javascript",h.async=!0,h.id="cjapitag",document.head.appendChild(h)}async function getCJEventIdFromCart(a,b){const c=getCookie("cart");if(c){const d=`cart=${encodeURIComponent(c)}`;try{const c=await fetch(`${a}saveAndGetCart?shop=${b}&cookies=${encodeURIComponent(d)}`,{method:"GET"});if(200===c.status){const a=await c.json(),{attributes:b={}}=a,{cjevent:d,cjdata:e}=b;return{cjevent:d,cjdata:e}}console.error(`CJ PLUGIN : Error fetching cart for shop ${b}`)}catch(a){console.error(`CJ PLUGIN : Error fetching cart for shop ${b} :`,a)}}return{}}async function saveCJEventIdIntoCart(a,b,c,d){const e=getCookie("cart");let f="";e&&(f=`cart=${encodeURIComponent(e)}`);try{const g=await fetch(`${c}saveAndGetCart?shop=${d}&cjEvent=${a}&cjData=${b}&cookies=${encodeURIComponent(f)}`,{method:"POST"});if(200===g.status){const a=await g.json();e||setCookie("cart",encodeURIComponent(a.token),31,d)}else console.error(`CJ PLUGIN : Error saving cart for shop ${d}`)}catch(a){console.error(`CJ PLUGIN : Error saving cart for shop ${d} :`,a)}}function deleteCookie(a,b){document.cookie=a+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain="+b+";"}function getCookie(a){let b=a+"=",c=decodeURIComponent(document.cookie),d=c.split(";");for(let c of d)if(c=c.trim(),0===c.indexOf(b))return c.substring(b.length,c.length);return null}function setCookie(a,b,c,d){let e=new Date;e.setTime(e.getTime()+1e3*(60*(60*(24*c))));let f="expires="+e.toUTCString();document.cookie=a+"="+b+";"+f+";path=/;SameSite=Lax;domain="+d}function parseCJShopifyData(a){return{currency:a.currencyCode||"",subTotalamount:a.subtotalPrice?.amount||0,totalAmount:a.totalPrice?.amount||0,taxAmount:a.totalTax?.amount||0,shippingAddress:a.shippingAddress||{},shippingAmount:a.shippingLine?.price?.amount||0,items:a.lineItems||[],shopifyOrderId:a.order||{},discount:a.discountApplications||[]}}async function processCheckoutData(a,b,c,d,e,f){window.cj={},window.cj.source={},shopifyCheckout=JSON.parse(JSON.stringify(a));const g=a;b?(isExtensibility=!1,taxes_exclusion_required=d.taxes_exclusion_required,taxToBeDivided=taxes_exclusion_required&&g.tax_lines&&0=a?"New":"Return"}h.orderId=d.orderId?d.orderId:g.order_id?g.order_id+"":"",d.items&&setDiscountAndUnitPrice(h,d),d.taxes_exclusion_required&&(h.amount=getTaxFreeAmount()),b&&isShippingDiscount(g)&&(h.discount=0);const i={enterpriseId:h.enterpriseId,pageType:h.pageType,userId:h.userId,cartSubtotal:h.amount,items:h.items},j={name:h.cjPlugin,version:b?"1.0.0":"2.0.0"};if(isTaxLinesMissing){const a=await getDataForReprocessing(h);await sendPostRequest(a,c.originDomain,c.shop)}else window.cj.order={},window.cj.order=cleanObject(h);window.cj.sitePage=cleanObject(i),window.cj.source=cleanObject(j)}function getDataForReprocessing(a){let b={orderId:a.orderId};const c=getCookie("cjevent_dc");return null!=c&&(b.cjevent=c),b}async function sendPostRequest(a,b,c){try{const d=await fetch(`${b}reprocessData?shop=${c}&data=${encodeURIComponent(JSON.stringify(a))}`,{method:"POST"});if(200===d.status)return await d.json();console.error(`CJ PLUGIN: Error reprocessing data for shop ${c}`)}catch(a){console.error(`CJ PLUGIN: Error reprocessing data for shop ${c} :`,a)}return{}}async function getShopifyCheckout(a,b){let c=a.shopifyOrderId,d=[],e=a.taxAmount||0,f=[],g=0,h=[],i=[];a.discount.forEach(function(a){"SHIPPING_LINE"!==a.targetType&&h.push(a.title)}),a.items.forEach(function(a){let b=0;if(a.discountAllocations&&0{"line_item"===b.target_type?"all"===b.target_selection&&"across"===b.allocation_method?a.set(c,"cart"):a.set(c,"item"):a.set(c,"shipping")}),m?.line_items?.map(b=>{let c=b.discount_allocations;c.map(b=>{let c=b.discount_application_index;a.get(c)&&(b.discount_type=a.get(c))})}),m?.line_items?.map((a,b)=>{let c=0,e=0,f=0;c=a.id?a.id:"";let g=0,h=0;a.discount_allocations.map(a=>{a.discount_type&&"cart"===a.discount_type?(g+=a.amount_set?.presentment_money?.amount?parseFloat(a.amount_set.presentment_money.amount):0,hasCartDiscount=!0):a.discount_type&&"item"===a.discount_type&&(h+=a.amount_set?.presentment_money?.amount?parseFloat(a.amount_set.presentment_money.amount):0,hasItemDiscount=!0)}),a.tax_lines.map(a=>{e+=a.rate?a.rate:0,f+=a.price?parseFloat(a.price):0,d[b]={rate:e,itemId:c,itemTax:f,cart_discount:g,item_discount:h}})})}let o={order_id:c.id||"",customer_id:c.customer?.id||"",presentment_currency:a.currency||"",subtotal_price:a.subTotalamount?.toFixed(2)||0,taxes_included:b.isTaxIncluded,tax_lines:m.tax_lines,ptax_lines:d,total_price:a.totalAmount?.toFixed(2)||0,total_tax:e.toFixed(2),line_items:f,shipping_rate:j,shipping_address:k,discount:l};return o}async function getOrderDetails(a,b,c){try{const d=await fetch(`${a}getOrderDetails?shop=${b}&orderId=${c}`,{method:"GET"});if(200===d.status)return await d.json();console.error(`CJ PLUGIN: Error fetching product tax lines for shop ${b}`)}catch(a){console.error(`CJ PLUGIN: Error fetching product tax lines for shop ${b} :`,a)}return{}}async function getCustomerOrders(a,b,c){try{const d=await fetch(`${a}getCustomerOrders?shop=${b}&customerId=${c}`,{method:"GET"});if(200===d.status)return await d.json();console.error(`CJ PLUGIN: Error fetching customer orders for shop ${b}`)}catch(a){console.error(`CJ PLUGIN: Error fetching customer orders for shop ${b} :`,a)}return{}}async function getCJShopifyData(a,b,c){let d;const e=a.shopifyOrderId?.customer;if(null!=e?.isFirstOrder)d=e.isFirstOrder?1:2;else{const a=await getCustomerOrders(b.originDomain,b.shop,e.id);d=a&&0{0!=a.discount&&(e=!0)});let f=transformItemList(b.items);a.items=isVariantIdReplaceSku?replaceSkuWithVariantId(f):f;let g=parseFloat(a.amount);if(parseFloat(getNumber(shopifyCheckout.total_price))===parseFloat((getNumber(shopifyCheckout.subtotal_price)-getNumber(a.discount)+getNumber(shopifyCheckout.total_tax)+getNumber(shopifyCheckout.shipping_rate.price)).toFixed(2))){let b=parseFloat((getNumber(shopifyCheckout.subtotal_price)-getNumber(a.discount)).toFixed(2));g=b}let h=function(a){for(let b in a)if(0===a[b].unitPrice&&0({...b,discount:reCalculateDiscountPrice(b.discount,isExtensibility?itemTaxLines:null,c,a.taxAmount)})),totalItemLevelDiscountWithoutTax=a.items.reduce((a,b)=>a+ +b.discount,0),totalItemLevelDiscountWithoutTax=parseFloat(totalItemLevelDiscountWithoutTax).toFixed(2),d=!0):sumOfItemLevelUnitPrice>g&&sumOfItemLevelUnitPrice===parseFloat(c+g).toFixed(2)?d=!0:sumOfItemLevelUnitPrice>g&&0!==a.discount?totalAmountCalculated==g?d=!0:d=!1:sumOfItemLevelUnitPrice===g&&(d=!1)):d=!0,!1===d&&isExtensibility&&b.items==a.items)a.items=a.items.map(a=>({...a,unitPrice:getFixedUnitPrice(a.unitPrice,a.discount,a.quantity)}));else if(taxes_exclusion_required){let b=isExtensibility?reCalcDiscWithPTaxLines(a.discount,itemTaxLines,getNumber(a.taxAmount)):reCalculateDiscountPrice(a.discount,null,null,a.taxAmount);if(totalItemLevelDiscountWithoutTax==b||null==shopifyCheckout.discount)a.discount=0,totalDiscount=totalItemLevelDiscountWithoutTax;else if(i&&totalItemLevelDiscountWithoutTax!=b){let c=(b-totalItemLevelDiscountWithoutTax).toFixed(2),d=0;if(h){a.items=a.items.map(a=>({...a,unitPrice:0===a.unitPrice?parseFloat(getFixedUnitPrice(a.unitPrice,a.discount,a.quantity)):a.unitPrice}));for(let b of a.items)b.unitPrice==b.discount&&(d+=parseFloat(b.discount));c=parseFloat(c)+d}a.discount=parseFloat(c).toFixed(2),a.discount=0>a.discount?0:a.discount,totalDiscount=b}else totalDiscount=b,a.discount=totalDiscount}else totalAmountCalculated!=g&&(a.discount=0===a.discount?0:a.discount.toFixed(2));if(!(isExtensibility||e)){let b=parseFloat(sumOfItemLevelUnitPrice-c).toFixed(2);const d=a.items.some(a=>0===a.unitPrice);a.amount!=b&&(a.amount=parseFloat(b),!taxes_exclusion_required&&d?a.items=a.items.map(a=>({...a,unitPrice:parseFloat(getFixedUnitPrice(a.unitPrice,a.discount,a.quantity))})):!(taxes_exclusion_required||d)&&(a.discount-=c))}else!(isExtensibility||taxes_exclusion_required)&&e&&(a.items=a.items.map(a=>({...a,unitPrice:getFixedUnitPrice(a.unitPrice,a.discount,a.quantity)})))}function replaceSkuWithVariantId(a){let b=a.map(a=>{let b=shopifyCheckout.line_items.find(b=>handlelize(b.sku)==a.itemId);return{...a,itemId:b.variant_id}});return b}function reCalculateDiscountPrice(a,b,c,d){if(a){if(b&&0{hasCartDiscount&&d.push(a.cart_discount/(1+a.rate)),hasItemDiscount&&d.push(a.item_discount/(1+a.rate))});let e=d.reduce((c,a)=>c+a,0);return parseFloat(e).toFixed(2)}function getTaxTobeDividedVal(a){let b=a.reduce((a,b)=>a+ +b.rate,1);return parseFloat(b).toFixed(2)}function getAmountPostDiscount(a,b,c){var d=0,e=b-(a+c);return e=e.toFixed(2),d=parseFloat(e),d}function getDiscount(a){return a?.amount?getNumber(a.amount):0}function getCoupon(a){return a.code?a.code:""}function isShippingDiscount(a){let b=getNumber(a.total_tax);a.taxes_included&&(b=0);const c=getNumber(a.total_price),d=getNumber(a.subtotal_price);let e=0;a.shipping_rate&&(e=getNumber(a.shipping_rate.price));const f=c-b-d;let g=!0;if(0!=e&&.01>f.toFixed(2)-e.toFixed(2)){let b=sumOfItemLevelUnitPrice;a.discount!=null&&(b-=getNumber(a.discount.amount)),b>=d&&(g=!1)}return 0!=e&&f.toFixed(2)getNumber(a.discount)).reduce((a,b)=>a+b)),b}function trimSpace(a){return a.trim()}function transformItemList(a){let b=a.map(a=>({...a,itemId:trimSpace(a.itemId),unitPrice:+parseFloat(a.unitPrice).toFixed(2)}));return b}function makeItemList(a){if(a){let b=a.map(a=>({itemId:isVariantIdReplaceSku?a.variant_id:a.sku?trimSpace(a.sku):"",unitPrice:a.price?getNumber(a.price):0,quantity:a.quantity?getNumber(a.quantity):0,discount:""}));return b}return[]}function findCountryName(a){return a?a.country_code?a.country_code:"":""}function getEventIdAndCJDataFromUrl(){const a=window.location.search,b=new URLSearchParams(a);let c=null,d=null;return b.forEach((a,b)=>{const e=b.toLowerCase();"cjevent"===e?c=a:"cjdata"===e&&(d=a)}),{cjevent:c,cjdata:d}}function cleanObject(a){return a.items&&removeItemDiscountWithValueZero(a.items),getDefinedProps(a)}function removeItemDiscountWithValueZero(a){a.forEach(a=>{for(let b in a)value=a[b],"discount"==b&&0===value&&delete a[b]})}function isArray(a){return"[object Array]"===Object.prototype.toString.call(a)}function getDefinedProps(a){for(let b in a)value=a[b],(""===value||null===value||void 0===value)&&"itemId"!==b?delete a[b]:isArray(value)&&value.forEach(a=>{getDefinedProps(a)});return a}function getNumber(a){return isNaN(a)?0:+a}function getFixedUnitPrice(a,b,c){return parseFloat(a+b/c).toFixed(2)}function handlelize(a){return a=a.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/([^\w]+|\s+)/g,"-").replace(/\-\-+/g,"-").replace(/(^-+|-+$)/g,"").toLowerCase(),a}function getTaxFreeAmount(){return parseFloat(sumOfItemLevelUnitPrice-totalItemLevelDiscountWithoutTax).toFixed(2)}function zeroTaxAmount(a){return!(0!=a.taxAmount)}function getPreCartDiscAmount(a,b){return b?parseFloat((a+b).toFixed(2)):parseFloat(a.toFixed(2))}function isCartLevelDiscount(a){return"ACROSS"===a.discountApplication.allocationMethod&&"ALL"===a.discountApplication.targetSelection} prepareDynamicJSFor(1536200,382845,296380435696,{"originDomain":"https://cjshpfy.cjintegrations.com/","shop":"rainbowshops-prod.myshopify.com","isPixelConnected":true,"isTaxIncluded":false})