File size: 4,411 Bytes
67fa90b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// ==========================================
// 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 = `<i class="fas ${icons[type]}"></i><span>${message}</span>`;
    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 = '<i class="fas fa-check text-sm"></i>';
        } 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