'use client'; import { useState, type FormEvent } from 'react'; import { ArrowRight, Mail, MapPin } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; export type ContactFormProps = { heading?: string; description?: string; email?: string; location?: string; nameLabel?: string; emailLabel?: string; companyLabel?: string; messageLabel?: string; submitLabel?: string; successMessage?: string; }; export default function ContactForm({ heading = '', description = '', email = '', location = '', nameLabel = 'Name', emailLabel = 'Email', companyLabel = 'Company', messageLabel = 'Message', submitLabel = 'Send message', successMessage = 'Thanks — we will be in touch soon.', }: ContactFormProps) { const [status, setStatus] = useState<'idle' | 'submitting' | 'success' | 'error'>('idle'); const [error, setError] = useState(''); async function handleSubmit(event: FormEvent) { event.preventDefault(); setStatus('submitting'); setError(''); const form = event.currentTarget; const body = Object.fromEntries(new FormData(form).entries()); try { const response = await fetch('/api/contact', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), }); const result = await response.json() as { error?: string }; if (!response.ok) throw new Error(result.error || 'We could not send your message.'); form.reset(); setStatus('success'); } catch (cause) { setError(cause instanceof Error ? cause.message : 'We could not send your message.'); setStatus('error'); } } return (

{heading}

{description &&

{description}

}
{email && } {location &&

}