gateButton.addEventListener("click", async function () { const name = gateName.value.trim(); const email = gateEmail.value.trim(); if (!name || !email) { gateMessage.textContent = "Please enter both your name and a valid email address to unlock the full report."; return; } if (!email.includes("@") || !email.includes(".")) { gateMessage.textContent = "Please enter a valid email address."; return; } if (!lastReportPayload) { gateMessage.textContent = "Please run a check first, then unlock the report."; return; } gateMessage.textContent = "Sending your report and unlocking the full view..."; try { const res = await fetch("/api/send-report", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name, email, report: lastReportPayload, }), }); if (!res.ok) { gateMessage.textContent = "Full report unlocked, but there was an issue emailing it. You can still print or save this page as PDF."; } else { gateMessage.textContent = "Full report unlocked. A copy has been sent to your email. You can also print or save this page as PDF."; } } catch (err) { gateMessage.textContent = "Full report unlocked. Email may not have been sent due to a connection issue. You can still print or save this page as PDF."; } fullSection.style.display = "block"; });