import React, { useState } from 'react'; import type { ScoreResult, UserAnswer } from '../types'; import { submitLead } from '../api/submitLead'; import { Mail, Lock } from 'lucide-react'; import { Turnstile } from '@marsidev/react-turnstile'; import styles from '../styles/results.module.css'; const config = window.noon_audit_config; interface EmailGateProps { auditId: number; scoreResult: ScoreResult; answers: UserAnswer[]; onComplete: () => void; } export const EmailGate: React.FC = ({ auditId, scoreResult, answers, onComplete, }) => { const [email, setEmail] = useState(''); const [name, setName] = useState(''); const [company, setCompany] = useState(''); const [websiteUrl, setWebsiteUrl] = useState(''); // Honeypot const [consent, setConsent] = useState(false); const [marketingOptin, setMarketingOptin] = useState(false); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(''); const [turnstileToken, setTurnstileToken] = useState(''); const agencyName = config.consultantName || 'us'; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!email || !consent) return; setSubmitting(true); setError(''); try { await submitLead({ audit_id: auditId, email, name, company, score: scoreResult.rawScore, risk_band: scoreResult.riskBand, category_scores: scoreResult.categoryScores, answers, website_url: websiteUrl, turnstile_token: turnstileToken, consented_at: new Date().toISOString(), marketing_optin: marketingOptin, }); onComplete(); } catch (err) { setError('Something went wrong. Please try again.'); console.error('Lead submission error:', err); } finally { setSubmitting(false); } }; // Build the required consent label with dynamic policy links const buildConsentLabel = () => { const hasPrivacy = !!config.privacyUrl; const hasTerms = !!config.termsUrl; const policyLinks = []; if (hasTerms) { policyLinks.push( Terms & Conditions ); } if (hasPrivacy) { policyLinks.push( Privacy Policy ); } return ( <> I consent to {agencyName} processing my data and contacting me regarding my audit results {policyLinks.length > 0 && ( <> . I have read the{' '} {policyLinks.reduce((acc, link, i) => { if (i > 0) acc.push(' and '); acc.push(link); return acc; }, [])} )} ); }; return (

Your audit is ready!

Enter your details below to unlock your personalised audit report and improvement roadmap.

{/* Anti-spam Honeypot: Visually hidden but visible to CSS-ignorant bots */} setEmail(e.target.value)} required id="noon-audit-email" /> setName(e.target.value)} id="noon-audit-name" /> setCompany(e.target.value)} id="noon-audit-company" /> {/* Required: Consent to contact about audit results */} {/* Optional: Marketing opt-in */} {config.turnstileSiteKey && (
setTurnstileToken(token)} onError={() => setError('Security check failed. Please refresh and try again.')} onExpire={() => setTurnstileToken('')} />
)} {error &&

{error}

}

Your details are kept secure and are never shared with third parties.

); };