{
  "version": 3,
  "sources": ["/cdn/shop/t/125/assets/component-cart-quantity-selector.js?chv=2"],
  "sourcesContent": ["import { QuantitySelectorComponent } from '@theme/component-quantity-selector';\n\n/**\n * A custom element that allows the user to select a quantity in the cart.\n * Extends QuantitySelectorComponent but uses absolute max limits instead of effective max.\n * Semantics: \"What should the total quantity BE in the cart\" vs \"How many to ADD to cart\"\n *\n * @extends {QuantitySelectorComponent}\n */\nclass CartQuantitySelectorComponent extends QuantitySelectorComponent {\n  limitMessageTimer;\n\n  disconnectedCallback() {\n    clearTimeout(this.limitMessageTimer);\n    super.disconnectedCallback();\n  }\n\n  /**\n   * Gets the effective maximum value for cart quantity selector\n   * Cart page: uses absolute max (how much can be in cart total)\n   * @returns {number | null} The effective max, or null if no max\n   */\n  getEffectiveMax() {\n    const { max, cartQuantity, value } = this.getCurrentValues();\n    if (max === null) return null;\n    if (!this.dataset.quantityLimit) return max;\n\n    const otherProductQuantity = Math.max(cartQuantity - value, 0);\n    return Math.max(max - otherProductQuantity, 0);\n  }\n\n  /**\n   * Updates button states based on current value and limits\n   * Cart buttons are always managed client-side, never server-disabled\n   */\n  updateButtonStates() {\n    const { minusButton, plusButton } = this.refs;\n    const { min, value } = this.getCurrentValues();\n    const effectiveMax = this.getEffectiveMax();\n    const canRemove = this.dataset.canRemove !== 'false';\n    const shouldRemove = value <= 1 && canRemove;\n\n    this.dataset.decreaseAction = shouldRemove ? 'remove' : 'decrease';\n    minusButton.classList.toggle('quantity-minus--remove', shouldRemove);\n    minusButton.setAttribute(\n      'aria-label',\n      shouldRemove\n        ? minusButton.dataset.cartRemoveLabel || 'Remove item'\n        : minusButton.dataset.cartDecreaseLabel || 'Decrease quantity'\n    );\n\n    // Keep the left control available at quantity 1 so it can remove the line.\n    minusButton.disabled = this.serverDisabledMinus || value <= 0 || (value <= min && !canRemove);\n    const canExplainLimitAttempt = Boolean(this.dataset.quantityLimit && this.closest('.cart-drawer'));\n    plusButton.disabled =\n      this.serverDisabledPlus ||\n      (effectiveMax !== null && value >= effectiveMax && !canExplainLimitAttempt);\n  }\n\n  showLimitMessage() {\n    if (!this.closest('.cart-drawer')) return;\n\n    const message = this.parentElement?.querySelector('.ch-quantity-limit-message');\n    if (!(message instanceof HTMLElement)) return;\n\n    message.classList.add('is-visible');\n    clearTimeout(this.limitMessageTimer);\n    this.limitMessageTimer = setTimeout(() => message.classList.remove('is-visible'), 4000);\n  }\n\n  hideLimitMessage() {\n    const message = this.parentElement?.querySelector('.ch-quantity-limit-message');\n    if (message instanceof HTMLElement) message.classList.remove('is-visible');\n    clearTimeout(this.limitMessageTimer);\n  }\n\n  increaseQuantity(event) {\n    if (!(event.target instanceof HTMLElement)) return;\n\n    const { step, value } = this.getCurrentValues();\n    const effectiveMax = this.getEffectiveMax();\n    if (effectiveMax !== null && value + step > effectiveMax) {\n      event.preventDefault();\n      this.showLimitMessage();\n      return;\n    }\n\n    this.hideLimitMessage();\n    super.increaseQuantity(event);\n  }\n\n  setQuantity(event) {\n    if (!(event.target instanceof HTMLInputElement)) return;\n\n    const effectiveMax = this.getEffectiveMax();\n    const exceedsMaximum = effectiveMax !== null && Number(event.target.value) > effectiveMax;\n    super.setQuantity(event);\n\n    if (exceedsMaximum) {\n      this.showLimitMessage();\n    } else {\n      this.hideLimitMessage();\n    }\n  }\n\n  /**\n   * Removes the cart line at quantity 1, otherwise decreases as usual.\n   * @param {Event} event - The event.\n   */\n  decreaseQuantity(event) {\n    if (!(event.target instanceof HTMLElement)) return;\n    event.preventDefault();\n    this.hideLimitMessage();\n\n    const { quantityInput } = this.refs;\n    const { value } = this.getCurrentValues();\n\n    if (value <= 1 && this.dataset.canRemove !== 'false') {\n      quantityInput.value = '0';\n      this.onQuantityChange();\n      this.updateButtonStates();\n      return;\n    }\n\n    this.updateQuantity(-1);\n  }\n}\n\nif (!customElements.get('cart-quantity-selector-component')) {\n  customElements.define('cart-quantity-selector-component', CartQuantitySelectorComponent);\n}\n"],
  "mappings": "AAAA,OAAS,8BAAiC,q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