/* Scoped to: ss-interior-flooring-template-footer */
(function() {
  'use strict';
  var componentRoots = document.querySelectorAll('[data-component-slug="ss-interior-flooring-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="ss-interior-flooring-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}}" || "Thank you for subscribing!", errorMessage: "{{newsletter_error_message}}" || "Something went wrong. Please try again.", }; var forms = document.querySelectorAll("form[data-newsletter-form]:not([data-initialized])"); forms.forEach(function (form) { form.setAttribute("data-initialized", "true"); form.setAttribute("onsubmit", "return false;"); var statusEl = document.getElementById("newsletter-status"); form.addEventListener("submit", function (e) { e.preventDefault(); e.stopPropagation(); var emailInput = form.querySelector('input[type="email"]'); var email = emailInput ? emailInput.value : ""; if (!email || !email.includes("@")) { showStatus("Please enter a valid email address.", "error"); return false; } var submitBtn = form.querySelector('button[type="submit"]'); var originalText = submitBtn ? submitBtn.textContent : ""; if (submitBtn) { submitBtn.textContent = "Subscribing..."; submitBtn.disabled = true; } if (CONFIG.apiEndpoint && CONFIG.apiEndpoint.indexOf("http") === 0) { fetch(CONFIG.apiEndpoint, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email: email }), }) .then(function (response) { if (!response.ok) throw new Error("Network error"); return response.json(); }) .then(function () { showStatus(CONFIG.successMessage, "success"); form.reset(); }) .catch(function () { showStatus(CONFIG.errorMessage, "error"); }) .finally(function () { if (submitBtn) { submitBtn.textContent = originalText; submitBtn.disabled = false; } }); } else { setTimeout(function () { showStatus(CONFIG.successMessage, "success"); form.reset(); if (submitBtn) { submitBtn.textContent = originalText; submitBtn.disabled = false; } }, 1000); } return false; }); function showStatus(message, type) { if (!statusEl) return; statusEl.textContent = message; statusEl.className = "mt-2 py-2 px-3 rounded text-xs text-center " + (type === "success" ? "bg-green-500/20 text-green-200" : "bg-red-500/20 text-red-200"); statusEl.classList.remove("hidden"); setTimeout(function () { statusEl.classList.add("hidden"); }, 5000); } }); }, 0); })();
  });
})();