!function(){"use strict";const e="os_offers",t="ADD_TO_CART",n="BUY_PRODUCT";function o(){return function(e){try{return JSON.parse(e)}catch(e){return!1}}(localStorage.getItem(e))||{}}const i={ADD_TO_CART:"https://outsellapp.com/api/v1/script/addToCart",BUY_PRODUCT:"https://outsellapp.com/api/v1/script/buyProduct"};!function(){if(-1!==location.pathname.indexOf("/checkouts/")&&-1!==location.pathname.indexOf("/thank_you")||-1!==location.pathname.indexOf("/orders/")){const a=window.Shopify?.checkout?.line_items,r=o(),c=window.Shopify?.checkout?.total_price_set?.shop_money?.currency_code,d=function(){const e=window.Shopify.checkout.total_price_set.presentment_money.amount;return window.Shopify.checkout.total_price_set.shop_money.amount/e}();if(a&&0!==Object.keys(r)){const o=new Set((r.acceptedOffers||[]).map((e=>e.funnelId)).filter(Boolean)),p=Array.from(o).map((e=>({id:e,acceptedOffers:r.acceptedOffers.filter((t=>t.funnelId===e)).map((e=>{const t=a.find((t=>`${t.variant_id}`==`${e.itemAdded.variantId}`));if(t){const n=t.applied_discounts?.length?t.applied_discounts.reduce(((e,t)=>e+=Number(t.amount)||0),0):0,o=e.itemRemovedByUpgrade&&e.itemRemovedByUpgrade.pricePerUnit*e.itemRemovedByUpgrade.quantityRemoved,i=(Number(t.price)*e.itemAdded.quantityAdded-n)*d-(o||0);return{id:e.offerId,variantId:e.itemAdded.variantId,quantity:e.itemAdded.quantityAdded,purchaseType:e.purchaseType,price:Math.max(i,0)}}return null})).filter(Boolean)})));(async function(e,o){if(!e&&!o)return;const{funnelId:a,shop:r,funnels:c,currencyCode:d}=o;switch(e){case t:a&&r&&await fetch(i.ADD_TO_CART,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({funnelId:a,shop:r})});break;case n:r&&c&&await fetch(i.BUY_PRODUCT,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({shop:r,funnels:c,currencyCode:d})});break;default:throw new Error("Unknown analytic type")}})(n,{shop:window.Shopify?.shop||window.location.host,funnels:p,currencyCode:c||""}).then((()=>{localStorage.removeItem(e)}))}}}()}();