'use client'; import { useState, useRef } from 'react'; import { useTranslations, useLocale } from 'next-intl'; import { requestBrochureAction } from '@/app/actions/brochure'; import { cn } from '@/components/ui/utils'; import { useAnalytics } from './analytics/useAnalytics'; import { AnalyticsEvents } from './analytics/analytics-events'; interface Props { className?: string; } export default function FooterBrochureForm({ className }: Props) { const t = useTranslations('Brochure'); const locale = useLocale(); const { trackEvent } = useAnalytics(); const formRef = useRef(null); const [phase, setPhase] = useState<'idle' | 'loading' | 'success' | 'error'>('idle'); const [err, setErr] = useState(''); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); if (!formRef.current) return; setPhase('loading'); const fd = new FormData(formRef.current); fd.set('locale', locale); try { const res = await requestBrochureAction(fd); if (res.success) { setPhase('success'); trackEvent(AnalyticsEvents.DOWNLOAD, { file_name: `klz-product-catalog-${locale}.pdf`, file_type: 'brochure', location: 'footer_inline', }); } else { setErr(res.error || 'Error'); setPhase('error'); } } catch { setErr('Network error'); setPhase('error'); } } if (phase === 'success') { return (

{locale === 'de' ? 'Erfolgreich angefordert!' : 'Successfully requested!'}

{locale === 'de' ? 'Wir haben Ihnen den Katalog soeben per E-Mail zugesendet.' : 'We have just sent the catalog to your email.'}

); } return (

{t('ctaTitle')}

{t('subtitle')}

{/* Anti-spam Honeypot */}
{phase === 'error' && err && (
{err}
)}
); }