/* WhatsApp modal — abre quando qualquer botão "Falar no WhatsApp" é clicado */ function WhatsModal({ open, onClose }) { const [nome, setNome] = React.useState(''); const [fone, setFone] = React.useState(''); const [sent, setSent] = React.useState(false); React.useEffect(() => { if (!open) { setSent(false); return; } const onKey = (e) => { if (e.key === 'Escape') onClose(); }; window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [open, onClose]); if (!open) return null; const formatPhone = (v) => { const d = v.replace(/\D/g, '').slice(0, 11); if (d.length <= 2) return d; if (d.length <= 7) return `(${d.slice(0,2)}) ${d.slice(2)}`; if (d.length <= 10) return `(${d.slice(0,2)}) ${d.slice(2,6)}-${d.slice(6)}`; return `(${d.slice(0,2)}) ${d.slice(2,7)}-${d.slice(7)}`; }; const submit = (e) => { e.preventDefault(); if (!nome.trim() || fone.replace(/\D/g,'').length < 10) return; const msg = `Olá! Meu nome é ${nome.trim()} e gostaria de saber mais sobre a Amparus. Meu telefone: ${fone}.`; const url = `https://wa.me/554797321834?text=${encodeURIComponent(msg)}`; window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'whatsapp_lead', nome: nome.trim() }); window.ampTrack && window.ampTrack('whatsapp-submit'); const _sid = sessionStorage.getItem('_amp_sid') || ''; fetch('/track/lead', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sessionId: _sid, nome: nome.trim(), fone: fone }), }).catch(function(){}); setSent(true); setTimeout(() => { window.open(url, '_blank'); }, 200); }; return (
Abrindo o WhatsApp em uma nova aba. Se nada aparecer, libere o pop-up do navegador.