"use strict";(self.webpackChunkui=self.webpackChunkui||[]).push([[47],{496:(i,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.usePromotionBanner=void 0;const o=t(3);e.usePromotionBanner=({promoGiftWithPurchaseData:i,total_price:e,isMobile:t,isInCart:a=!1,addToCartWithPayload:n,promoItemsInCart:r,isFirstSync:d,currencyCode:l,totalPriceToDisplay:c,addGWPProductToList:s})=>{var u,v,p,T,P,m,g;try{if(!i||!s)throw new Error("no promo data");const b=i.cards.map((i=>{var e;return null!==(e=null==i?void 0:i.tier)&&void 0!==e?e:0})),h={tierOne:b[0],tierTwo:b[1],tierThree:b[2],currentPrice:null!==(u=Math.floor(e))&&void 0!==u?u:0,currentDisplayPrice:"",isNotUsdPrice:"USD"!==l,isMobile:t},[y,C]=(0,o.useState)(i.cards),[f,j]=(0,o.useState)(h),O=null===(v=null==i?void 0:i.cards)||void 0===v?void 0:v.map((i=>i.addToCartPayload)),w=null===(p=null==i?void 0:i.cards)||void 0===p?void 0:p.findIndex((i=>"blendjet-2"===i.addToCartPayload[0].product.handle)),S=null===(T=null==i?void 0:i.cards)||void 0===T?void 0:T[w],k=null===(P=i.bj2SimplifiedProduct)||void 0===P?void 0:P.variants,[D,L]=(0,o.useState)(null==k?void 0:k.find((i=>i.id===(null==S?void 0:S.addToCartPayload[0].variant.id)))),I=null!==(m=null==k?void 0:k.map((i=>i.id)))&&void 0!==m?m:[],[B,$]=(0,o.useState)(!1),x=()=>{if($(!1),!S||!D)return;s({product:Object.assign(Object.assign({},S.addToCartPayload[0]),{variant:D}),gwpData:{minTotal:S.tier,tierIndex:w}});const i=new Date;i.setHours(i.getHours()+24);const e=i.toUTCString();document.cookie=`bonus_products=${[null==D?void 0:D.id].join("|")}*ONE*${b[w]}; expires=${e}; path=/`},M=i=>{var e,t,o,a,n;if("blendjet-2"===O[i][0].product.handle)return void $(!0);s({product:O[i][0],gwpData:{minTotal:b[i],tierIndex:i}});const r=null!==(n=null===(a=null===(o=null===(t=null===(e=y[i])||void 0===e?void 0:e.addToCartPayload)||void 0===t?void 0:t[0])||void 0===o?void 0:o.variant)||void 0===a?void 0:a.id)&&void 0!==n?n:"",d=new Date;d.setHours(d.getHours()+24);const l=d.toUTCString();document.cookie=`bonus_products=${[r].join("|")}*ONE*${b[i]}; expires=${l}; path=/`};(0,o.useEffect)((()=>{var t;const o=I.find((i=>r.includes(i)));if(o&&o!=(null==D?void 0:D.id)){const i=null==k?void 0:k.find((i=>i.id===o));if(!i)return;L(i)}const n=i.cards.some((i=>i.ctaTopLineTwo.length>4)),l=null===(t=null==i?void 0:i.cards)||void 0===t?void 0:t.map(((i,t)=>{var o,l,c;const s=t===w&&null!==(o=null==D?void 0:D.cartImage.src)&&void 0!==o?o:i.imageSrc;return a?{ctaTopLineOne:n?i.ctaTopLineOne:`${i.ctaTopLineOne} ${i.ctaTopLineTwo}`,ctaTopLineTwo:n?i.ctaTopLineTwo:"",ctaBottomLineTwo:`${i.ctaBottomLineTwo}`,ctaBottomLineOne:"",imageSrc:s,active:e>=i.tier,checked:d?i.checked:t===w?r.includes(null!==(l=null==D?void 0:D.id)&&void 0!==l?l:""):r.includes(i.addToCartPayload[0].variant.id),tier:i.tier,addToCartPayload:i.addToCartPayload,onClick:()=>M(t),cardsVersion:i.cardsVersion}:Object.assign(Object.assign({},i),{addToCartPayload:t===w&&D?[Object.assign(Object.assign({},i.addToCartPayload[0]),{variant:D})]:i.addToCartPayload,imageSrc:s,checked:d?i.checked:t===w?r.includes(null!==(c=null==D?void 0:D.id)&&void 0!==c?c:""):r.includes(i.addToCartPayload[0].variant.id),active:e>=i.tier,onClick:()=>M(t)})}));if(d&&!a){const i=l.findIndex((i=>i.checked));i>-1&&s({product:O[i][0],gwpData:{minTotal:b[i],tierIndex:i}})}C(l),j((i=>Object.assign(Object.assign({},i),{currentPrice:Math.floor(e),currentDisplayPrice:null==c?void 0:c.split(".")[0]})))}),[e,c,r[0]]);const V=i=>{var e;if("decrement"===i&&s(null),"increment"===i){const i=y.findIndex((i=>i.checked));if(-1===i)return;const t=i===w?Object.assign(Object.assign({},S.addToCartPayload[0]),{variant:null!=D?D:null===(e=null==S?void 0:S.addToCartPayload[0])||void 0===e?void 0:e.variant,properties:{}}):O[i];n(Array.isArray(t)?t.map((i=>Object.assign(Object.assign({},i),{properties:{}}))):t)}};return{title:a&&i.subtitle?i.subtitle:null!==(g=null==i?void 0:i.title)&&void 0!==g?g:"",cards:y,priceSlider:f,bj2Variants:k,currentBj2Variant:D,showBj2Selector:B,handleBj2VariantAdd:x,setCurrentBj2Variant:L,handleGWPQuantityChange:V}}catch(i){return"no promo data"!=(null==i?void 0:i.message)&&console.log("error on gwp banner"),{title:"",cards:[],priceSlider:{currentPrice:0,currentDisplayPrice:"",isNotUsdPrice:!1,tierOne:0,tierTwo:0,tierThree:0,isMobile:!1}}}}}}]);