'use client'; import { useState } from 'react'; import { Loader2, CheckCircle2 } from 'lucide-react'; import { submitMultisplitForm } from '@/app/zapytanie-multisplit/actions'; import { getRecaptchaToken } from '@/lib/getRecaptchaToken'; interface Props { productName: string; productSku: string; } export default function MultisplitContactForm({ productName, productSku }: Props) { const [form, setForm] = useState({ name: '', phone: '', email: '', city: '', rooms: '2', message: '', consent: false, }); const [loading, setLoading] = useState(false); const [sent, setSent] = useState(false); const [error, setError] = useState(''); const handle = (e: React.ChangeEvent) => { const { name, value, type } = e.target; setForm(prev => ({ ...prev, [name]: type === 'checkbox' ? (e.target as HTMLInputElement).checked : value, })); }; const submit = async () => { if (!form.name || !form.phone || !form.consent) { setError('Wypełnij wymagane pola i zaznacz zgodę.'); return; } setLoading(true); setError(''); try { const token = await getRecaptchaToken('submit'); const recaptchaToken = token || ''; const res = await submitMultisplitForm({ name: form.name, phone: form.phone, email: form.email, city: form.city, rooms: form.rooms, message: form.message, consent: form.consent, productName, productSku, recaptchaToken, }); if (res.success) setSent(true); else setError(res.message || 'Błąd wysyłki. Zadzwoń do nas bezpośrednio.'); } catch { setError('Błąd połączenia. Spróbuj ponownie.'); } setLoading(false); }; if (sent) { return (

Zapytanie wysłane!

Oddzwonimy w ciągu 24 godzin z bezpłatną wyceną.

); } return (
{/* Produkt info */}
Zapytanie dotyczy: {productName}