import { useState } from 'preact/hooks'; import { submitLead } from './api'; import { IconSpan } from './icon-span'; import { useWidgetStore } from './store'; export const Contact = () => { const { visitor, updateVisitor, captchaToken } = useWidgetStore(); const [interest, setInterest] = useState(''); const [message, setMessage] = useState(''); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); const [error, setError] = useState(''); const handleSubmit = async () => { if (!visitor.name.trim() || !visitor.phone.trim()) return; setLoading(true); setError(''); try { await submitLead({ name: visitor.name.trim(), phone: visitor.phone.trim(), interest: interest.trim() || undefined, message: message.trim() || undefined, captchaToken, }); setSuccess(true); } catch { setError('Submission failed. Please try again.'); } finally { setLoading(false); } }; if (success) { return (
); } return (