class Confetti{confettiInterval=null;containerEl=null;confettiColors=["#EF2964","#00C09D","#2D87B0","#48485E","#EFFF1D"];confettiAnimations=["slow","medium","fast"];timeRun=0;constructor(t){t&&(this.container=t,this.setupElement(),this.render())}setupElement=()=>{if(!this.container)return;const t=document.createElement("div"),e=this.container.style.position;"relative"===e&&"absolute"===e||(this.container.style.position="relative"),t&&t.classList.add("confetti-container"),this.container.appendChild(t),this.containerEl=t};stopConfetti=()=>{clearInterval(this.confettiInterval),setTimeout((()=>this.containerEl.remove()),1500)};render=()=>{this.confettiInterval=setInterval((()=>{this.timeRun+=1,this.timeRun>=160&&this.stopConfetti();const t=document.createElement("div"),e=Math.floor(3*Math.random())+7+"px",s=this.confettiColors[Math.floor(Math.random()*this.confettiColors.length)],i=Math.floor(Math.random()*this.container.offsetWidth)+"px",o=this.confettiAnimations[Math.floor(Math.random()*this.confettiAnimations.length)];t.classList.add("confetti","confetti--animation-"+o),t.style.left=i,t.style.width=e,t.style.height=e,t.style.backgroundColor=s,t.removeTimeout=setTimeout((function(){t.parentNode.removeChild(t)}),3e3),this.containerEl.appendChild(t)}),20)}}customElements.define("foxkit-cart-goal",class extends HTMLElement{constructor(){super(),this.selectors={cartContainer:".scd__content, cart-items",cartFooter:"#main-cart-footer, .cart-footer, .cart__footer, .sf-cart__summary",cartSubtotal:"[data-cart-subtotal], .cart__footer .totals, #main-cart-footer .totals",shippingNote:"[data-shipping-note], .tax-note",title:".foxkit-cartgoal__title",progressBar:"[data-progress]",goalLeft:"[data-goal-left]",icon:".foxkit-cartgoal__icon"},this.classes={hidden:"!foxkit-hidden",hasGoal:"scd--has-cartgoal",done:"foxkit-cartgoal--done"},this.defaultIcon='',this.doneIcon='',this.progress=0,this.goalDone=!1,this.enabled=!0,this.settings=window.FoxKitPlugins.CartGoal,this.goal=Number(this.settings.goal_amount)*Number(window.Shopify.currency.rate||1)||0,this.reached_message=window.__i18n.transPlugin({configs:this.settings,key:"message_reached"}),this.message=window.__i18n.transPlugin({configs:this.settings,key:"message"})}connectedCallback(){if(!window.FoxKitThemeHelperEnabled)return;this.dataset.plugin="CartGoal",this.classList.add("foxkit-cartgoal","!foxkit-hidden"),this.domNodes=window.FoxKitV2.Utils.queryDomNodes(this.selectors,this);const t=this.closest(this.selectors.cartContainer),e=document.querySelector(this.selectors.cartFooter);t&&t.classList.add(this.classes.hasGoal),e&&(this.shippingNote=e.querySelector(this.selectors.shippingNote),this.cartSubtotal=e.querySelector(this.selectors.cartSubtotal)),this.confettiShow=this.goalDone,this.cacheShowKey="_foxKit_reachedGoal",this.triggerEvent=!1,this.renderShippingBadge(),this.updateProgress(),window.FoxkitEvents.subscribe("ON_FOXKIT_CART_UPDATE",(t=>this.handleChange(t))),this.querySelector(this.selectors.progressBar)||this.renderTemplate()}disconnectedCallback(){window.FoxkitEvents.unSubscribe("ON_FOXKIT_CART_UPDATE",(t=>this.handleChange(t)))}renderTemplate(){this.innerHTML=`

${this.message.replace("{{variable}}",`${this.settings?.goal_amount||0}`)}

\n
\n
\n \n
\n ${this.defaultIcon}\n
`}async updateProgress(t){t||(t=await window.FoxKitV2.getCart()),this.enabled=t.requires_shipping;const e=t._foxCartPrices?t._foxCartPrices.total_price:t.total_price;this.goalLeft=100*this.goal-e,this.progress=this.goalLeft>0?e/this.goal:100,this.goalDone=this.goalLeft<=0,this.goalTitle=this.goalDone?this.reached_message:this.message,this.domNodes.icon&&(this.domNodes.icon.innerHTML=this.goalDone?this.doneIcon:this.defaultIcon),this.style.setProperty("--progress",this.progress+"%"),this.goalTitle=this.goalTitle.replace("{{variable}}",`${FoxKitV2.Utils.formatMoney(this.goalLeft,FoxKitSettings.moneyFormat)}`),setTimeout((()=>{const t=this.goalDone?"add":"remove";this.querySelector(this.selectors.title).innerHTML=this.goalTitle,this.classList[t](this.classes.done)}),500),this.setDone(),this.enabled?(this.classList.remove(this.classes.hidden),this.removeAttribute("hidden")):(this.setAttribute("hidden",""),this.classList.add(this.classes.hidden),this.freeBadge&&this.freeBadge.remove())}handleChange(t){this.domNodes=FoxKitV2.Utils.queryDomNodes(this.selectors),this.updateProgress(t);const e=this.goalDone?"add":"remove";this.classList[e]("shakeY"),this.goalLeft<=0?(this.triggerEvent||(publishWebPixelsEvent({plugin:"CartGoal",pluginId:this.settings._id},WEB_PIXELS_EVENT.REACHED_GOAL),this.triggerEvent=!0),this.showConfetti()):(this.triggerEvent=!1,this.confettiShow=!1,window.FoxKitV2.Utils.setSessionStorage(this.cacheShowKey,!1))}setDone(){this.freeBadge&&this.freeBadge.remove(),this.shippingNote&&this.shippingNote.classList.remove(this.classes.hidden),this.goalDone&&this.enabled?(window.FoxKitV2.freeShip=!0,this.addShippingNote()):window.FoxKitV2.freeShip=!1}showConfetti(){const t=window.FoxKitV2.Utils.getSessionStorage(this.cacheShowKey);!this.enabled||this.confettiShow||t||(window.FoxKitV2.Utils.setSessionStorage(this.cacheShowKey,this.settings._id),new Confetti(document.querySelector(this.selectors.cartContainer)),this.confettiShow=!0)}renderShippingBadge(){this.freeBadge=document.createElement("div"),this.freeBadge.classList.add("foxkit-cartgoal-free-shipping","flex","justify-between","items-center"),this.freeBadge.innerHTML=`${window.__i18n.tr("shipping_label")} ${window.__i18n.tr("free")}`}addShippingNote=()=>{this.cartSubtotal&&this.domNodes.cartSubtotal.before(this.freeBadge),this.shippingNote&&this.shippingNote.classList.add(this.classes.hidden)}});