File size: 11,149 Bytes
a39cdcd
 
 
 
 
 
 
c68dffd
 
a39cdcd
 
 
 
 
 
 
 
 
c68dffd
 
 
a39cdcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c68dffd
 
 
a39cdcd
 
 
c68dffd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a39cdcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f870dda
 
 
a39cdcd
 
 
 
 
 
f870dda
a39cdcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f870dda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355

// Database simulation (in a real app, this would be API calls)
const db = {
    founders: [],
    advisors: [],
    matches: [],
    insights: [],
    users: [],
    pendingApprovals: [],

    // Initialize with sample data
    init() {
        if (localStorage.getItem('lumikiza_db')) {
            const saved = JSON.parse(localStorage.getItem('lumikiza_db'));
            this.founders = saved.founders || [];
            this.advisors = saved.advisors || [];
            this.matches = saved.matches || [];
            this.insights = saved.insights || [];
            this.users = saved.users || [];
            this.pendingApprovals = saved.pendingApprovals || [];
} else {
            // Sample data
            this.founders = Array.from({length: 50}, (_, i) => ({
                id: `f${i+1}`,
                name: `Founder ${i+1}`,
                business: `Business ${i+1}`,
                stage: ['idea', 'pre-revenue', 'early-revenue', 'growth'][Math.floor(Math.random() * 4)],
                needs: ['funding', 'marketing', 'strategy', 'operations', 'technology'].filter(() => Math.random() > 0.5),
                registeredAt: new Date(Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000)
            }));

            this.advisors = Array.from({length: 30}, (_, i) => ({
                id: `a${i+1}`,
                name: `Advisor ${i+1}`,
                expertise: ['finance', 'marketing', 'tech', 'operations', 'legal'].filter(() => Math.random() > 0.5),
                industries: ['tech', 'agriculture', 'healthcare', 'finance', 'manufacturing'].filter(() => Math.random() > 0.5),
                registeredAt: new Date(Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000)
            }));

            this.matches = Array.from({length: 100}, (_, i) => ({
                id: `m${i+1}`,
                founderId: `f${Math.floor(Math.random() * 50) + 1}`,
                advisorId: `a${Math.floor(Math.random() * 30) + 1}`,
                matchedAt: new Date(Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000),
                success: Math.random() > 0.3
            }));

            this.save();
        }
    },

    // Save to localStorage
    save() {
        localStorage.setItem('lumikiza_db', JSON.stringify({
            founders: this.founders,
            advisors: this.advisors,
            matches: this.matches,
            insights: this.insights,
            users: this.users,
            pendingApprovals: this.pendingApprovals
        }));
    },

    // Admin functions
    getPendingApprovals() {
        return this.users.filter(user => user.status === 'pending');
    },

    approveUser(userId) {
        const user = this.users.find(u => u.id === userId);
        if (user) {
            user.status = 'active';
            this.save();
            return true;
        }
        return false;
    },

    suspendUser(userId) {
        const user = this.users.find(u => u.id === userId);
        if (user) {
            user.status = 'suspended';
            this.save();
            return true;
        }
        return false;
    },

    deleteUser(userId) {
        const index = this.users.findIndex(u => u.id === userId);
        if (index !== -1) {
            this.users.splice(index, 1);
            this.save();
            return true;
        }
        return false;
    },

    getPendingMatches() {
        return this.matches.filter(match => match.status === 'pending');
    },

    approveMatch(matchId) {
        const match = this.matches.find(m => m.id === matchId);
        if (match) {
            match.status = 'approved';
            this.save();
            return true;
        }
        return false;
    },

    rejectMatch(matchId) {
        const match = this.matches.find(m => m.id === matchId);
        if (match) {
            match.status = 'rejected';
            this.save();
            return true;
        }
        return false;
    },

    createManualMatch(founderId, advisorId) {
        const newMatch = {
            id: `m${Date.now()}`,
            founderId,
            advisorId,
            matchedAt: new Date(),
            status: 'approved',
            isManual: true,
            score: Math.floor(Math.random() * 30) + 70 // Random score 70-100
        };
        this.matches.push(newMatch);
        this.save();
        return newMatch;
    },
// AI analysis functions
    analyzeMatches() {
        const insights = [];
        
        // Find most common founder needs
        const needsCount = {};
        this.founders.forEach(f => {
            f.needs.forEach(n => {
                needsCount[n] = (needsCount[n] || 0) + 1;
            });
        });
        
        insights.push({
            type: 'founder_needs',
            data: needsCount,
            timestamp: new Date()
        });

        // Find most common advisor expertise
        const expertiseCount = {};
        this.advisors.forEach(a => {
            a.expertise.forEach(e => {
                expertiseCount[e] = (expertiseCount[e] || 0) + 1;
            });
        });

        insights.push({
            type: 'advisor_expertise',
            data: expertiseCount,
            timestamp: new Date()
        });

        // Calculate match success rate
        const totalMatches = this.matches.length;
        const successfulMatches = this.matches.filter(m => m.success).length;
        const successRate = (successfulMatches / totalMatches) * 100;

        insights.push({
            type: 'match_success',
            data: { rate: successRate },
            timestamp: new Date()
        });

        this.insights = insights;
        this.save();
        return insights;
    },

    // Get AI recommendations for matches
    getMatchRecommendations(founderId) {
        const founder = this.founders.find(f => f.id === founderId);
        if (!founder) return [];

        // Find advisors with matching expertise
        return this.advisors.filter(advisor => 
            advisor.expertise.some(e => founder.needs.includes(e))
        ).map(advisor => ({
            advisor,
            score: Math.floor(Math.random() * 41) + 60 // Random score between 60-100
        })).sort((a, b) => b.score - a.score);
    }
};

// Initialize database
db.init();

// Shared functions
function initTooltips() {
const tooltipTriggers = document.querySelectorAll('[data-tooltip]');
    
    tooltipTriggers.forEach(trigger => {
        const tooltip = document.createElement('div');
        tooltip.className = 'tooltip hidden absolute z-50 bg-gray-800 text-white text-xs rounded py-1 px-2';
        tooltip.textContent = trigger.getAttribute('data-tooltip');
        trigger.appendChild(tooltip);
        
        trigger.addEventListener('mouseenter', () => {
            tooltip.classList.remove('hidden');
        });
        
        trigger.addEventListener('mouseleave', () => {
            tooltip.classList.add('hidden');
        });
    });
}
document.addEventListener('DOMContentLoaded', function() {
    // Initialize all tooltips
    initTooltips();
    
    // Initialize authentication
    initAuth();
    
    // Animate elements on scroll
    const animateOnScroll = () => {
        const elements = document.querySelectorAll('.animate-on-scroll');
        
        elements.forEach(el => {
            const rect = el.getBoundingClientRect();
        const isVisible = (rect.top <= window.innerHeight * 0.75) && (rect.bottom >= 0);
            
            if (isVisible) {
                el.classList.add('animate-fade-in');
            }
        });
    };
    
    window.addEventListener('scroll', animateOnScroll);
    animateOnScroll(); // Run once on load
});
// Form validation helper
function validateForm(formId) {
    const form = document.getElementById(formId);
    if (!form) return true;
    
    let isValid = true;
    const inputs = form.querySelectorAll('input[required], select[required], textarea[required]');
    
    inputs.forEach(input => {
        if (!input.value.trim()) {
            input.classList.add('border-red-500');
            isValid = false;
        } else {
            input.classList.remove('border-red-500');
        }
    });
    
    return isValid;
}
// Login simulation (in real app, this would be API calls)
function simulateLogin(email, password) {
    const db = JSON.parse(localStorage.getItem('lumikiza_db') || { founders: [], advisors: [] };
    
    // Check if user exists
    const allUsers = [...db.founders, ...db.advisors];
    const user = allUsers.find(u => u.email === email);
    
    if (user) {
        // In a real app, password would be hashed and verified
        return { success: true, user: user, userType: db.founders.includes(user) ? 'founder' : 'advisor';
    } else {
        return { success: false, message: 'Invalid email or password' };
    }
}

// Check if user is logged in
function checkAuth() {
    const token = localStorage.getItem('auth_token');
    if (!token) {
        // Redirect to login if not authenticated
        if (window.location.pathname !== '/login.html' && window.location.pathname !== '/register.html' && window.location.pathname !== '/register-founder.html' && window.location.pathname !== '/register-advisor.html' && window.location.pathname !== '/') {
            window.location.href = '/login.html';
        }
    }
    
    // Update navigation based on authentication status
    updateNavigation();
}

// Update navigation based on authentication
function updateNavigation() {
    const token = localStorage.getItem('auth_token');
    const userType = localStorage.getItem('user_type');
    
    if (token && userType) {
        // User is logged in
        const navLinks = document.querySelectorAll('.nav-links, .mobile-menu');
        
        navLinks.forEach(container => {
            const loginLink = container.querySelector('a[href="/login.html"]');
            if (loginLink) {
                loginLink.textContent = 'Logout';
                loginLink.href = '#';
            }
        });
    }
}

// Handle login form submission
function handleLogin(email, password) {
    const result = simulateLogin(email, password);
    
    if (result.success) {
        // Store authentication token and user info
        localStorage.setItem('auth_token', 'authenticated_' + Date.now());
        localStorage.setItem('user_type', userType);
        localStorage.setItem('user_email', email);
        
        // Redirect based on user type
        if (result.userType === 'founder') {
            window.location.href = '/dashboard.html';
        } else {
            window.location.href = '/ceo-dashboard.html';
        }
    } else {
        alert(result.message);
        return false;
    }
    
    return true;
}

// Handle logout
function handleLogout() {
    localStorage.removeItem('auth_token');
    localStorage.removeItem('user_type');
    localStorage.removeItem('user_email');
        window.location.href = '/';
    }
}

// Initialize authentication
function initAuth() {
    const token = localStorage.getItem('auth_token');
    
    if (token) {
        updateNavigation();
    }
}