'use client' import { Container, Card, CardContent, Typography, Box, Button, TextField, Paper, useTheme, Alert, Snackbar, } from '@mui/material' import { Email, Send, ContactSupport, } from '@mui/icons-material' import { useRouter } from 'next/navigation' import { useTranslations, useLocale } from 'next-intl' import { useState, useEffect } from 'react' import RefreshIcon from '@mui/icons-material/Refresh' export default function Contact() { const theme = useTheme() const router = useRouter() const t = useTranslations('contact') const locale = useLocale() const [formData, setFormData] = useState({ name: '', email: '', subject: '', message: '' }) const [captcha, setCaptcha] = useState<{ id: string question: string answer: string }>({ id: '', question: '', answer: '' }) const [captchaError, setCaptchaError] = useState(false) const [isSubmitting, setIsSubmitting] = useState(false) const [showSuccess, setShowSuccess] = useState(false) const [showError, setShowError] = useState(false) const loadCaptcha = async () => { try { const response = await fetch('/api/captcha') const data = await response.json() if (data.success) { setCaptcha({ id: data.captchaId, question: data.question, answer: '' }) setCaptchaError(false) } } catch (error) { console.error('Failed to load captcha:', error) } } useEffect(() => { loadCaptcha() }, []) const handleInputChange = (field: string) => (event: React.ChangeEvent) => { setFormData(prev => ({ ...prev, [field]: event.target.value })) } const handleCaptchaChange = (event: React.ChangeEvent) => { setCaptcha(prev => ({ ...prev, answer: event.target.value })) setCaptchaError(false) } const handleSubmit = async (event: React.FormEvent) => { event.preventDefault() // Validate captcha answer is provided if (!captcha.answer.trim()) { setCaptchaError(true) return } setIsSubmitting(true) try { const response = await fetch('/api/contact', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ ...formData, captchaId: captcha.id, captchaAnswer: captcha.answer }) }) const data = await response.json() if (response.ok && data.success) { setFormData({ name: '', email: '', subject: '', message: '' }) setShowSuccess(true) // Load new captcha loadCaptcha() } else { console.error('Contact form error:', data.error) setShowError(true) // Reload captcha on error loadCaptcha() } } catch (error) { console.error('Contact form submission error:', error) setShowError(true) // Reload captcha on error loadCaptcha() } finally { setIsSubmitting(false) } } const contactInfo = [ { icon: , title: t('info.email.title'), content: t('info.email.content'), action: 'mailto:contact@biblical-guide.com' } ] return ( {/* Hero Section */} {t('hero.title')} {t('hero.subtitle')} {t('hero.description')} {/* Contact Form */} {t('form.title')} {t('form.description')} {/* Captcha */} Security Check What is {captcha.question}? {/* Contact Information */} {t('info.title')} {t('info.description')} {contactInfo.map((info, index) => ( info.action && window.open(info.action, '_self')} > {info.icon} {info.title} {info.content} ))} {/* FAQ Quick Link */} {t('faq.title')} {t('faq.description')} {/* Success/Error Messages */} setShowSuccess(false)} anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }} > setShowSuccess(false)} severity="success" sx={{ width: '100%' }}> {t('form.success')} setShowError(false)} anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }} > setShowError(false)} severity="error" sx={{ width: '100%' }}> {t('form.error')} ) }