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
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
// Global State
let state = {
    projects: [],
    clients: [],
    categories: ['Web Development', 'Mobile Apps', 'AI/ML', 'Game Dev', 'Blockchain', 'IoT', 'DevOps', 'Desktop Apps'],
    currentFilter: 'all'
};

// DOM Elements
const recentProjectsTable = document.getElementById('recentProjects');
const projectModal = document.getElementById('projectModal');
let categoryChart = null;
let revenueChart = null;

// Initialize Charts
function initializeCharts() {
    // Category Distribution Chart
    const categoryCtx = document.getElementById('categoryChart').getContext('2d');
    categoryChart = new Chart(categoryCtx, {
        type: 'doughnut',
        data: {
            labels: state.categories,
            datasets: [{
                data: [15, 8, 6, 4, 3, 2, 2, 2],
                backgroundColor: [
                    '#6366f1', '#f59e0b', '#10b981', '#ef4444', '#8b5cf6', '#06b6d4', '#f97316', '#84cc16'
                ],
                borderWidth: 2,
                borderColor: '#0f172a'
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    position: 'right',
                    labels: {
                        color: '#cbd5e1',
                        padding: 20
                    }
                }
            },
            animation: {
                animateScale: true,
                animateRotate: true
            }
        }
    });

    // Revenue Chart
    const revenueCtx = document.getElementById('revenueChart').getContext('2d');
    revenueChart = new Chart(revenueCtx, {
        type: 'line',
        data: {
            labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul'],
            datasets: [{
                label: 'Revenue',
                data: [4500, 5200, 7800, 9200, 12500, 14800, 16500],
                borderColor: '#f59e0b',
                backgroundColor: 'rgba(245, 158, 11, 0.1)',
                borderWidth: 3,
                fill: true,
                tension: 0.4
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    labels: {
                        color: '#cbd5e1'
                    }
                }
            },
            scales: {
                x: {
                    grid: {
                        color: 'rgba(255, 255, 255, 0.1)'
                    },
                    ticks: {
                        color: '#cbd5e1'
                    }
                },
                y: {
                    grid: {
                        color: 'rgba(255, 255, 255, 0.1)'
                    },
                    ticks: {
                        color: '#cbd5e1',
                        callback: function(value) {
                            return '$' + value;
                        }
                    }
                }
            }
        }
    });
}

// Load Recent Projects
function loadRecentProjects() {
    const sampleProjects = [
        {
            id: 1,
            name: 'E-Commerce Platform',
            category: 'Web Development',
            status: 'complete',
            completion: '100%',
            client: 'TechCorp Inc.',
            date: '2024-01-15',
            amount: '$12,500',
            paid: true
        },
        {
            id: 2,
            name: 'Fitness Mobile App',
            category: 'Mobile Apps',
            status: 'in-progress',
            completion: '75%',
            client: 'FitLife LLC',
            date: '2024-02-20',
            amount: '$8,000',
            paid: false
        },
        {
            id: 3,
            name: 'AI Chat Assistant',
            category: 'AI/ML',
            status: 'in-progress',
            completion: '60%',
            client: 'Innovate AI',
            date: '2024-03-10',
            amount: '$15,000',
            paid: true
        },
        {
            id: 4,
            name: 'Blockchain Wallet',
            category: 'Blockchain',
            status: 'pending',
            completion: '30%',
            client: 'CryptoWorks',
            date: '2024-03-25',
            amount: '$20,000',
            paid: false
        },
        {
            id: 5,
            name: 'Game Engine',
            category: 'Game Dev',
            status: 'complete',
            completion: '100%',
            client: 'GameDev Studio',
            date: '2024-01-30',
            amount: '$25,000',
            paid: true
        }
    ];

    recentProjectsTable.innerHTML = '';
    sampleProjects.forEach(project => {
        const row = document.createElement('tr');
        row.className = 'border-b border-gray-700 hover:bg-gray-800/50 transition-colors';
        row.innerHTML = `
            <td class="py-4">
                <div class="flex items-center space-x-3">
                    <div class="w-10 h-10 rounded-lg bg-gradient-to-br from-primary/20 to-secondary/20 flex items-center justify-center">
                        <i data-feather="folder" class="text-primary"></i>
                    </div>
                    <div>
                        <h4 class="font-medium">${project.name}</h4>
                        <p class="text-sm text-gray-400">Started: ${project.date}</p>
                    </div>
                </div>
            </td>
            <td class="py-4">
                <span class="px-3 py-1 rounded-full text-xs bg-gray-700 text-gray-300">${project.category}</span>
            </td>
            <td class="py-4">
                <span class="status-badge status-${project.status}">${project.status.replace('-', ' ')}</span>
            </td>
            <td class="py-4">
                <div class="flex items-center space-x-2">
                    <div class="w-24 h-2 bg-gray-700 rounded-full overflow-hidden">
                        <div class="h-full bg-gradient-to-r from-primary to-secondary" style="width: ${project.completion}"></div>
                    </div>
                    <span class="text-sm">${project.completion}</span>
                </div>
            </td>
            <td class="py-4">
                <div class="flex items-center space-x-2">
                    <div class="w-8 h-8 rounded-full bg-gradient-to-br from-primary to-secondary flex items-center justify-center">
                        <i data-feather="user" class="text-white text-xs"></i>
                    </div>
                    <span>${project.client}</span>
                </div>
            </td>
            <td class="py-4">
                <div class="flex space-x-2">
                    <button class="w-8 h-8 rounded-lg bg-gray-700 hover:bg-gray-600 flex items-center justify-center transition-colors" onclick="viewProject(${project.id})" title="View Details">
                        <i data-feather="eye"></i>
                    </button>
                    <button class="w-8 h-8 rounded-lg bg-primary/20 hover:bg-primary/30 flex items-center justify-center transition-colors" onclick="editProject(${project.id})" title="Edit">
                        <i data-feather="edit-2"></i>
                    </button>
                    <button class="w-8 h-8 rounded-lg ${project.paid ? 'bg-green-500/20 hover:bg-green-500/30' : 'bg-red-500/20 hover:bg-red-500/30'} flex items-center justify-center transition-colors" onclick="togglePayment(${project.id})" title="${project.paid ? 'Mark as Unpaid' : 'Mark as Paid'}">
                        <i data-feather="${project.paid ? 'check-circle' : 'x-circle'}"></i>
                    </button>
                </div>
            </td>
        `;
        recentProjectsTable.appendChild(row);
    });
    feather.replace();
}

// View Project Details
function viewProject(id) {
    const project = {
        id: id,
        name: 'Sample Project Details',
        description: 'Detailed information about the project including requirements, progress, and client communications.',
        category: 'Web Development',
        status: 'in-progress',
        startDate: '2024-01-15',
        deadline: '2024-04-30',
        client: 'TechCorp Inc.',
        budget: '$12,500',
        paid: '$8,000',
        pending: '$4,500',
        progress: '75%',
        images: [
            'http://static.photos/technology/640x360/1',
            'http://static.photos/technology/640x360/2',
            'http://static.photos/technology/640x360/3'
        ]
    };

    projectModal.innerHTML = `
        <div class="space-y-6">
            <div class="flex justify-between items-start">
                <div>
                    <h3 class="text-2xl font-bold">${project.name}</h3>
                    <p class="text-gray-400 mt-2">${project.category}</p>
                </div>
                <button onclick="closeModal()" class="w-10 h-10 rounded-full bg-gray-700 hover:bg-gray-600 flex items-center justify-center transition-colors">
                    <i data-feather="x"></i>
                </button>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                    <h4 class="font-semibold mb-2">Project Description</h4>
                    <p class="text-gray-300">${project.description}</p>
                </div>
                <div>
                    <h4 class="font-semibold mb-2">Progress</h4>
                    <div class="space-y-4">
                        <div>
                            <div class="flex justify-between mb-1">
                                <span>Completion</span>
                                <span>${project.progress}</span>
                            </div>
                            <div class="w-full h-3 bg-gray-700 rounded-full overflow-hidden">
                                <div class="h-full bg-gradient-to-r from-primary to-secondary" style="width: ${project.progress}"></div>
                            </div>
                        </div>
                        <div class="flex justify-between">
                            <div>
                                <p class="text-sm text-gray-400">Start Date</p>
                                <p class="font-medium">${project.startDate}</p>
                            </div>
                            <div>
                                <p class="text-sm text-gray-400">Deadline</p>
                                <p class="font-medium">${project.deadline}</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                <div class="bg-gray-700/30 p-4 rounded-xl">
                    <p class="text-sm text-gray-400">Total Budget</p>
                    <p class="text-2xl font-bold">${project.budget}</p>
                </div>
                <div class="bg-green-500/10 p-4 rounded-xl">
                    <p class="text-sm text-gray-400">Amount Paid</p>
                    <p class="text-2xl font-bold text-green-400">${project.paid}</p>
                </div>
                <div class="bg-red-500/10 p-4 rounded-xl">
                    <p class="text-sm text-gray-400">Pending Amount</p>
                    <p class="text-2xl font-bold text-red-400">${project.pending}</p>
                </div>
            </div>
            
            <div>
                <h4 class="font-semibold mb-3">Project Images</h4>
                <div class="grid grid-cols-3 gap-4">
                    ${project.images.map(img => `
                        <div class="aspect-video rounded-lg overflow-hidden">
                            <img src="${img}" alt="Project Screenshot" class="w-full h-full object-cover hover:scale-110 transition-transform duration-300">
                        </div>
                    `).join('')}
                </div>
            </div>
            
            <div class="flex justify-end space-x-4">
                <button onclick="closeModal()" class="px-6 py-3 bg-gray-700 hover:bg-gray-600 rounded-lg font-medium transition-colors">
                    Close
                </button>
                <button onclick="generateReport(${id})" class="px-6 py-3 bg-primary hover:bg-primary/80 rounded-lg font-medium flex items-center space-x-2 transition-colors">
                    <i data-feather="printer"></i>
                    <span>Print Report</span>
                </button>
            </div>
        </div>
    `;
    
    projectModal.classList.remove('hidden');
    projectModal.classList.add('flex');
    feather.replace();
}

// Edit Project
function editProject(id) {
    alert(`Editing project #${id} - Feature coming soon!`);
}

// Toggle Payment Status
function togglePayment(id) {
    alert(`Toggling payment status for project #${id} - Feature coming soon!`);
}

// Generate Report
function generateReport(id) {
    const printWindow = window.open('', '_blank');
    printWindow.document.write(`
        <html>
        <head>
            <title>Project Report #${id}</title>
            <style>
                body { font-family: Arial, sans-serif; margin: 40px; }
                h1 { color: #333; }
                .section { margin: 30px 0; }
                table { width: 100%; border-collapse: collapse; }
                th, td { border: 1px solid #ddd; padding: 12px; text-align: left; }
                th { background-color: #f5f5f5; }
                .total { font-weight: bold; font-size: 1.2em; }
                @media print {
                    .no-print { display: none; }
                }
            </style>
        </head>
        <body>
            <h1>CodeVault Pro - Project Report</h1>
            <p>Generated on: ${new Date().toLocaleDateString()}</p>
            
            <div class="section">
                <h2>Project Summary</h2>
                <p>Complete project report including timeline, budget, and progress details.</p>
            </div>
            
            <div class="section">
                <h2>Financial Summary</h2>
                <table>
                    <tr>
                        <th>Item</th>
                        <th>Amount</th>
                    </tr>
                    <tr>
                        <td>Total Budget</td>
                        <td>$12,500.00</td>
                    </tr>
                    <tr>
                        <td>Amount Received</td>
                        <td>$8,000.00</td>
                    </tr>
                    <tr class="total">
                        <td>Pending Amount</td>
                        <td>$4,500.00</td>
                    </tr>
                </table>
            </div>
            
            <div class="section">
                <h2>Project Timeline</h2>
                <table>
                    <tr>
                        <th>Phase</th>
                        <th>Status</th>
                        <th>Completion Date</th>
                    </tr>
                    <tr>
                        <td>Planning</td>
                        <td>Completed</td>
                        <td>2024-01-20</td>
                    </tr>
                    <tr>
                        <td>Development</td>
                        <td>In Progress</td>
                        <td>2024-04-15</td>
                    </tr>
                    <tr>
                        <td>Testing</td>
                        <td>Pending</td>
                        <td>2024-04-30</td>
                    </tr>
                </table>
            </div>
            
            <div class="section no-print">
                <button onclick="window.print()">Print Report</button>
            </div>
        </body>
        </html>
    `);
    printWindow.document.close();
}

// Close Modal
function closeModal() {
    projectModal.classList.add('hidden');
    projectModal.classList.remove('flex');
}

// Print Report
window.printReport = function() {
    window.print();
}

// Filter Projects
function filterProjects(category) {
    state.currentFilter = category;
    alert(`Filtering projects by: ${category === 'all' ? 'All Categories' : category}`);
}

// Add New Project
function addNewProject() {
    alert('Add New Project feature coming soon!');
}

// Add New Client
function addNewClient() {
    alert('Add New Client feature coming soon!');
}

// Initialize app
document.addEventListener('DOMContentLoaded', function() {
    // Load initial data
    loadRecentProjects();
    
    // Add event listeners for navigation
    document.addEventListener('click', function(e) {
        if (e.target.closest('[data-nav]')) {
            const page = e.target.closest('[data-nav]').getAttribute('data-nav');
            navigateTo(page);
        }
    });
});

// Navigation function
function navigateTo(page) {
    // In a real app, this would load different pages
    alert(`Navigating to ${page} - Feature coming soon!`);
}