{
  "version": 3,
  "sources": ["/cdn/shop/t/1/assets/price-per-item.js?v=115937180292451397851787334881"],
  "sourcesContent": ["import { Component } from '@theme/component';\nimport { ThemeEvents } from '@theme/events';\nimport { StandardEvents } from '@shopify/events';\n\n/**\n * Displays dynamic per-item pricing based on quantity and volume pricing tiers.\n * Updates automatically when quantity changes or cart is updated.\n *\n * @typedef {Object} PriceBreak\n * @property {number} quantity - Minimum quantity for this price tier\n * @property {string} price - Formatted price string (e.g., \"$9.50 USD\")\n *\n * @typedef {Object} PricePerItemRefs\n * @property {HTMLElement} [pricePerItemText] - The text element displaying the price\n *\n * @extends {Component<PricePerItemRefs>}\n */\nclass PricePerItemComponent extends Component {\n  /** @type {PriceBreak[]} */\n  #priceBreaks = [];\n  #abortController = new AbortController();\n\n  connectedCallback() {\n    super.connectedCallback();\n    this.#parsePriceBreaks();\n    this.#attachEventListeners();\n    this.#updatePriceDisplay();\n  }\n\n  disconnectedCallback() {\n    super.disconnectedCallback();\n    this.#abortController.abort();\n  }\n\n  /**\n   * Parses price breaks from data attributes\n   */\n  #parsePriceBreaks() {\n    const minQuantity = parseInt(this.dataset.minQuantity || '') || 1;\n    const { variantPrice, priceBreaks: priceBreaksData } = this.dataset;\n\n    // Start with base price tier\n    if (variantPrice) {\n      this.#priceBreaks.push({ quantity: minQuantity, price: variantPrice });\n    }\n\n    // Parse additional price breaks from JSON array\n    if (priceBreaksData) {\n      const breaks = JSON.parse(priceBreaksData);\n      for (const { quantity, price } of breaks) {\n        if (quantity && price) {\n          this.#priceBreaks.push({ quantity: parseInt(quantity), price });\n        }\n      }\n    }\n\n    // Sort by quantity descending for efficient lookup\n    this.#priceBreaks.sort((a, b) => b.quantity - a.quantity);\n  }\n\n  /**\n   * Attaches event listeners for quantity and cart updates\n   */\n  #attachEventListeners() {\n    const { signal } = this.#abortController;\n\n    // Listen on document to catch all events (more reliable than form-only)\n    document.addEventListener(ThemeEvents.quantitySelectorUpdate, this.#handleQuantityUpdate, { signal });\n    document.addEventListener(StandardEvents.cartLinesUpdate, this.#handleCartUpdate, { signal });\n  }\n\n  /**\n   * Handles quantity selector updates\n   * @param {Event} event\n   */\n  #handleQuantityUpdate = (event) => {\n    // Only respond to updates for our variant's quantity selector\n    const form = this.closest('product-form-component');\n    if (!form || !(event.target instanceof Node) || !form.contains(event.target)) return;\n\n    this.#updatePriceDisplay();\n  };\n\n  /**\n   * Handles cart updates by refreshing display after the cart response resolves,\n   * so data-cart-quantity is up-to-date when we recalculateo.\n   * @param {import('@shopify/events').CartLinesUpdateEvent} event\n   */\n  #handleCartUpdate = (event) => {\n    event.promise\n      ?.then(() => this.#updatePriceDisplay())\n      .catch((error) => {\n        if (error?.name !== 'AbortError') console.warn('[price-per-item] Cart update promise rejected:', error);\n      });\n  };\n\n  /**\n   * Gets the total quantity (cart + current input value)\n   * @returns {number}\n   */\n  #getCurrentQuantity() {\n    const form = this.closest('product-form-component');\n    const quantityInput = /** @type {HTMLInputElement | null} */ (form?.querySelector('input[name=\"quantity\"]'));\n    if (!quantityInput) return 1;\n\n    // Read the current cart quantity from the data attribute\n    const cartQty = parseInt(quantityInput.getAttribute('data-cart-quantity') || '0') || 0;\n    // Read the current input value (quantity to add)\n    const inputQty = parseInt(quantityInput.value) || 1;\n\n    return cartQty + inputQty;\n  }\n\n  /**\n   * Updates the price display based on current quantity\n   */\n  updatePriceDisplay() {\n    if (!this.#priceBreaks.length || !this.refs.pricePerItemText) return;\n\n    const quantity = this.#getCurrentQuantity();\n\n    // Price breaks are sorted descending, find first tier that quantity qualifies for\n    const priceBreak =\n      this.#priceBreaks.find((pb) => quantity >= pb.quantity) ?? this.#priceBreaks[this.#priceBreaks.length - 1];\n\n    if (priceBreak) {\n      this.refs.pricePerItemText.innerHTML = `${this.dataset.atText} ${priceBreak.price}/${this.dataset.eachText}`;\n    }\n  }\n\n  /**\n   * Private wrapper for event handlers\n   */\n  #updatePriceDisplay = () => {\n    this.updatePriceDisplay();\n  };\n}\n\nif (!customElements.get('price-per-item')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