Diagnóstico rápido
Responda em menos de 3 minutos e permita que nossos especialistas conheçam melhor a realidade da sua operação. Ao final, nossa equipe poderá entrar em contato para compartilhar sugestões e oportunidades identificadas a partir das suas respostas.
const hero = document.getElementById('hero'); const form = document.getElementById('surveyForm'); const thanks = document.getElementById('thanks'); const startBtn = document.getElementById('startBtn'); const steps = Array.from(form.querySelectorAll('.step')); const progressSteps = Array.from(form.querySelectorAll('.progress-step'));
startBtn.addEventListener('click', () => { hero.classList.add('hidden'); form.classList.remove('hidden'); form.scrollIntoView({behavior:'smooth', block:'start'}); });
function showStep(n){ steps.forEach(s => s.classList.toggle('hidden', Number(s.dataset.step) !== n)); progressSteps.forEach(p => { const stepNum = Number(p.dataset.step); p.classList.toggle('active', stepNum === n); p.classList.toggle('done', stepNum { const input = field.querySelector('input[type=text], input[type=tel], input[type=email], select'); const group = field.querySelector('.options'); let ok = true;
if (input) { ok = input.value.trim().length > 0; if (input.type === 'email' && ok) { ok = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(input.value.trim()); } } else if (group) { const name = group.dataset.group; const checked = form.querySelectorAll('input[name="'+name+'"]:checked'); ok = checked.length > 0; }
field.classList.toggle('invalid', !ok); if (!ok) valid = false; }); return valid; }
form.querySelectorAll('.next-step').forEach(btn => { btn.addEventListener('click', () => { const currentStep = btn.closest('.step'); if (!validateStep(currentStep)) return; showStep(Number(currentStep.dataset.step) + 1); }); });
form.querySelectorAll('.prev-step').forEach(btn => { btn.addEventListener('click', () => { const currentStep = btn.closest('.step'); showStep(Number(currentStep.dataset.step) - 1); }); });
// Exclusive "Nenhum" checkbox logic for 2.3 const nenhum = document.getElementById('servicoNenhum'); const servicosGroup = document.querySelectorAll('input[name="servicos"]'); nenhum.addEventListener('change', () => { if (nenhum.checked) { servicosGroup.forEach(cb => { if (cb !== nenhum) cb.checked = false; }); } }); servicosGroup.forEach(cb => { if (cb !== nenhum) { cb.addEventListener('change', () => { if (cb.checked) nenhum.checked = false; }); } });
// Max-3 logic for 2.4 const desafioGroup = document.querySelectorAll('input[name="desafio"]'); const desafioNote = document.querySelector('[data-note-for="desafio"]'); function updateDesafioNote(){ const n = document.querySelectorAll('input[name="desafio"]:checked').length; desafioNote.textContent = n + ' de 3 selecionados'; desafioNote.classList.toggle('warn', n >= 3); } desafioGroup.forEach(cb => { cb.addEventListener('change', () => { const checked = document.querySelectorAll('input[name="desafio"]:checked'); if (checked.length > 3) { cb.checked = false; } updateDesafioNote(); }); });
form.addEventListener('submit', (e) => { e.preventDefault(); const step2 = form.querySelector('.step[data-step="2"]'); if (!validateStep(step2)) return;
// Collect answers const data = new FormData(form); const payload = {}; for (const [key, value] of data.entries()) { if (payload[key]) { payload[key] = Array.isArray(payload[key]) ? [...payload[key], value] : [payload[key], value]; } else { payload[key] = value; } }
console.log('Diagnóstico CWR — respostas:', payload);
function showThanks(){ form.classList.add('hidden'); thanks.classList.remove('hidden'); thanks.scrollIntoView({behavior:'smooth', block:'start'}); }
if (WEBHOOK_URL && WEBHOOK_URL.indexOf('https://script.google.com/macros/s/AKfycbyxTX7D-UeJrKYxjekyj-BQA-8p8Qe-hA9BnljjWtzStIb8Cd1npF6zgV1rDnnwBYiGnQ/exec') === -1) { const submitBtn = document.getElementById('submitBtn'); submitBtn.disabled = true; submitBtn.textContent = 'Enviando...'; fetch(WEBHOOK_URL, { method: 'POST', headers: { 'Content-Type': 'text/plain;charset=utf-8' }, // evita preflight CORS no Apps Script body: JSON.stringify(payload) }) .then(showThanks) .catch(() => { // Mesmo se a rede falhar, não trava o usuário numa tela de erro — // mas registre no console para investigar a integração. console.error('Falha ao enviar para o Apps Script. Verifique a URL do WEBHOOK_URL.'); showThanks(); }); } else { showThanks(); } }); })();