/* PymeLegal WordPress JS */ (function(){ function initPymeLegal(){ const root = document.querySelector('.pl-wrap'); const SCRIPT_URL = root ? root.getAttribute('data-script-url') : ''; if (!root) return; const leadForm = document.getElementById('plLeadForm'); const statusBox = document.getElementById('plFormStatus'); const testGate = document.getElementById('plTestGate'); const showTestBtn = document.getElementById('plShowTest'); const skipTestBtn = document.getElementById('plSkipTest'); const testCard = document.getElementById('plTestCard'); const testForm = document.getElementById('plTestForm'); const resultCard = document.getElementById('plResultCard'); const resultScore = document.getElementById('plResultScore'); const resultTitle = document.getElementById('plResultTitle'); const resultText = document.getElementById('plResultText'); const resultList = document.getElementById('plResultList'); function showStatus(type, message){ statusBox.className = 'pl-form-status is-' + type; statusBox.textContent = message; } if (!leadForm || !statusBox || !testGate || !showTestBtn || !skipTestBtn || !testCard || !testForm || !resultCard || !resultScore || !resultTitle || !resultText || !resultList) { return; } leadForm.addEventListener('submit', async function(event){ event.preventDefault(); const submitButton = leadForm.querySelector('button[type="submit"]'); submitButton.disabled = true; submitButton.textContent = 'Enviando...'; const formData = new FormData(leadForm); const payload = { nombre: formData.get('nombre'), email: formData.get('email'), empresa: formData.get('empresa'), mensaje: formData.get('mensaje'), origen: formData.get('origen') || 'pymelegal.cl' }; let submissionOk = false; if (SCRIPT_URL) { try { await fetch(SCRIPT_URL, { method: 'POST', mode: 'no-cors', headers: { 'Content-Type': 'text/plain;charset=utf-8' }, body: JSON.stringify(payload) }); submissionOk = true; } catch (error) { submissionOk = false; } } testGate.classList.add('is-visible'); testCard.classList.remove('is-visible'); resultCard.classList.remove('is-visible'); if (submissionOk) { showStatus('success', 'Listo. Ya recibimos tus datos. Si quieres, ahora puedes hacer el test de validación de cumplimiento.'); leadForm.reset(); } else { showStatus('error', 'Hubo un problema al enviar el formulario. El Apps Script no está respondiendo de forma usable desde esta landing. Igual puedes continuar con el test.'); } testGate.scrollIntoView({behavior:'smooth', block:'start'}); submitButton.disabled = false; submitButton.textContent = 'Solicitar asesoría gratuita'; }); showTestBtn.addEventListener('click', function(){ testGate.classList.remove('is-visible'); testCard.classList.add('is-visible'); testCard.scrollIntoView({behavior:'smooth', block:'start'}); }); skipTestBtn.addEventListener('click', function(){ testGate.innerHTML = '
Ya recibimos tu solicitud. Te contactaremos pronto para revisar tu caso.