{
  "version": 3,
  "sources": ["/cdn/shop/t/145/assets/predictive-search.js?cb=20260310c"],
  "sourcesContent": ["class PredictiveSearch extends SearchForm {\n  constructor() {\n    super();\n    this.cachedResults = {};\n    this.predictiveSearchResults = this.querySelector('[data-predictive-search]');\n    this.allPredictiveSearchInstances = document.querySelectorAll('predictive-search');\n    this.isOpen = false;\n    this.abortController = new AbortController();\n    this.searchTerm = '';\n\n    this.setupEventListeners();\n  }\n\n  setupEventListeners() {\n    this.input.form.addEventListener('submit', this.onFormSubmit.bind(this));\n\n    this.input.addEventListener('focus', this.onFocus.bind(this));\n    this.addEventListener('focusout', this.onFocusOut.bind(this));\n    this.addEventListener('keyup', this.onKeyup.bind(this));\n    this.addEventListener('keydown', this.onKeydown.bind(this));\n  }\n\n  getQuery() {\n    return this.input.value.trim();\n  }\n\n  onChange() {\n    super.onChange();\n    const newSearchTerm = this.getQuery();\n    if (!this.searchTerm || !newSearchTerm.startsWith(this.searchTerm)) {\n      // Remove the results when they are no longer relevant for the new search term\n      // so they don't show up when the dropdown opens again\n      this.querySelector('#predictive-search-results-groups-wrapper')?.remove();\n    }\n\n    // Update the term asap, don't wait for the predictive search query to finish loading\n    this.updateSearchForTerm(this.searchTerm, newSearchTerm);\n\n    this.searchTerm = newSearchTerm;\n\n    if (!this.searchTerm.length) {\n      this.close(true);\n      return;\n    }\n\n    this.getSearchResults(this.searchTerm);\n  }\n\n  onFormSubmit(event) {\n    if (!this.getQuery().length || this.querySelector('[aria-selected=\"true\"] a')) event.preventDefault();\n  }\n\n  onFormReset(event) {\n    super.onFormReset(event);\n    if (super.shouldResetForm()) {\n      this.searchTerm = '';\n      this.abortController.abort();\n      this.abortController = new AbortController();\n      this.closeResults(true);\n    }\n  }\n\n  onFocus() {\n    const currentSearchTerm = this.getQuery();\n\n    if (!currentSearchTerm.length) return;\n\n    if (this.searchTerm !== currentSearchTerm) {\n      // Search term was changed from other search input, treat it as a user change\n      this.onChange();\n    } else if (this.getAttribute('results') === 'true') {\n      this.open();\n    } else {\n      this.getSearchResults(this.searchTerm);\n    }\n  }\n\n  onFocusOut() {\n    setTimeout(() => {\n      if (!this.contains(document.activeElement)) this.close();\n    });\n  }\n\n  onKeyup(event) {\n    if (!this.getQuery().length) this.close(true);\n    event.preventDefault();\n\n    switch (event.code) {\n      case 'ArrowUp':\n        this.switchOption('up');\n        break;\n      case 'ArrowDown':\n        this.switchOption('down');\n        break;\n      case 'Enter':\n        this.selectOption();\n        break;\n    }\n  }\n\n  onKeydown(event) {\n    // Prevent the cursor from moving in the input when using the up and down arrow keys\n    if (event.code === 'ArrowUp' || event.code === 'ArrowDown') {\n      event.preventDefault();\n    }\n  }\n\n  updateSearchForTerm(previousTerm, newTerm) {\n    const searchForTextElement = this.querySelector('[data-predictive-search-search-for-text]');\n    const currentButtonText = searchForTextElement?.innerText;\n    if (currentButtonText) {\n      if (currentButtonText.match(new RegExp(previousTerm, 'g')).length > 1) {\n        // The new term matches part of the button text and not just the search term, do not replace to avoid mistakes\n        return;\n      }\n      const newButtonText = currentButtonText.replace(previousTerm, newTerm);\n      searchForTextElement.innerText = newButtonText;\n    }\n  }\n\n  switchOption(direction) {\n    if (!this.getAttribute('open')) return;\n\n    const moveUp = direction === 'up';\n    const selectedElement = this.querySelector('[aria-selected=\"true\"]');\n\n    // Filter out hidden elements (duplicated page and article resources) thanks\n    // to this https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent\n    const allVisibleElements = Array.from(this.querySelectorAll('li, button.predictive-search__item')).filter(\n      (element) => element.offsetParent !== null\n    );\n    let activeElementIndex = 0;\n\n    if (moveUp && !selectedElement) return;\n\n    let selectedElementIndex = -1;\n    let i = 0;\n\n    while (selectedElementIndex === -1 && i <= allVisibleElements.length) {\n      if (allVisibleElements[i] === selectedElement) {\n        selectedElementIndex = i;\n      }\n      i++;\n    }\n\n    this.statusElement.textContent = '';\n\n    if (!moveUp && selectedElement) {\n      activeElementIndex = selectedElementIndex === allVisibleElements.length - 1 ? 0 : selectedElementIndex + 1;\n    } else if (moveUp) {\n      activeElementIndex = selectedElementIndex === 0 ? allVisibleElements.length - 1 : selectedElementIndex - 1;\n    }\n\n    if (activeElementIndex === selectedElementIndex) return;\n\n    const activeElement = allVisibleElements[activeElementIndex];\n\n    activeElement.setAttribute('aria-selected', true);\n    if (selectedElement) selectedElement.setAttribute('aria-selected', false);\n\n    this.input.setAttribute('aria-activedescendant', activeElement.id);\n  }\n\n  selectOption() {\n    const selectedOption = this.querySelector('[aria-selected=\"true\"] a, button[aria-selected=\"true\"]');\n\n    if (selectedOption) selectedOption.click();\n  }\n\n  getSearchResults(searchTerm) {\n    const queryKey = searchTerm.replace(' ', '-').toLowerCase();\n    this.setLiveRegionLoadingState();\n\n    if (this.cachedResults[queryKey]) {\n      this.renderSearchResults(this.cachedResults[queryKey]);\n      return;\n    }\n\n    fetch(`${routes.predictive_search_url}?q=${encodeURIComponent(searchTerm)}&section_id=predictive-search`, {\n      signal: this.abortController.signal,\n    })\n      .then((response) => {\n        if (!response.ok) {\n          var error = new Error(response.status);\n          this.close();\n          throw error;\n        }\n\n        return response.text();\n      })\n      .then((text) => {\n        const resultsMarkup = new DOMParser()\n          .parseFromString(text, 'text/html')\n          .querySelector('#shopify-section-predictive-search').innerHTML;\n        // Save bandwidth keeping the cache in all instances synced\n        this.allPredictiveSearchInstances.forEach((predictiveSearchInstance) => {\n          predictiveSearchInstance.cachedResults[queryKey] = resultsMarkup;\n        });\n        this.renderSearchResults(resultsMarkup);\n      })\n      .catch((error) => {\n        if (error?.code === 20) {\n          // Code 20 means the call was aborted\n          return;\n        }\n        this.close();\n        throw error;\n      });\n  }\n\n  setLiveRegionLoadingState() {\n    this.statusElement = this.statusElement || this.querySelector('.predictive-search-status');\n    this.loadingText = this.loadingText || this.getAttribute('data-loading-text');\n\n    this.setLiveRegionText(this.loadingText);\n    this.setAttribute('loading', true);\n  }\n\n  setLiveRegionText(statusText) {\n    this.statusElement.setAttribute('aria-hidden', 'false');\n    this.statusElement.textContent = statusText;\n\n    setTimeout(() => {\n      this.statusElement.setAttribute('aria-hidden', 'true');\n    }, 1000);\n  }\n\n  renderSearchResults(resultsMarkup) {\n    this.predictiveSearchResults.innerHTML = resultsMarkup;\n    this.setAttribute('results', true);\n\n    this.setLiveRegionResults();\n    this.open();\n  }\n\n  setLiveRegionResults() {\n    this.removeAttribute('loading');\n    this.setLiveRegionText(this.querySelector('[data-predictive-search-live-region-count-value]').textContent);\n  }\n\n  getResultsMaxHeight() {\n    this.resultsMaxHeight =\n      window.innerHeight - document.querySelector('.section-header')?.getBoundingClientRect().bottom;\n    return this.resultsMaxHeight;\n  }\n\n  open() {\n    this.predictiveSearchResults.style.maxHeight = this.resultsMaxHeight || `${this.getResultsMaxHeight()}px`;\n    this.setAttribute('open', true);\n    this.input.setAttribute('aria-expanded', true);\n    this.isOpen = true;\n  }\n\n  close(clearSearchTerm = false) {\n    this.closeResults(clearSearchTerm);\n    this.isOpen = false;\n  }\n\n  closeResults(clearSearchTerm = false) {\n    if (clearSearchTerm) {\n      this.input.value = '';\n      this.removeAttribute('results');\n    }\n    const selected = this.querySelector('[aria-selected=\"true\"]');\n\n    if (selected) selected.setAttribute('aria-selected', false);\n\n    this.input.setAttribute('aria-activedescendant', '');\n    this.removeAttribute('loading');\n    this.removeAttribute('open');\n    this.input.setAttribute('aria-expanded', false);\n    this.resultsMaxHeight = false;\n    this.predictiveSearchResults.removeAttribute('style');\n  }\n}\n\ncustomElements.define('predictive-search', PredictiveSearch);\n"],
  "mappings": "AAAA,MAAM,yBAAyB,UAAW,CACxC,aAAc,CACZ,MAAM,EACN,KAAK,cAAgB,CAAC,EACtB,KAAK,wBAA0B,KAAK,cAAc,0BAA0B,EAC5E,KAAK,6BAA+B,SAAS,iBAAiB,mBAAmB,EACjF,KAAK,OAAS,GACd,KAAK,gBAAkB,IAAI,gBAC3B,KAAK,WAAa,GAElB,KAAK,oBAAoB,CAC3B,CAEA,qBAAsB,CACpB,KAAK,MAAM,KAAK,iBAA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