// ========================================== // LegalData Manager - Client Portal // ========================================== let clientFiles = []; let clientData = {}; // --- Toast --- function showToast(message, type = 'success') { const container = document.getElementById('toast-container'); const colors = { success: 'bg-green-500', error: 'bg-red-500', info: 'bg-blue-500', warning: 'bg-yellow-500' }; const icons = { success: 'fa-check-circle', error: 'fa-times-circle', info: 'fa-info-circle', warning: 'fa-exclamation-triangle' }; const toast = document.createElement('div'); toast.className = `toast ${colors[type]} text-white px-4 py-3 rounded-lg shadow-lg flex items-center space-x-3 min-w-72`; toast.innerHTML = `${message}`; container.appendChild(toast); requestAnimationFrame(() => toast.classList.add('show')); setTimeout(() => { toast.classList.remove('show'); setTimeout(() => toast.remove(), 400); }, 4000); } // --- Step Navigation --- function goToStep(step) { // Hide all steps document.getElementById('form-step-1').classList.add('hidden'); document.getElementById('form-step-2').classList.add('hidden'); document.getElementById('form-step-3').classList.add('hidden'); // Show current step document.getElementById('form-step-' + step).classList.remove('hidden'); // Update step indicators for (let i = 1; i <= 3; i++) { const circle = document.getElementById('step-' + i); const line = document.getElementById('line-' + (i - 1)); circle.classList.remove('active', 'completed'); if (i < step) { circle.classList.add('completed'); circle.innerHTML = ''; } else if (i === step) { circle.classList.add('active'); circle.textContent = i; } else { circle.textContent = i; } if (line) { line.classList.toggle('active', i <= step); } } window.scrollTo({ top: 0, behavior: 'smooth' }); } // --- Client Form --- function handleClientSubmit(event) { event.preventDefault(); const nome = document.getElementById('reg-nome').value; const tipo = document.getElementById('reg-tipo').value; const cpfCnpj = document.getElementById('reg-cpfcnpj').value; const email = document.getElementById('reg-email').value; const telefone = document.getElementById('reg-telefone').value; if (!nome || !cpfCnpj || !email || !telefone) { showToast('Preencha todos os campos obrigatórios', 'error'); return false; } // Validate email if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { showToast('E-mail inválido', 'error'); return false; } // Save client data clientData = { id: Date.now(), nome: nome, tipo: tipo, cpfCnpj: cpfCnpj, rg: document.getElementById('reg-rg').value, email: email, telefone: telefone, endereco: document.getElementById('reg-endereco').value, profissao: document.getElementById('reg-profissao').value, estadoCivil: document.getElementById('reg-estadocivil').value, tipoProcesso: document.getElementById('reg-tipo-processo').value, descricao: document.getElementById('reg-descricao').value, dataCadastro: new Date().toISOString() }; // Save to localStorage (shared with main app) let appData = {}; try { const saved = localStorage.getItem('legaldata_app'); if (saved) appData = JSON.parse(saved); } catch(e) {} if (!appData.clientes) appData.clientes = []; // Check if already registered const exists = appData.clientes.find(c => c.cpfCnpj === cpfCnpj); if (exists) { clientData.id = exists.id; showToast('Cliente já cadastrado. Prossiga com o envio de provas.', 'info'); } else { appData.clientes.push({ id: clientData.id, nome: clientData.nome, tipo: clientData.tipo, cpfCnpj: clientData.cpfCnpj, email: clientData.email, telefone: clientData.telefone, endereco: clientData.endereco, processos: 0 }); } localStorage.setItem('legaldata_app', JSON.stringify(appData