{
  "version": 3,
  "sources": ["/cdn/shop/t/1/assets/cart-icon.js?v=157241182139685326961768528522"],
  "sourcesContent": ["import { Component } from '@theme/component';\nimport { onAnimationEnd } from '@theme/utilities';\nimport { ThemeEvents, CartUpdateEvent } from '@theme/events';\n\n/**\n * A custom element that displays a cart icon.\n *\n * @typedef {object} Refs\n * @property {HTMLElement} cartBubble - The cart bubble element.\n * @property {HTMLElement} cartBubbleText - The cart bubble text element.\n * @property {HTMLElement} cartBubbleCount - The cart bubble count element.\n *\n * @extends {Component<Refs>}\n */\nclass CartIcon extends Component {\n  requiredRefs = ['cartBubble', 'cartBubbleText', 'cartBubbleCount'];\n\n  /** @type {number} */\n  get currentCartCount() {\n    return parseInt(this.refs.cartBubbleCount.textContent ?? '0', 10);\n  }\n\n  set currentCartCount(value) {\n    this.refs.cartBubbleCount.textContent = value < 100 ? String(value) : '';\n  }\n\n  connectedCallback() {\n    super.connectedCallback();\n\n    document.addEventListener(ThemeEvents.cartUpdate, this.onCartUpdate);\n    window.addEventListener('pageshow', this.onPageShow);\n    this.ensureCartBubbleIsCorrect();\n  }\n\n  disconnectedCallback() {\n    super.disconnectedCallback();\n\n    document.removeEventListener(ThemeEvents.cartUpdate, this.onCartUpdate);\n    window.removeEventListener('pageshow', this.onPageShow);\n  }\n\n  /**\n   * Handles the page show event when the page is restored from cache.\n   * @param {PageTransitionEvent} event - The page show event.\n   */\n  onPageShow = (event) => {\n    if (event.persisted) {\n      this.ensureCartBubbleIsCorrect();\n    }\n  };\n\n  /**\n   * Handles the cart update event.\n   * @param {CartUpdateEvent} event - The cart update event.\n   */\n  onCartUpdate = async (event) => {\n    const itemCount = event.detail.data?.itemCount ?? 0;\n    const comingFromProductForm = event.detail.data?.source === 'product-form-component';\n\n    this.renderCartBubble(itemCount, comingFromProductForm);\n  };\n\n  /**\n   * Renders the cart bubble.\n   * @param {number} itemCount - The number of items in the cart.\n   * @param {boolean} comingFromProductForm - Whether the cart update is coming from the product form.\n   */\n  renderCartBubble = async (itemCount, comingFromProductForm, animate = true) => {\n    // If the cart update is coming from the product form, we add to the current cart count, otherwise we set the new cart count\n\n    this.refs.cartBubbleCount.classList.toggle('hidden', itemCount === 0);\n    this.refs.cartBubble.classList.toggle('visually-hidden', itemCount === 0);\n\n    this.currentCartCount = comingFromProductForm ? this.currentCartCount + itemCount : itemCount;\n\n    this.classList.toggle('header-actions__cart-icon--has-cart', itemCount > 0);\n\n    sessionStorage.setItem(\n      'cart-count',\n      JSON.stringify({\n        value: String(this.currentCartCount),\n        timestamp: Date.now(),\n      })\n    );\n\n    if (!animate || itemCount === 0) return;\n\n    // Ensure element is visible before starting animation\n    // Use requestAnimationFrame to ensure the browser sees the state change\n    await new Promise((resolve) => requestAnimationFrame(resolve));\n\n    this.refs.cartBubble.classList.add('cart-bubble--animating');\n    await onAnimationEnd(this.refs.cartBubbleText);\n\n    this.refs.cartBubble.classList.remove('cart-bubble--animating');\n  };\n\n  /**\n   * Checks if the cart count is correct.\n   */\n  ensureCartBubbleIsCorrect = () => {\n    // Ensure refs are available\n    if (!this.refs.cartBubbleCount) return;\n\n    const sessionStorageCount = sessionStorage.getItem('cart-count');\n\n    // If no session storage data, nothing to check\n    if (sessionStorageCount === null) return;\n\n    const visibleCount = this.refs.cartBubbleCount.textContent;\n\n    try {\n      const { value, timestamp } = JSON.parse(sessionStorageCount);\n\n      // Check if the stored count matches what's visible\n      if (value === visibleCount) return;\n\n      // Only update if timestamp is recent (within 10 seconds)\n      if (Date.now() - timestamp < 10000) {\n        const count = parseInt(value, 10);\n\n        if (count >= 0) {\n          this.renderCartBubble(count, false, false);\n        }\n      }\n    } catch (_) {\n      // no-op\n    }\n  };\n}\n\nif (!customElements.get('cart-icon')) {\n  customElements.define('cart-icon', CartIcon);\n}\n"],
  "mappings": "AAAA,OAAS,cAAiB,mBAC1B,OAAS,mBAAsB,mBAC/B,OAAS,gBAAoC,gBAY7C,MAAM,iBAAiB,SAAU,CAC/B,aAAe,CAAC,aAAc,iBAAkB,i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