/* Scoped to: politician-party-template-footer */
(function() {
  'use strict';
  var componentRoots = document.querySelectorAll('[data-component-slug="politician-party-template-footer"]');
  componentRoots.forEach(function(componentRoot) {
    // Helper to query within component, with fallback to document for sibling elements
    var $ = function(sel) { 
      return componentRoot.querySelector(sel) || document.querySelector('[data-component-slug="politician-party-template-footer"] ~ ' + sel) || document.querySelector(sel);
    };
    var $$ = function(sel) { 
      var results = componentRoot.querySelectorAll(sel);
      return results.length ? results : document.querySelectorAll(sel);
    };
    // Original component JS runs in this scope
    (function () { setTimeout(function () { var CONFIG = { apiEndpoint: "{{newsletter_api_endpoint}}", successMessage: "{{newsletter_success_message}}" || "Subscribed successfully!", errorMessage: "{{newsletter_error_message}}" || "Subscription failed. Try again.", redirectUrl: "{{newsletter_redirect_url}}", redirectDelay: parseInt("{{newsletter_redirect_delay}}") || 2000, }; var forms = document.querySelectorAll("form[data-footer-newsletter]:not([data-initialized])"); forms.forEach(function (form) { form.setAttribute("data-initialized", "true"); var statusEl = form.nextElementSibling; var submitBtn = form.querySelector("button[type='submit']"); var input = form.querySelector("input[type='email']"); var originalBtnText = submitBtn.textContent; form.addEventListener("submit", function (e) { e.preventDefault(); if (!input.value) return; submitBtn.textContent = "Subscribing..."; submitBtn.disabled = true; function showStatus(msg, success) { statusEl.textContent = msg; statusEl.className = "mt-4 text-sm text-center " + (success ? "text-green-400" : "text-red-400"); statusEl.classList.remove("hidden"); } if (CONFIG.apiEndpoint && CONFIG.apiEndpoint.indexOf("http") === 0) { fetch(CONFIG.apiEndpoint, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email: input.value }), }) .then(function (res) { if (!res.ok) throw new Error(); return res.json(); }) .then(function () { showStatus(CONFIG.successMessage, true); form.reset(); if ( CONFIG.redirectUrl && (CONFIG.redirectUrl.indexOf("http") === 0 || CONFIG.redirectUrl.indexOf("/") === 0) ) { setTimeout(function () { window.location.href = CONFIG.redirectUrl; }, CONFIG.redirectDelay); } }) .catch(function () { showStatus(CONFIG.errorMessage, false); }) .finally(function () { submitBtn.textContent = originalBtnText; submitBtn.disabled = false; }); } else { setTimeout(function () { showStatus(CONFIG.successMessage, true); form.reset(); submitBtn.textContent = originalBtnText; submitBtn.disabled = false; }, 800); } }); }); }, 0); })();
  });
})();