(function($){function executeFunction(){window.designated_buy_gift_function&&custom.designatedBuyGift(),window.full_amount_buy_gift_function&&(window.designated_buy_gift_function?setTimeout(()=>{custom.fullamountBuyGift()},100):custom.fullamountBuyGift())}var carthandler={set(target,property,value){return property==="isActive"&&value===!0&&executeFunction(),target[property]=value,!0}};window.cart_proxy=new Proxy(window.CartChangetarget,carthandler),$(document).ready(function(){custom.init()});var custom={init:function(){window.designated_buy_gift_function&&this.designatedBuyGift(),window.full_amount_buy_gift_function&&this.fullamountBuyGift()},disable_checkout:function(){$(".cart__checkout-button").attr("disabled","disabled").addClass("loading"),$(".cart__checkout-button .loading__spinner").removeClass("hidden"),$(".gift-item")?.addClass("loading")},open_checkout:function(){$(".cart__checkout-button").removeAttr("disabled").removeClass("loading"),$(".cart__checkout-button .loading__spinner").addClass("hidden"),$(".gift-item")?.removeClass("loading")},formatPrice(priceInCents,currencyCode,decimalDigits){const price=priceInCents/100,currencyInfo={USD:{locale:"en-US"},EUR:{locale:"de-DE"},JPY:{locale:"ja-JP"},GBP:{locale:"en-GB"},AUD:{locale:"en-AU"}},{locale}=currencyInfo[currencyCode]||currencyInfo.USD;let finalDecimalDigits;return decimalDigits!==void 0?finalDecimalDigits=decimalDigits:finalDecimalDigits=Number.isInteger(price)?0:2,new Intl.NumberFormat(locale,{style:"currency",currency:currencyCode,minimumFractionDigits:finalDecimalDigits,maximumFractionDigits:finalDecimalDigits}).format(price)},freegift_Tips_section(curr_level,subtotal_Price){let imagePath,tips_text,adding_tips,price_diff,last_point,second_point,valuenow,second_position,next_level,curr_giftName,next_giftName,curr_fullamount,next_fullamount,curr_imagePath,next_imagePath,first_point,total_Level,second_html,curr_point;if(next_level=parseInt(curr_level)+1,second_html="",first_point=custom.formatPrice(0,window.active_currency),curr_point=custom.formatPrice(subtotal_Price,window.active_currency),total_Level=parseInt(document.querySelectorAll(".fullamount-item").length),curr_level==0)curr_giftName=$(`.fullamount-item[data-level='${next_level}']`).attr("data-gift-name"),curr_fullamount=$(`.fullamount-item[data-level='${next_level}']`).attr("data-fullamount")*window.active_currency_rate,curr_imagePath=$(`.fullamount-item[data-level='${next_level}']`)?.attr("data-gift-image");else if(curr_level==total_Level){curr_fullamount=$(`.fullamount-item[data-level='${total_Level}']`).attr("data-fullamount")*window.active_currency_rate,curr_imagePath=$(`.fullamount-item[data-level='${total_Level}']`)?.attr("data-gift-image"),curr_giftName=$(`.fullamount-item[data-level='${total_Level}']`).attr("data-gift-name");for(var i=1;i${second_point}`}}else curr_giftName=$(`.fullamount-item[data-level='${curr_level}']`).attr("data-gift-name"),next_giftName=$(`.fullamount-item[data-level='${next_level}']`).attr("data-gift-name"),curr_fullamount=$(`.fullamount-item[data-level='${curr_level}']`).attr("data-fullamount")*window.active_currency_rate,next_fullamount=$(`.fullamount-item[data-level='${next_level}']`).attr("data-fullamount")*window.active_currency_rate,curr_imagePath=$(`.fullamount-item[data-level='${curr_level}']`)?.attr("data-gift-image"),next_imagePath=$(`.fullamount-item[data-level='${next_level}']`)?.attr("data-gift-image");next_level<=total_Level?subtotal_Price>=curr_fullamount?(price_diff=custom.formatPrice(next_fullamount-subtotal_Price,window.active_currency,2),imagePath=next_imagePath,tips_text=`You've unlocked free ${curr_giftName}`,adding_tips=`Add ${price_diff} to unlock free ${next_giftName}!`,second_point=custom.formatPrice(curr_fullamount,window.active_currency),second_position=curr_fullamount/next_fullamount*100-5+"%",second_html=`${second_point}`,last_point=custom.formatPrice(next_fullamount,window.active_currency,0),valuenow=subtotal_Price/next_fullamount*100+"%"):(price_diff=custom.formatPrice(curr_fullamount-subtotal_Price,window.active_currency,2),imagePath=curr_imagePath,tips_text=`Add ${price_diff} to unlock free ${curr_giftName}!`,last_point=custom.formatPrice(curr_fullamount,window.active_currency,0),valuenow=subtotal_Price/curr_fullamount*100+"%"):(imagePath=curr_imagePath,tips_text=`You've unlocked free ${curr_giftName}`,last_point=custom.formatPrice(curr_fullamount,window.active_currency,0),valuenow="100%");const htmlContent=`
${tips_text?`

${tips_text}

`:""} ${adding_tips?`

${adding_tips}

`:""}

(Only one free gift is eligible for each order, not both.)

${first_point} ${second_html?`${second_html}`:""} ${last_point}
`,dawerhtmlContent=`
${adding_tips?`

${adding_tips}

`:tips_text?`

${tips_text}

`:""}

(Only one free gift is eligible for each order)

${curr_point>=last_point?last_point:curr_point}
${first_point} ${last_point}
`;window.location.href.indexOf("/cart")>0&&$(".cart-freegift-content-2").html(htmlContent),$(".drawer-freegift-tips").html(dawerhtmlContent)},updateGift:function(gifobj){$.ajax({type:"POST",url:"/cart/update.js",data:{updates:gifobj},dataType:"json",success:function(cart){custom.updateCartContent(cart)},error:function(xhr){xhr.responseText&&console.log(xhr.responseText),window.location.reload()}})},addGift:function(giftobj){$.ajax({async:!1,type:"post",url:"/cart/add.js",data:giftobj,dataType:"json",success:function(cart){custom.updateCartContent(cart)},error:function(xhr){xhr.responseText&&console.log(xhr.responseText),window.location.reload()},complete:function(){}})},changeGift:function(giftobj){$.ajax({async:!1,type:"post",url:"/cart/change.js",data:giftobj,dataType:"json",success:function(cart){custom.updateCartContent(cart)},error:function(xhr){xhr.responseText&&console.log(xhr.responseText),window.location.reload()},complete:function(){}})},clearCart:function(){$.ajax({async:!1,type:"post",url:"/cart/clear.js",dataType:"json",success:cart=>{custom.updateCartContent(cart)},error:function(xhr,textStatus,errorMsg){xhr.responseText&&console.log(xhr.responseText),window.location.reload()},complete:function(){}})},updateCartDrawerInfo:function(){fetch(`${routes.cart_url}`).then(response=>response.text()).then(responseText=>{const html=new DOMParser().parseFromString(responseText,"text/html"),selectors=[".cart-count-bubble",".drawer__header",".sider-cart-top-count",".drawer__inner-empty","cart-drawer-items",".cart-drawer__footer",".cart-items-js-contents",".subtotal-content","#cart-empty .js-contents"];for(const selector of selectors){const targetElement=document.querySelector(selector),sourceElement=html.querySelector(selector);targetElement&&sourceElement&&targetElement.replaceWith(sourceElement)}}).catch(e=>{console.error(e),window.location.reload()})},updateCartContent:function(cart){const cartDrawerWrapper=document.querySelector("cart-drawer");let local=window.location.href;if(cart.item_count==0){if($(".cartCount").html(`${cart.item_count} item(s)`),cartDrawerWrapper&&cartDrawerWrapper.classList.toggle("is-empty",cart.item_count===0),local.indexOf("/cart")>0){const cartitemlist=document.getElementById("main-cart-items"),cartFooter=document.getElementById("main-cart-footer"),CartEmptySection=document.getElementById("cart-empty"),cartbestsellerSection=document.getElementById("cart-bestseller");cartitemlist&&cartitemlist.classList.toggle("is-empty",cart.item_count===0),cartFooter&&cartFooter.classList.toggle("is-empty",cart.item_count===0),cartbestsellerSection&&cartbestsellerSection.classList.toggle("is-empty",cart.item_count===0),CartEmptySection&&CartEmptySection.classList.toggle("hidden",cart.item_count!=0)}custom.updateCartDrawerInfo()}else custom.disable_checkout(),custom.updateCartDrawerInfo(),custom.open_checkout(),jQuery.getJSON("/cart.js",function(cart2){let idToCheck="",have_giftincartFlag=!1;if(cart2.item_count==1&&(idToCheck=String(cart2.items[0].id),have_giftincartFlag=window.full_amount_gift_group.indexOf(idToCheck)!==-1||window.designated_buy_gift_group.indexOf(idToCheck)!==-1),cart2.item_count==1&&have_giftincartFlag)custom.clearCart();else{if($(".cartCount").html(`${cart2.item_count} item(s)`),cartDrawerWrapper&&cartDrawerWrapper.classList.toggle("is-empty",cart2.item_count===0),local.indexOf("/cart")>0){const cartitemlist=document.getElementById("main-cart-items"),cartFooter=document.getElementById("main-cart-footer"),CartEmptySection=document.getElementById("cart-empty"),cartbestsellerSection=document.getElementById("cart-bestseller");cartitemlist&&cartitemlist.classList.toggle("is-empty",cart2.item_count===0),cartFooter&&cartFooter.classList.toggle("is-empty",cart2.item_count===0),cartbestsellerSection&&cartbestsellerSection.classList.toggle("is-empty",cart2.item_count===0),CartEmptySection&&CartEmptySection.classList.toggle("hidden",cart2.item_count!=0)}window.full_amount_buy_gift_function&&custom.fullamountBuyGift()}})},designatedBuyGift:function(){$(".buy-gift-item").length&&(custom.disable_checkout(),$(".buy-gift-item").each(function(){if($(this).hasClass("only-one-gift")){var designateIdArr=$(this).attr("data-id").split(","),giftId=parseInt($(this).attr("data-gift-id")),giftObj={},giftRemoveObj={},giftavailableID=parseInt($(this).attr("data-gift-variant"));if($(`cart-drawer-items .cart-items [data-product-id="${giftId}"]`).length){let tempVariantId=parseInt($(`cart-drawer-items .cart-items [data-product-id="${giftId}"]`).attr("data-idth"));tempVariantId!=giftavailableID&&(giftRemoveObj={id:tempVariantId,quantity:0})}else giftObj={id:giftavailableID,quantity:1},giftRemoveObj={id:giftavailableID,quantity:0};jQuery.getJSON("/cart.js",function(cart){var cartItems=cart.items,hadDesignated=!1,hasGift=!1,giftNums=0;if(cartItems.forEach(item=>{let itemProId=item.product_id;designateIdArr.indexOf(itemProId.toString())!=-1&&(hadDesignated=!0),itemProId==giftId&&(hasGift=!0,giftNums+=item.quantity)}),hadDesignated&&hasGift&&giftNums==1){custom.open_checkout();return}hadDesignated&&hasGift&&giftNums!=1&&(giftObj={id:giftavailableID,quantity:1},custom.changeGift(giftObj)),hadDesignated&&!hasGift&&custom.addGift(giftObj),!hadDesignated&&hasGift&&(giftRemoveObj={id:giftavailableID,quantity:0},custom.changeGift(giftRemoveObj)),!hadDesignated&&!hasGift&&custom.open_checkout()})}else{var designateIdArr=$(this).attr("data-id").split(","),giftavailableID=parseInt($(this).attr("data-gift-variant")),giftId=parseInt($(this).attr("data-gift-id")),giftObj={},giftRemoveObj={},tempObj={};jQuery.getJSON("/cart.js",function(cart){var cartItems=cart.items,designatedNums=0,giftNums=0;if(cartItems.forEach(item=>{let itemProId=item.product_id;designateIdArr.indexOf(itemProId.toString())!=-1&&(designatedNums+=item.quantity),itemProId==giftId&&(giftNums+=item.quantity)}),$(`cart-drawer-items .cart-items [data-product-id="${giftId}"]`).length){let tempVariantId=parseInt($(`cart-drawer-items .cart-items [data-product-id="${giftId}"]`).attr("data-idth"));tempVariantId!=giftavailableID?giftRemoveObj={id:tempVariantId,quantity:0}:(giftObj={id:giftavailableID,quantity:designatedNums},giftRemoveObj={id:giftavailableID,quantity:0})}else giftObj={id:giftavailableID,quantity:designatedNums},giftRemoveObj={id:giftavailableID,quantity:0};if(designatedNums==0&&giftNums==0){custom.open_checkout();return}if(designatedNums>0&&designatedNums==giftNums){custom.open_checkout();return}if(designatedNums>0&&giftNums==0&&custom.addGift(giftObj),giftNums>0&&designatedNums!=giftNums){custom.updateCartContent(cart),tempObj[giftavailableID]=designatedNums;let tempkey;$.ajax({type:"POST",url:"/cart/update.js",data:{updates:tempObj},dataType:"json",success:function(cart2){if(cart2.item_count!=0){if(cart2.items.forEach(item=>{let itemProId=item.product_id,itemdiscountprice=item.discounted_price,itemKey1=item.key;itemProId==giftId&&itemdiscountprice!=0&&(tempkey=itemKey1)}),typeof tempkey=="string"&&tempkey.length!=0){let tempobj2={id:tempkey,quantity:0};setTimeout(()=>{$.ajax({async:!1,type:"post",url:"/cart/change.js",data:tempobj2,dataType:"json",success:function(cart3){custom.updateCartContent(cart3),window.full_amount_buy_gift_function&&custom.fullamountBuyGift()},error:function(xhr){xhr.responseText&&console.log(xhr.responseText)},complete:function(){}})},100)}else custom.updateCartContent(cart2);window.full_amount_buy_gift_function&&setTimeout(()=>{custom.fullamountBuyGift()},200)}},error:function(xhr){xhr.responseText&&console.log(xhr.responseText),window.location.reload()}})}})}}))},fullamountBuyGift:function(){$(".fullamount-item").length>0&&(custom.disable_checkout(),jQuery.getJSON("/cart.js",function(cart){for(var fullamountLen=$(".fullamount-item").length,fullNTCArr=window.pro_ntc_idlist?window.pro_ntc_idlist:[],fullGiftIdArr=[],giftInCartArr=[],subtotalPrice=0,currlevel=0,cartItems=cart.items,hasGift=!1,idToCheck2="",temp_key,i=0;i{fullGiftIdArr.indexOf(item.product_id)==-1&&fullNTCArr.indexOf(item.product_id)==-1&&(subtotalPrice+=item.final_line_price),fullGiftIdArr.indexOf(item.product_id)!=-1&&(hasGift=!0,giftInCartArr.push(item.product_id))}),$(".fullamount-item").each(function(){let tempPrice=parseInt($(this).attr("data-fullamount"))*window.active_currency_rate;subtotalPrice>=tempPrice&&(currlevel=parseInt($(this).attr("data-level")))}),cart.items.length==1&&hasGift)custom.clearCart();else if(currlevel>0)if(hasGift){var fullgiftId=parseInt($(`.fullamount-item[data-level="${currlevel}"]`).attr("data-gift-id")),fullgiftAvaiId=$(`.fullamount-item[data-level="${currlevel}"]`).attr("data-gift-variant"),fullupdatesObj={};if(giftInCartArr.forEach(function(giftInCartId){if(giftInCartId!=fullgiftId&&$(`cart-drawer-items .cart-items [data-product-id="${giftInCartId}"]`).length){let tempVariantId=parseInt($(`cart-drawer-items .cart-items [data-product-id="${giftInCartId}"]`).attr("data-idth"));tempVariantId!=fullgiftAvaiId&&(fullupdatesObj[tempVariantId]=0)}}),cart.items.forEach(item=>{let itemProId=item.variant_id,itemdiscountprice=item.discounted_price,itemKey1=item.key;itemProId==fullgiftAvaiId&&itemdiscountprice!=0&&(temp_key=itemKey1)}),typeof temp_key=="string"&&temp_key.length!=0){let tempobj={id:temp_key,quantity:0};$.ajax({async:!1,type:"post",url:"/cart/change.js",data:tempobj,dataType:"json",success:function(cart2){custom.updateCartContent(cart2)},error:function(xhr){xhr.responseText&&console.log(xhr.responseText)},complete:function(){}})}else giftInCartArr.indexOf(fullgiftId)==-1&&(fullupdatesObj[fullgiftAvaiId]=1,custom.updateGift(fullupdatesObj))}else{var fullgiftAvaiId=$(`.fullamount-item[data-level="${currlevel}"]`).attr("data-gift-variant");fullgiftObj={id:fullgiftAvaiId,quantity:1},custom.addGift(fullgiftObj)}else if(currlevel==0&&hasGift&&giftInCartArr.length>0){let fullupdatesObj2={};giftInCartArr.forEach(function(giftInCartId){if($(`cart-drawer-items .cart-items [data-product-id="${giftInCartId}"]`).length){let tempVariantId=parseInt($(`cart-drawer-items .cart-items [data-product-id="${giftInCartId}"]`).attr("data-idth"));tempVariantId!=fullgiftAvaiId&&(fullupdatesObj2[tempVariantId]=0)}}),console.log(fullupdatesObj2),custom.updateGift(fullupdatesObj2)}else currlevel==0&&!hasGift&&giftInCartArr.length==0&&window.designated_buy_gift_function==!0&&(cart.item_count==1&&(idToCheck2=String(cart.items[0].id)),cart.item_count==1&&window.designated_buy_gift_group.indexOf(idToCheck2)!==-1&&custom.clearCart());custom.open_checkout(),custom.freegift_Tips_section(currlevel,subtotalPrice)}))}}})(jQuery); //# sourceMappingURL=/cdn/shop/t/106/assets/cart-gift.js.map?v=164092368233191087061755659349