{
  "version": 3,
  "sources": ["/cdn/shop/t/66/assets/search-form.js?cb=16427"],
  "sourcesContent": ["/* global debounce */\n\nif (!customElements.get('search-form')) {\n  class SearchForm extends HTMLElement {\n    constructor() {\n      super();\n      this.input = this.querySelector('.js-search-input');\n      this.productTypeSelect = this.querySelector('.js-search-product-types');\n      this.productTypeInput = document.getElementById('product_type_input');\n      this.resetBtn = this.querySelector('.js-search-reset');\n      this.addListeners();\n      this.init();\n    }\n\n    addListeners() {\n      this.input.addEventListener('input', debounce(this.handleInput.bind(this)));\n      if (this.productTypeSelect) {\n        this.productTypeSelect.addEventListener('change', this.handleProductTypeChange.bind(this));\n      }\n      this.resetBtn.addEventListener('click', this.handleReset.bind(this));\n    }\n\n    init() {\n      if ((this.input.dataset.placeholderTwo || this.input.dataset.placeholderThree)\n        && (this.input.dataset.placeholderPromptsMob === 'true' || theme.mediaMatches.md)) {\n        this.typeInPlaceholders();\n      }\n    }\n\n    /**\n     * Simulates the placeholder titles being typed in and the previous one deleted, on repeat\n     */\n    typeInPlaceholders() {\n      const typingSpeed = this.input.dataset.typingSpeed || 100;\n      const deletingSpeed = this.input.dataset.deletingSpeed || 60;\n      const delayAfterDeleting = this.input.dataset.delayAfterDeleting || 500;\n      const delayBeforeFirstDelete = this.input.dataset.delayBeforeFirstDelete || 2000;\n      const delayAfterWordTyped = this.input.dataset.delayAfterWordTyped || 2400;\n      const placeholders = [];\n\n      if (this.input.placeholder) {\n        placeholders.push(this.input.placeholder);\n      }\n\n      if (this.input.dataset.placeholderTwo) {\n        placeholders.push(this.input.dataset.placeholderTwo);\n      }\n\n      if (this.input.dataset.placeholderThree) {\n        placeholders.push(this.input.dataset.placeholderThree);\n      }\n\n      const typeInNextPlaceholder = async (placeholder) => {\n        await new Promise((resolve) => {\n          let currentPlaceholder = this.input.getAttribute('placeholder');\n\n          // If necessary remove the start of the word to type in if it already exists in the\n          // placeholder\n          let nextPlaceholder = (currentPlaceholder.length >= 3\n              && placeholder.startsWith(currentPlaceholder))\n            ? placeholder.replace(currentPlaceholder, '')\n            : placeholder;\n\n          const typingIntervalId = setInterval(() => {\n            currentPlaceholder = this.input.getAttribute('placeholder');\n            this.input.setAttribute('placeholder', currentPlaceholder + nextPlaceholder.charAt(0));\n            if (nextPlaceholder.length === 1) {\n              resolve();\n              clearInterval(typingIntervalId); // Stop typing\n            } else {\n              nextPlaceholder = nextPlaceholder.substring(1);\n            }\n          }, typingSpeed);\n        });\n      };\n\n      const deleteCurrentPlaceholder = async (nextPlaceholder) => {\n        await new Promise((resolve) => {\n          let prevPlaceholder = this.input.getAttribute('placeholder');\n          const deletionIntervalId = setInterval(() => {\n            const newPlaceholder = prevPlaceholder.substring(0, prevPlaceholder.length - 1);\n            this.input.setAttribute('placeholder', newPlaceholder);\n            prevPlaceholder = newPlaceholder;\n            if (prevPlaceholder.length === 0\n              || (prevPlaceholder.length >= 3 && nextPlaceholder.startsWith(prevPlaceholder))) {\n              resolve();\n              clearInterval(deletionIntervalId);\n            }\n          }, deletingSpeed);\n        });\n      };\n\n      let startIndex = 0;\n      const showNextPlaceholder = () => {\n        startIndex = (startIndex + 1) % placeholders.length;\n        const nextPlaceholder = placeholders[startIndex];\n        deleteCurrentPlaceholder.call(this, nextPlaceholder).then(() => {\n          setTimeout(() => {\n            typeInNextPlaceholder.call(this, nextPlaceholder).then(() => {\n              setTimeout(showNextPlaceholder.bind(this), delayAfterWordTyped);\n            });\n          }, delayAfterDeleting);\n        });\n      };\n\n      setTimeout(showNextPlaceholder.bind(this), delayBeforeFirstDelete);\n    }\n\n    /**\n     * Handles 'input' events on the search field.\n     */\n    handleInput() {\n      if (this.input.value.length > 0) {\n        this.input.classList.add('search__input--dirty');\n      } else {\n        this.input.classList.remove('search__input--dirty');\n      }\n    }\n\n    /**\n     * Handles a change of product type\n     * @param {object} evt - Event object.\n     */\n    handleProductTypeChange(evt) {\n      this.productTypeInput.value = evt.detail.selectedValue;\n    }\n\n    /**\n     * Handles the reset button being clicked\n     */\n    handleReset()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