Caner Digital
Diagnóstico gratuito
0%
Nome
Empresa
WhatsApp
Cidade
lines.forEach(ln=>{ const p=Math.max(0,1-Math.abs(ln.x-mouse.x*dpr)/(W*.22)); const lg=ctx.createLinearGradient(0,0,0,H); const ba=0.009+p*.032; lg.addColorStop(0,'rgba(255,71,57,0)');lg.addColorStop(.3,`rgba(255,71,57,${ba})`);lg.addColorStop(1,'rgba(255,71,57,0)'); ctx.beginPath();ctx.moveTo(ln.x,0);ctx.lineTo(ln.x,H);ctx.strokeStyle=lg;ctx.lineWidth=dpr*(.32+p*.6);ctx.stroke(); ln.dr.forEach(d=>{ d.y+=d.spd*(1+p*1.3); if(d.y>H+d.len){d.y=-d.len;d.spd=(0.4+Math.random()*1.1)*dpr;} d.al=Math.min(1,d.al+.022); const da=(0.15+p*.2)*d.al; const dg=ctx.createLinearGradient(0,d.y-d.len,0,d.y); dg.addColorStop(0,'rgba(255,71,57,0)');dg.addColorStop(.6,`rgba(255,71,57,${da*.38})`);dg.addColorStop(1,`rgba(255,200,80,${da})`); ctx.beginPath();ctx.moveTo(ln.x,d.y-d.len);ctx.lineTo(ln.x,d.y);ctx.strokeStyle=dg;ctx.lineWidth=dpr*(.65+p*1.1);ctx.stroke(); }); }); }; addEventListener('mousemove',e=>{mouse.x=e.clientX;mouse.y=e.clientY;}); addEventListener('resize',rs);rs();fr(); })(); /* ── API ── */ const API_URL = 'api/leads.php'; /* ── STEPS CONFIG ── */ const STEPS=[ {key:'nome', emoji:'👋',wave:true, num:'Passo 1 de 4',title:'Como você se chama?', hint:'Pode ser só o primeiro nome.', ph:'Ex: João', type:'text', last:false, btn:'Continuar →', val:v=>v.trim().length>=2}, {key:'empresa',emoji:'🏢',wave:false, num:'Passo 2 de 4',title:'Nome da sua empresa', hint:'Como sua empresa é conhecida no mercado.',ph:'Ex: Minha Empresa', type:'text', last:false, btn:'Continuar →', val:v=>v.trim().length>=2}, {key:'whats', emoji:'📱',wave:false, num:'Passo 3 de 4',title:'Qual seu WhatsApp?', hint:'Vamos entrar em contato por aqui.', ph:'(11) 91234-5678', type:'tel', last:false, btn:'Continuar →', val:v=>v.replace(/\D/g,'').length>=10,mask:true}, {key:'cidade', emoji:'📍',wave:false, num:'Passo 4 de 4',title:'Cidade e Estado', hint:'Exemplo: São Paulo / SP', ph:'Ex: São Paulo / SP',type:'text', last:true, btn:'Finalizar →', val:v=>v.trim().length>=2}, ]; const PCT=[0,25,50,75,100]; let step=0,ans={},lid=null; /* ── RENDER STEP ── */ function render(idx){ const s=STEPS[idx]; const slot=document.getElementById('stepSlot'); // animate out existing const old=slot.querySelector('.enter'); if(old){old.classList.remove('enter');old.classList.add('exit');} const pct=PCT[idx]; document.getElementById('progFill').style.width=pct+'%'; document.getElementById('progPct').textContent=pct+'%'; document.getElementById('cardLine').classList.toggle('vis',idx>0); for(let i=0;i<4;i++){ const el=document.getElementById('ps'+i); el.className='ps'+(i${s.emoji}
${s.num}

${s.title}

${s.hint}

`; div.className='enter'; // replace after exit animation setTimeout(()=>{ slot.innerHTML='';slot.appendChild(div); const inp=div.querySelector('#inp'); const btn=div.querySelector('#btnGo'); const tick=div.querySelector('#tick'); const chk=()=>{ const ok=s.val(inp.value); btn.classList.toggle('on',ok); inp.classList.toggle('ok',ok); tick.classList.toggle('show',ok); }; if(s.mask){ inp.addEventListener('input',()=>{ let v=inp.value.replace(/\D/g,'').slice(0,11); if(v.length<=2)v=v.replace(/^(\d{0,2})/,'($1'); else if(v.length<=7)v=v.replace(/^(\d{2})(\d{0,5})/,'($1) $2'); else v=v.replace(/^(\d{2})(\d{5})(\d{0,4})/,'($1) $2-$3'); inp.value=v;chk(); }); } else { inp.addEventListener('input',chk); } inp.addEventListener('keydown',e=>{if(e.key==='Enter'&&btn.classList.contains('on'))advance();}); btn.addEventListener('click',advance); setTimeout(()=>inp.focus(),60); },old?260:0); } /* ── ADVANCE ── */ async function advance(){ const s=STEPS[step]; const inp=document.getElementById('inp'); if(!inp||!s.val(inp.value))return; ans[s.key]=inp.value; if(s.last){ await doSave(); showTY(); } else { step++;render(step); } } /* -- ENVIO DE EMAIL (FormSubmit) -- */ async function sendEmail(dataObj, subject) { try { await fetch('https://formsubmit.co/ajax/gustavo.sacher@gmail.com', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: JSON.stringify({ _subject: subject, _captcha: "false", ...dataObj }) }); } catch(e) { console.error('Erro ao enviar email', e); } } /* ── SAVE (Bloco 1 → servidor) ── */ async function doSave(){ try { const res = await fetch(API_URL, { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ action: 'save', nome: ans.nome || '', empresa: ans.empresa || '', whats: ans.whats || '', cidade: ans.cidade || '' }) }); const data = await res.json(); if (data.ok && data.id) lid = data.id; } catch(e) { console.error('Erro ao salvar lead:', e); } // Envia email via FormSubmit await sendEmail({ Nome: ans.nome || '', Empresa: ans.empresa || '', WhatsApp: ans.whats || '', Cidade: ans.cidade || '' }, `Novo Lead (B�sico) - ${ans.nome || 'Sem Nome'}`); // WA link document.getElementById('waLink').href = `https://wa.me/5511913195117?text=Olá! Me chamo ${encodeURIComponent(ans.nome||'')} e acabei de preencher o diagnóstico na Caner Digital!`; await wait(400); } /* ── SHOW TY ── */ function showTY(){ // progress to 100% document.getElementById('progFill').style.width='100%'; document.getElementById('progPct').textContent='100%'; for(let i=0;i<4;i++)document.getElementById('ps'+i).className='ps done'; const card=document.getElementById('mainCard'); card.style.transition='opacity .4s,transform .4s';card.style.opacity='0';card.style.transform='translateY(-16px)'; setTimeout(()=>{ card.style.display='none'; // fade progress out const pw=document.getElementById('progWrap'); pw.style.transition='opacity .3s';pw.style.opacity='0'; setTimeout(()=>pw.style.display='none',300); const ty=document.getElementById('tyWrap'); ty.style.display='block';ty.style.opacity='0';ty.style.transform='translateY(20px)';ty.style.transition='all .55s cubic-bezier(.34,1.4,.64,1)'; setTimeout(()=>{ty.style.opacity='1';ty.style.transform='translateY(0)';},40); confetti(); },400); } /* ── SHOW B2 ── */ function showB2(){ const ty=document.getElementById('tyWrap'); ty.style.transition='opacity .3s';ty.style.opacity='0'; setTimeout(()=>{ ty.style.display='none'; const b2=document.getElementById('b2Wrap'); b2.style.display='block';b2.style.opacity='0';b2.style.transform='translateY(20px)';b2.style.transition='all .55s cubic-bezier(.34,1.4,.64,1)'; setTimeout(()=>{b2.style.opacity='1';b2.style.transform='translateY(0)';},40); },300); } /* ── BACK TO TY ── */ function backToTY(){ const b2=document.getElementById('b2Wrap'); b2.style.transition='opacity .3s';b2.style.opacity='0'; setTimeout(()=>{ b2.style.display='none'; const ty=document.getElementById('tyWrap'); ty.style.display='block';ty.style.opacity='0';ty.style.transition='opacity .4s'; setTimeout(()=>ty.style.opacity='1',40); },300); } /* ── SUBMIT B2 (Bloco 2 → servidor) ── */ async function submitB2(btn){ btn.classList.add('loading');btn.disabled=true; const obj=[...document.querySelectorAll('#q1 .ci.sel')].map(e=>e.textContent.trim()); const inv=document.querySelector('#q2 .ri.sel'); const sat=document.querySelector('#q3 .ri.sel'); const pos=[...document.querySelectorAll('#q4 .ci.sel')].map(e=>e.textContent.trim()); try { await fetch(API_URL, { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ action: 'update', id: lid, objetivos: obj, investimento: inv ? inv.textContent.trim() : '', satisfacao: sat ? sat.textContent.trim() : '', possui: pos }) }); } catch(e) { console.error('Erro ao atualizar lead:', e); } // Envia email com todos os dados await sendEmail({ Nome: ans.nome || '', Empresa: ans.empresa || '', WhatsApp: ans.whats || '', Cidade: ans.cidade || '', Objetivos: obj.join(', ') || 'Nenhum', Investimento: inv ? inv.textContent.trim() : 'N�o informado', Satisfacao: sat ? sat.textContent.trim() : 'N�o informado', Possui: pos.join(', ') || 'Nenhum' }, `Lead Completo (Diagn�stico) - ${ans.nome || 'Sem Nome'}`); await wait(900); const b2=document.getElementById('b2Wrap'); b2.style.transition='opacity .3s';b2.style.opacity='0'; setTimeout(()=>{ b2.style.display='none'; const upBtn=document.querySelector('.btn-up'); if(upBtn)upBtn.remove(); const tySub=document.querySelector('.ty-sub'); if(tySub)tySub.textContent='Diagnóstico completo enviado! Nossa equipe vai analisar tudo com cuidado e entrar em contato em breve com um plano personalizado para o seu negócio.'; const ty=document.getElementById('tyWrap'); ty.style.display='block';ty.style.opacity='0';ty.style.transition='all .55s cubic-bezier(.34,1.4,.64,1)';ty.style.transform='translateY(20px)'; setTimeout(()=>{ty.style.opacity='1';ty.style.transform='translateY(0)';},40); confetti(); },300); } /* ── CHECKBOX / RADIO ── */ function tCh(el){el.classList.toggle('sel');} function sRd(el,g){document.querySelectorAll('#'+g+' .ri').forEach(i=>i.classList.remove('sel'));el.classList.add('sel');} /* ── CONFETTI ── */ function confetti(){ const cols=['#ff4739','#ff276d','#fff','#ffbd2e','#28ca41','#60a5fa']; for(let i=0;i<65;i++){ const p=document.createElement('div'); p.className='cof'; p.style.cssText=`left:${Math.random()*100}vw;top:-10px;width:${4+Math.random()*7}px;height:${4+Math.random()*7}px;background:${cols[i%cols.length]};animation-delay:${Math.random()*.9}s;animation-duration:${2+Math.random()*1.8}s;transform:rotate(${Math.random()*360}deg);`; document.body.appendChild(p); setTimeout(()=>p.remove(),4500); } } function xss(s){return String(s).replace(/&/g,'&').replace(//g,'>').replace(/"/g,'"');} function wait(ms){return new Promise(r=>setTimeout(r,ms));} /* INIT */ render(0);