import{Component}from"@theme/component";import{onAnimationEnd}from"@theme/utilities";import{ThemeEvents}from"@theme/events";class CartIcon extends Component{requiredRefs=["cartBubble","cartBubbleText"];get currentCartCount(){return parseInt(this.refs.cartBubbleText.textContent??"0",10)}set currentCartCount(value){this.refs.cartBubbleText.textContent=value<100?String(value):""}connectedCallback(){super.connectedCallback(),document.addEventListener(ThemeEvents.cartUpdate,this.onCartUpdate),this.ensureCartBubbleIsCorrect()}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(ThemeEvents.cartUpdate,this.onCartUpdate)}onCartUpdate=async event=>{const itemCount=event.detail.data?.itemCount??0,comingFromProductForm=event.detail.data?.source==="product-form-component";this.renderCartBubble(itemCount,comingFromProductForm)};renderCartBubble=async(itemCount,comingFromProductForm,animate=!0)=>{this.refs.cartBubble.classList.toggle("visually-hidden",itemCount===0),this.refs.cartBubble.classList.toggle("cart-bubble--animating",itemCount>0&&animate),this.currentCartCount=comingFromProductForm?this.currentCartCount+itemCount:itemCount,this.classList.toggle("header-actions__cart-icon--has-cart",itemCount>0),sessionStorage.setItem("cart-count",JSON.stringify({value:String(this.currentCartCount),timestamp:Date.now()})),animate&&(await onAnimationEnd(this.refs.cartBubbleText),this.refs.cartBubble.classList.remove("cart-bubble--animating"))};ensureCartBubbleIsCorrect=()=>{const sessionStorageCount=sessionStorage.getItem("cart-count"),visibleCount=this.refs.cartBubbleText.textContent;if(!(sessionStorageCount===visibleCount||sessionStorageCount===null))try{const{value,timestamp}=JSON.parse(sessionStorageCount);if(Date.now()-timestamp<1e4){const count=parseInt(value,10);count>=0&&this.renderCartBubble(count,!1,!1)}}catch{}}}customElements.get("cart-icon")||customElements.define("cart-icon",CartIcon);
//# sourceMappingURL=/s/files/1/0677/1399/0759/t/1/assets/cart-icon.js.map?v=1783128459
