{
  "version": 3,
  "sources": ["/cdn/shop/t/163/assets/forms-to-water-report.js?enable_js_minification=1"],
  "sourcesContent": ["// [MC Popups] Handles Mailchimp popup form submission and redirects to the water report page with the entered ZIP code as a query parameter.\nwindow.addEventListener('load', () => {\n  const bodyObserver = new MutationObserver((_, obs) => {\n    const wrappers = document.querySelectorAll('[id^=\"mcforms-\"]');\n    if (wrappers.length > 0) {\n      obs.disconnect();\n      initMailchimpPopupRedirect(wrappers);\n    }\n  });\n\n  bodyObserver.observe(document.body, { childList: true, subtree: true });\n});\n\nfunction initMailchimpPopupRedirect(wrappers) {\n  wrappers.forEach((wrapper) => {\n    const shadowRoot = wrapper?.shadowRoot;\n    if (!shadowRoot) return;\n\n    let capturedZip = null;\n\n    function attachZipListeners() {\n      const zipInputs = shadowRoot.querySelectorAll('input[name=\"$zip\"]');\n      if (zipInputs.length === 0) return;\n\n      zipInputs.forEach((input) => {\n        if (!input.__mc_zip_listener_attached) {\n          input.addEventListener('input', (e) => {\n            capturedZip = e.target.value.trim();\n          });\n          input.__mc_zip_listener_attached = true;\n        }\n      });\n    }\n\n    attachZipListeners();\n\n    const zipObserver = new MutationObserver(attachZipListeners);\n    zipObserver.observe(shadowRoot, { childList: true, subtree: true });\n\n    function observeStepForms() {\n      const stepForms = shadowRoot.querySelectorAll('form.step');\n      if (stepForms.length === 0) return;\n\n      stepForms.forEach((form) => {\n        const stepObserver = new MutationObserver(() => {\n          const isVisible = form.classList.contains('visible') && form.style.display !== 'none';\n          if (!isVisible) return;\n\n          const stepText = form.textContent?.trim();\n\n          if (\n            stepText?.includes('Your water report is on its way!') &&\n            capturedZip\n          ) {\n            const redirectUrl = `https://www.theshowerheadstore.com/pages/water-report?zip=${encodeURIComponent(capturedZip)}`;\n            window.location.href = redirectUrl;\n          }\n        });\n\n        stepObserver.observe(form, {\n          attributes: true,\n          attributeFilter: ['class', 'style'],\n        });\n      });\n    }\n\n    observeStepForms();\n\n    const stepWaitObserver = new MutationObserver(observeStepForms);\n    stepWaitObserver.observe(shadowRoot, { childList: true, subtree: true });\n  });\n}\n\n\n\n\n\n// [Klaviyo Forms] Handles Klaviyo form submission and redirects to the water report page with the entered ZIP code as a query parameter.\ndocument.addEventListener(\"DOMContentLoaded\", () => {\n  const initializedForms = new WeakSet();\n\n  const runObserverLogic = () => {\n    const forms = document.querySelectorAll('form[data-testid=\"klaviyo-form-Y7ZjvB\"], form[data-testid=\"klaviyo-form-X7LJeA\"]');\n\n    forms.forEach((form) => {\n      if (initializedForms.has(form)) return;\n\n      const zipInput = form.querySelector('input[placeholder=\"Zip Code\"]');\n      const submitBtn = form.querySelector('button[type=\"button\"]');\n\n      if (!zipInput || !submitBtn) return;\n\n      initializedForms.add(form);\n\n      const successObserver = new MutationObserver(() => {\n        if (form.innerHTML.includes(\"Your Water Report is on its way!\")) {\n          const zip = zipInput.value.trim();\n          if (/^\\d{5}$/.test(zip)) {\n            const targetURL = `/pages/water-report?zip=${zip}`;\n            window.location.href = targetURL;\n          }\n          successObserver.disconnect();\n        }\n      });\n\n      successObserver.observe(form, { childList: true, subtree: true });\n    });\n  };\n\n  runObserverLogic();\n\n  const observer = new MutationObserver(runObserverLogic);\n  observer.observe(document.body, { childList: true, subtree: true });\n});\n\n\n\n\n\n// Watches ALIA popup forms and redirects to the water report page after ZIP submission and success message.\n(() => {\n  const LOG_PREFIX = '\uD83E\uDDEA [ALIA ZIP Redirect]';\n  const initializedForms = new WeakSet();\n\n  function getZipValue(input) {\n    const raw = input?.value?.trim() || '';\n    const match = raw.match(/^(\\d{5})(?:[-\\s]?\\d{4})?$/);\n    return match ? match[1] : null;\n  }\n\n  function isAliaSuccessVisible(popupRoot) {\n    const successPhrases = [\n      'your water report is on its way',\n      'thank you'\n    ];\n\n    const headingParagraphs = popupRoot.querySelectorAll('[class*=\"alia-style-heading\"] p');\n\n    for (const p of headingParagraphs) {\n      const text = p.innerText?.trim().toLowerCase();\n      if (!text) continue;\n\n      if (successPhrases.some(phrase => text.includes(phrase))) {\n        return true;\n      }\n    }\n\n    return false;\n  }\n\n  function observePopupForForm(popupRoot) {\n    const formObserver = new MutationObserver(() => {\n      const form = popupRoot.querySelector('form');\n      if (form && !initializedForms.has(form)) {\n        handleAliaForm(form, popupRoot);\n        formObserver.disconnect(); // Stop watching once form is found\n      }\n    });\n\n    formObserver.observe(popupRoot, { childList: true, subtree: true });\n\n    // Also check if form is already there\n    const existingForm = popupRoot.querySelector('form');\n    if (existingForm && !initializedForms.has(existingForm)) {\n      handleAliaForm(existingForm, popupRoot);\n      formObserver.disconnect();\n    }\n  }\n\n  function handleAliaForm(form, popupRoot) {\n    initializedForms.add(form);\n    const zipInput = form.querySelector('input[name=\"property_%24zip\"], input[autocomplete=\"postal-code\"]');\n    if (!zipInput) {\n      console.warn(LOG_PREFIX, 'ZIP input not found in form.');\n      return;\n    }\n\n    let capturedZip = '';\n\n    zipInput.addEventListener('input', () => {\n      capturedZip = getZipValue(zipInput);\n    });\n\n    form.addEventListener('submit', () => {\n      capturedZip = getZipValue(zipInput);\n      if (!capturedZip) {\n        console.log(LOG_PREFIX, 'Invalid ZIP on submit.');\n        return;\n      }\n\n      console.log(LOG_PREFIX, 'Form submitted. Watching for success\u2026 ZIP =', capturedZip);\n\n      let redirected = false;\n      const redirect = () => {\n        if (redirected) return;\n        redirected = true;\n        const target = `/pages/water-report?zip=${capturedZip}`;\n        console.log(LOG_PREFIX, '\u2705 Success detected. Redirecting \u2192', target);\n        window.location.href = target;\n      };\n\n      const successObserver = new MutationObserver(() => {\n        if (isAliaSuccessVisible(popupRoot)) {\n          successObserver.disconnect();\n          redirect();\n        }\n      });\n\n      successObserver.observe(popupRoot, {\n        childList: true,\n        subtree: true\n      });\n\n      setTimeout(() => successObserver.disconnect(), 8000);\n    });\n  }\n\n  function watchForPopupRoots() {\n    const alreadyScanned = new WeakSet();\n\n    // Watch for dynamically injected popup roots\n    const bodyObserver = new MutationObserver((muts) => {\n      muts.forEach(m => {\n       m.addedNodes.forEach(node => {\n  if (!(node instanceof HTMLElement)) return;\n\n  const nodeId = node.id;\n  if (typeof nodeId === 'string' && nodeId.startsWith('alia-popup-root') && !alreadyScanned.has(node)) {\n    alreadyScanned.add(node);\n    console.log(LOG_PREFIX, '\uD83D\uDFE2 New ALIA popup root detected:', nodeId);\n    observePopupForForm(node);\n  }\n});\n      });\n    });\n\n    bodyObserver.observe(document.body, { childList: true, subtree: true });\n\n    // \uD83D\uDD01 Also re-scan any existing popup roots\n    const existingPopups = document.querySelectorAll('[id^=\"alia-popup-root\"]');\n    existingPopups.forEach(popup => {\n      if (!alreadyScanned.has(popup)) {\n        alreadyScanned.add(popup);\n        console.log(LOG_PREFIX, '\u26A0\uFE0F Scanning existing ALIA popup root:', popup.id);\n        observePopupForForm(popup);\n      }\n    });\n  }\n\n  if (document.readyState === 'loading') {\n    document.addEventListener('DOMContentLoaded', watchForPopupRoots);\n  } else {\n    watchForPopupRoots();\n  }\n\n  console.log(LOG_PREFIX, 'ALIA ZIP redirect script is active.');\n})();\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"],
  "mappings": "AACA,OAAO,iBAAiB,OAAQ,IAAM,CACf,IAAI,iBAAiB,CAAC,EAAG,MAAQ,CACpD,MAAM,SAAW,SAAS,iBAAiB,kBAAkB,EACzD,SAAS,OAAS,IACpB,IAAI,WAAW,EACf,2BAA2B,QAAQ,EAEvC,CAAC,EAEY,QAAQ,SAAS,KAAM,CAAE,UAAW,GAAM,QAAS,EAAK,CAAC,CACxE,CAAC,EAED,SAAS,2BAA2B,SAAU,CAC5C,SAAS,QAAS,SAAY,CAC5B,MAAM,WAAa,SAAS,WAC5B,GAAI,CAAC,WAAY,OAEjB,IAAI,YAAc,KAElB,SAAS,oBAAqB,CAC5B,MAAM,UAAY,WAAW,iBAAiB,oBAAoB,EAC9D,UAAU,SAAW,GAEzB,UAAU,QAAS,OAAU,CACtB,MAAM,6BACT,MAAM,iBAAiB,QAAU,GAAM,CACrC,YAAc,EAAE,OAAO,MAAM,KAAK,C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