/* Scoped to: marathon-contact-form-map */
(function() {
  'use strict';
  var componentRoots = document.querySelectorAll('[data-component-slug="marathon-contact-form-map"]');
  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="marathon-contact-form-map"] ~ ' + 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: "{{contact_api_endpoint}}", successMessage: "{{contact_success_message}}" || "Thank you for your message! We'll get back to you soon.", errorMessage: "{{contact_error_message}}" || "Something went wrong. Please try again.", }; var forms = document.querySelectorAll( "form[data-contact-form]:not([data-initialized])" ); forms.forEach(function (form) { form.setAttribute("data-initialized", "true"); var container = form.closest("section") || form.parentElement; var statusEl = container ? container.querySelector("#contact-form-status") : null; form.setAttribute("onsubmit", "return false;"); form.addEventListener("submit", function (e) { e.preventDefault(); e.stopPropagation(); var formData = new FormData(form); var data = {}; formData.forEach(function (value, key) { data[key] = value; }); var submitBtn = form.querySelector('button[type="submit"]'); var originalText = submitBtn ? submitBtn.textContent : ""; if (submitBtn) { submitBtn.innerHTML = "Sending..."; submitBtn.disabled = true; } if (CONFIG.apiEndpoint && CONFIG.apiEndpoint.indexOf("http") === 0) { fetch(CONFIG.apiEndpoint, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data), }) .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.innerHTML = '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8"/></svg>' + originalText; submitBtn.disabled = false; } }); } else { setTimeout(function () { showStatus(CONFIG.successMessage, "success"); form.reset(); if (submitBtn) { submitBtn.innerHTML = '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8"/></svg> SEND MESSAGE'; submitBtn.disabled = false; } }, 1000); } return false; }); function showStatus(message, type) { if (!statusEl) return; statusEl.textContent = message; statusEl.className = "py-3 px-4 rounded-lg text-center font-medium " + (type === "success" ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"); statusEl.classList.remove("hidden"); setTimeout(function () { statusEl.classList.add("hidden"); }, 5000); } }); }, 0); })();
  });
})();