Spaces:
Running

File size: 35,876 Bytes
14ebcbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Suivi PIC Valais</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .pillar-color-1 { background-color: #E3F2FD; }
        .pillar-color-2 { background-color: #E8F5E9; }
        .pillar-color-3 { background-color: #FFF8E1; }
        .pillar-color-4 { background-color: #F3E5F5; }
        
        .chart-container {
            position: relative;
            height: 300px;
            width: 100%;
        }
        
        .fade-in {
            animation: fadeIn 0.5s ease-in-out;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="container mx-auto px-4 py-8">
        <!-- Header -->
        <header class="mb-8">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div>
                    <h1 class="text-3xl font-bold text-gray-800">Suivi PIC Valais</h1>
                    <p class="text-gray-600">Programme d'Intégration Cantonal</p>
                </div>
                <img src="https://www.vs.ch/documents/267648/0/logo_etat_du_valais.png" alt="Logo Valais" class="h-16 mt-4 md:mt-0">
            </div>
        </header>

        <!-- Navigation Tabs -->
        <div class="mb-8">
            <div class="flex flex-wrap border-b border-gray-200">
                <button id="dashboard-tab" class="px-4 py-2 font-medium text-blue-600 border-b-2 border-blue-600">Tableau de bord</button>
                <button id="add-tab" class="px-4 py-2 font-medium text-gray-500 hover:text-gray-700">Ajouter un suivi</button>
                <button id="stats-tab" class="px-4 py-2 font-medium text-gray-500 hover:text-gray-700">Statistiques</button>
                <button id="export-btn" class="px-4 py-2 font-medium text-gray-500 hover:text-gray-700 ml-auto">
                    <i class="fas fa-download mr-2"></i>Exporter CSV
                </button>
            </div>
        </div>

        <!-- Dashboard Content -->
        <div id="dashboard-content" class="fade-in">
            <!-- Search and Filter -->
            <div class="mb-6 flex flex-col md:flex-row gap-4">
                <div class="relative flex-grow">
                    <input type="text" placeholder="Rechercher..." class="w-full pl-10 pr-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                    <i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
                </div>
                <select class="border rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
                    <option>Tous les piliers</option>
                    <option>Primo-info</option>
                    <option>Conseils</option>
                    <option>Protection contre la discrimination</option>
                    <option>Langue et formation</option>
                    <option>Petite enfance</option>
                    <option>Employabilité</option>
                    <option>Interprétariat</option>
                    <option>Vivre-ensemble</option>
                </select>
                <select class="border rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
                    <option>Tous les types</option>
                    <option>Appel</option>
                    <option>Entretien</option>
                    <option>Email</option>
                </select>
            </div>

            <!-- Stats Cards -->
            <div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-8">
                <div class="bg-white p-4 rounded-lg shadow">
                    <div class="flex items-center">
                        <div class="p-3 rounded-full bg-blue-100 text-blue-600 mr-4">
                            <i class="fas fa-phone-alt text-xl"></i>
                        </div>
                        <div>
                            <p class="text-gray-500">Appels</p>
                            <h3 class="text-2xl font-bold" id="calls-count">0</h3>
                        </div>
                    </div>
                </div>
                <div class="bg-white p-4 rounded-lg shadow">
                    <div class="flex items-center">
                        <div class="p-3 rounded-full bg-green-100 text-green-600 mr-4">
                            <i class="fas fa-handshake text-xl"></i>
                        </div>
                        <div>
                            <p class="text-gray-500">Entretiens</p>
                            <h3 class="text-2xl font-bold" id="meetings-count">0</h3>
                        </div>
                    </div>
                </div>
                <div class="bg-white p-4 rounded-lg shadow">
                    <div class="flex items-center">
                        <div class="p-3 rounded-full bg-yellow-100 text-yellow-600 mr-4">
                            <i class="fas fa-envelope text-xl"></i>
                        </div>
                        <div>
                            <p class="text-gray-500">Emails</p>
                            <h3 class="text-2xl font-bold" id="emails-count">0</h3>
                        </div>
                    </div>
                </div>
                <div class="bg-white p-4 rounded-lg shadow">
                    <div class="flex items-center">
                        <div class="p-3 rounded-full bg-purple-100 text-purple-600 mr-4">
                            <i class="fas fa-users text-xl"></i>
                        </div>
                        <div>
                            <p class="text-gray-500">Bénéficiaires</p>
                            <h3 class="text-2xl font-bold" id="beneficiaries-count">0</h3>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Recent Activities -->
            <div class="bg-white rounded-lg shadow overflow-hidden mb-8">
                <div class="px-6 py-4 border-b">
                    <h2 class="text-xl font-semibold text-gray-800">Activités récentes</h2>
                </div>
                <div class="divide-y divide-gray-200" id="activities-list">
                    <!-- Activities will be added here by JavaScript -->
                </div>
            </div>

            <!-- Pillar Distribution -->
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <div class="bg-white p-6 rounded-lg shadow">
                    <h3 class="text-lg font-semibold mb-4">Répartition par pilier</h3>
                    <div class="chart-container">
                        <canvas id="pillarChart"></canvas>
                    </div>
                </div>
                <div class="bg-white p-6 rounded-lg shadow">
                    <h3 class="text-lg font-semibold mb-4">Types de contact</h3>
                    <div class="chart-container">
                        <canvas id="typeChart"></canvas>
                    </div>
                </div>
            </div>
        </div>

        <!-- Add Content (hidden by default) -->
        <div id="add-content" class="hidden fade-in">
            <div class="bg-white rounded-lg shadow overflow-hidden max-w-2xl mx-auto">
                <div class="px-6 py-4 border-b">
                    <h2 class="text-xl font-semibold text-gray-800">Nouveau suivi</h2>
                </div>
                <div class="p-6">
                    <form id="tracking-form">
                        <div class="mb-4">
                            <label class="block text-gray-700 mb-2" for="contact-type">Type de contact</label>
                            <div class="flex space-x-4">
                                <label class="inline-flex items-center">
                                    <input type="radio" name="contact-type" value="call" class="form-radio text-blue-600" checked>
                                    <span class="ml-2">Appel</span>
                                </label>
                                <label class="inline-flex items-center">
                                    <input type="radio" name="contact-type" value="meeting" class="form-radio text-green-600">
                                    <span class="ml-2">Entretien</span>
                                </label>
                                <label class="inline-flex items-center">
                                    <input type="radio" name="contact-type" value="email" class="form-radio text-yellow-600">
                                    <span class="ml-2">Email</span>
                                </label>
                            </div>
                        </div>

                        <div class="mb-4">
                            <label class="block text-gray-700 mb-2" for="date">Date</label>
                            <input type="date" id="date" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                        </div>

                        <div class="mb-4">
                            <label class="block text-gray-700 mb-2" for="beneficiary">Bénéficiaire</label>
                            <input type="text" id="beneficiary" placeholder="Nom du bénéficiaire" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                        </div>

                        <div class="mb-4">
                            <label class="block text-gray-700 mb-2" for="pillar">Pilier PIC</label>
                            <select id="pillar" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                                <option value="">Sélectionner un pilier</option>
                                <option value="1">Primo-info</option>
                                <option value="2">Conseils</option>
                                <option value="3">Protection contre la discrimination</option>
                                <option value="4">Langue et formation</option>
                                <option value="5">Petite enfance</option>
                                <option value="6">Employabilité</option>
                                <option value="7">Interprétariat</option>
                                <option value="8">Vivre-ensemble</option>
                            </select>
                        </div>

                        <div class="mb-4">
                            <label class="block text-gray-700 mb-2" for="details">Détails</label>
                            <textarea id="details" rows="4" placeholder="Notes sur le contact..." class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"></textarea>
                        </div>

                        <div class="flex justify-end">
                            <button type="button" id="cancel-btn" class="px-4 py-2 mr-2 text-gray-700 border rounded-lg hover:bg-gray-100">Annuler</button>
                            <button type="submit" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500">
                                Enregistrer
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <!-- Stats Content (hidden by default) -->
        <div id="stats-content" class="hidden fade-in">
            <div class="bg-white rounded-lg shadow overflow-hidden mb-8">
                <div class="px-6 py-4 border-b">
                    <h2 class="text-xl font-semibold text-gray-800">Statistiques globales</h2>
                </div>
                <div class="p-6">
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-8">
                        <div>
                            <h3 class="text-lg font-semibold mb-4">Activités par mois</h3>
                            <div class="chart-container">
                                <canvas id="monthlyChart"></canvas>
                            </div>
                        </div>
                        <div>
                            <h3 class="text-lg font-semibold mb-4">Répartition par bénéficiaire</h3>
                            <div class="chart-container">
                                <canvas id="beneficiaryChart"></canvas>
                            </div>
                        </div>
                    </div>

                    <div class="overflow-x-auto">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Bénéficiaire</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Appels</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Entretiens</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Emails</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Total</th>
                                </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-gray-200" id="stats-table-body">
                                <!-- Stats rows will be added here by JavaScript -->
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script>
        // Sample data
        let trackings = [
            { id: 1, type: 'call', date: '2023-06-15', beneficiary: 'Jean Dupont', pillar: '1', details: 'Appel pour information sur cours de français' },
            { id: 2, type: 'meeting', date: '2023-06-10', beneficiary: 'Maria Garcia', pillar: '3', details: 'Entretien orientation professionnelle' },
            { id: 3, type: 'email', date: '2023-06-05', beneficiary: 'Ahmed Khan', pillar: '4', details: 'Email concernant accès aux soins' },
            { id: 4, type: 'call', date: '2023-05-28', beneficiary: 'Sophie Martin', pillar: '2', details: 'Appel pour questions sur droits et devoirs' },
            { id: 5, type: 'meeting', date: '2023-05-20', beneficiary: 'Jean Dupont', pillar: '1', details: 'Évaluation niveau de langue' }
        ];

        // DOM Elements
        const dashboardTab = document.getElementById('dashboard-tab');
        const addTab = document.getElementById('add-tab');
        const statsTab = document.getElementById('stats-tab');
        const exportBtn = document.getElementById('export-btn');
        const dashboardContent = document.getElementById('dashboard-content');
        const addContent = document.getElementById('add-content');
        const statsContent = document.getElementById('stats-content');
        const trackingForm = document.getElementById('tracking-form');
        const cancelBtn = document.getElementById('cancel-btn');
        const activitiesList = document.getElementById('activities-list');
        const statsTableBody = document.getElementById('stats-table-body');
        
        // Count elements
        const callsCount = document.getElementById('calls-count');
        const meetingsCount = document.getElementById('meetings-count');
        const emailsCount = document.getElementById('emails-count');
        const beneficiariesCount = document.getElementById('beneficiaries-count');

        // Charts
        let pillarChart, typeChart, monthlyChart, beneficiaryChart;

        // Export to CSV
        function exportToCSV() {
            const headers = ['Type', 'Date', 'Bénéficiaire', 'Pilier', 'Détails'];
            const csvContent = [
                headers.join(','),
                ...trackings.map(t => [
                    t.type === 'call' ? 'Appel' : t.type === 'meeting' ? 'Entretien' : 'Email',
                    formatDate(t.date),
                    `"${t.beneficiary}"`,
                    `Pilier ${t.pillar}`,
                    `"${t.details}"`
                ].join(','))
            ].join('\n');

            const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
            const url = URL.createObjectURL(blob);
            const link = document.createElement('a');
            link.setAttribute('href', url);
            link.setAttribute('download', `suivi_pic_${new Date().toISOString().slice(0,10)}.csv`);
            link.style.visibility = 'hidden';
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        }

        // Export to CSV
        function exportToCSV() {
            const headers = ['Type', 'Date', 'Bénéficiaire', 'Pilier', 'Détails'];
            const csvContent = [
                headers.join(','),
                ...trackings.map(t => [
                    t.type === 'call' ? 'Appel' : t.type === 'meeting' ? 'Entretien' : 'Email',
                    formatDate(t.date),
                    `"${t.beneficiary}"`,
                    `Pilier ${t.pillar}`,
                    `"${t.details}"`
                ].join(','))
            ].join('\n');

            const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
            const url = URL.createObjectURL(blob);
            const link = document.createElement('a');
            link.setAttribute('href', url);
            link.setAttribute('download', `suivi_pic_${new Date().toISOString().slice(0,10)}.csv`);
            link.style.visibility = 'hidden';
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        }

        // Initialize the app
        function initApp() {
            updateCounts();
            renderActivities();
            renderStatsTable();
            initCharts();
            setupEventListeners();
        }

        // Update counts
        function updateCounts() {
            const calls = trackings.filter(t => t.type === 'call').length;
            const meetings = trackings.filter(t => t.type === 'meeting').length;
            const emails = trackings.filter(t => t.type === 'email').length;
            const beneficiaries = [...new Set(trackings.map(t => t.beneficiary))].length;
            
            callsCount.textContent = calls;
            meetingsCount.textContent = meetings;
            emailsCount.textContent = emails;
            beneficiariesCount.textContent = beneficiaries;
        }

        // Render activities
        function renderActivities() {
            activitiesList.innerHTML = '';
            
            // Sort by date (newest first)
            const sortedTrackings = [...trackings].sort((a, b) => new Date(b.date) - new Date(a.date));
            
            sortedTrackings.slice(0, 5).forEach(tracking => {
                const activityItem = document.createElement('div');
                activityItem.className = 'px-6 py-4 flex items-start';
                
                let iconClass, iconColor, typeText;
                
                switch(tracking.type) {
                    case 'call':
                        iconClass = 'fa-phone-alt';
                        iconColor = 'text-blue-500';
                        typeText = 'Appel';
                        break;
                    case 'meeting':
                        iconClass = 'fa-handshake';
                        iconColor = 'text-green-500';
                        typeText = 'Entretien';
                        break;
                    case 'email':
                        iconClass = 'fa-envelope';
                        iconColor = 'text-yellow-500';
                        typeText = 'Email';
                        break;
                }
                
                const pillarClass = `pillar-color-${tracking.pillar}`;
                
                activityItem.innerHTML = `
                    <div class="flex-shrink-0 pt-1">
                        <div class="h-10 w-10 rounded-full ${iconColor} flex items-center justify-center">
                            <i class="fas ${iconClass} text-lg"></i>
                        </div>
                    </div>
                    <div class="ml-4 flex-1">
                        <div class="flex items-center justify-between">
                            <h4 class="text-sm font-medium text-gray-900">${tracking.beneficiary}</h4>
                            <span class="text-xs text-gray-500">${formatDate(tracking.date)}</span>
                        </div>
                        <div class="mt-1 flex items-center">
                            <span class="text-xs px-2 py-1 rounded-full ${pillarClass} mr-2">${getPillarName(tracking.pillar)}</span>
                            <span class="text-xs text-gray-500">${typeText}</span>
                        </div>
                        <p class="mt-1 text-sm text-gray-600">${tracking.details}</p>
                    </div>
                `;
                
                activitiesList.appendChild(activityItem);
            });
        }

        // Render stats table
        function renderStatsTable() {
            statsTableBody.innerHTML = '';
            
            const beneficiaries = [...new Set(trackings.map(t => t.beneficiary))];
            const stats = beneficiaries.map(beneficiary => {
                const beneficiaryTrackings = trackings.filter(t => t.beneficiary === beneficiary);
                return {
                    beneficiary,
                    calls: beneficiaryTrackings.filter(t => t.type === 'call').length,
                    meetings: beneficiaryTrackings.filter(t => t.type === 'meeting').length,
                    emails: beneficiaryTrackings.filter(t => t.type === 'email').length,
                    total: beneficiaryTrackings.length
                };
            });
            
            stats.sort((a, b) => b.total - a.total).forEach(stat => {
                const row = document.createElement('tr');
                row.innerHTML = `
                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${stat.beneficiary}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${stat.calls}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${stat.meetings}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${stat.emails}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 font-semibold">${stat.total}</td>
                `;
                statsTableBody.appendChild(row);
            });
        }

        // Initialize charts
        function initCharts() {
            // Pillar distribution chart
            const pillarCtx = document.getElementById('pillarChart').getContext('2d');
            const pillarData = {
                labels: ['Primo-info', 'Conseils', 'Protection contre la discrimination', 'Langue et formation', 'Petite enfance', 'Employabilité', 'Interprétariat', 'Vivre-ensemble'],
                datasets: [{
                    data: [
                        trackings.filter(t => t.pillar === '1').length,
                        trackings.filter(t => t.pillar === '2').length,
                        trackings.filter(t => t.pillar === '3').length,
                        trackings.filter(t => t.pillar === '4').length
                    ],
                    backgroundColor: [
                        '#E3F2FD',
                        '#E8F5E9',
                        '#FFF8E1',
                        '#F3E5F5'
                    ],
                    borderWidth: 1
                }]
            };
            
            pillarChart = new Chart(pillarCtx, {
                type: 'doughnut',
                data: pillarData,
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    plugins: {
                        legend: {
                            position: 'right'
                        }
                    }
                }
            });
            
            // Type distribution chart
            const typeCtx = document.getElementById('typeChart').getContext('2d');
            const typeData = {
                labels: ['Appels', 'Entretiens', 'Emails'],
                datasets: [{
                    data: [
                        trackings.filter(t => t.type === 'call').length,
                        trackings.filter(t => t.type === 'meeting').length,
                        trackings.filter(t => t.type === 'email').length
                    ],
                    backgroundColor: [
                        '#93C5FD',
                        '#86EFAC',
                        '#FDE047'
                    ],
                    borderWidth: 1
                }]
            };
            
            typeChart = new Chart(typeCtx, {
                type: 'pie',
                data: typeData,
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    plugins: {
                        legend: {
                            position: 'right'
                        }
                    }
                }
            });
            
            // Monthly chart
            const monthlyCtx = document.getElementById('monthlyChart').getContext('2d');
            const monthlyData = {
                labels: ['Jan', 'Fév', 'Mar', 'Avr', 'Mai', 'Juin'],
                datasets: [
                    {
                        label: 'Appels',
                        data: [3, 5, 4, 6, 7, 4],
                        backgroundColor: '#3B82F6',
                        borderColor: '#3B82F6',
                        borderWidth: 1
                    },
                    {
                        label: 'Entretiens',
                        data: [2, 3, 2, 4, 5, 3],
                        backgroundColor: '#10B981',
                        borderColor: '#10B981',
                        borderWidth: 1
                    },
                    {
                        label: 'Emails',
                        data: [4, 3, 5, 4, 3, 2],
                        backgroundColor: '#F59E0B',
                        borderColor: '#F59E0B',
                        borderWidth: 1
                    }
                ]
            };
            
            monthlyChart = new Chart(monthlyCtx, {
                type: 'bar',
                data: monthlyData,
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    scales: {
                        x: {
                            stacked: false,
                        },
                        y: {
                            stacked: false,
                            beginAtZero: true
                        }
                    }
                }
            });
            
            // Beneficiary chart
            const beneficiaryCtx = document.getElementById('beneficiaryChart').getContext('2d');
            const beneficiaries = [...new Set(trackings.map(t => t.beneficiary))];
            const beneficiaryData = {
                labels: beneficiaries,
                datasets: [{
                    label: 'Contacts',
                    data: beneficiaries.map(b => trackings.filter(t => t.beneficiary === b).length),
                    backgroundColor: '#8B5CF6',
                    borderColor: '#8B5CF6',
                    borderWidth: 1
                }]
            };
            
            beneficiaryChart = new Chart(beneficiaryCtx, {
                type: 'bar',
                data: beneficiaryData,
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    scales: {
                        y: {
                            beginAtZero: true
                        }
                    }
                }
            });
        }

        // Get pillar name from number
        function getPillarName(pillarNumber) {
            const pillars = {
                '1': 'Primo-info',
                '2': 'Conseils',
                '3': 'Protection contre la discrimination',
                '4': 'Langue et formation',
                '5': 'Petite enfance', 
                '6': 'Employabilité',
                '7': 'Interprétariat',
                '8': 'Vivre-ensemble'
            };
            return pillars[pillarNumber] || `Pilier ${pillarNumber}`;
        }

        // Format date
        function formatDate(dateString) {
            const options = { day: 'numeric', month: 'short', year: 'numeric' };
            return new Date(dateString).toLocaleDateString('fr-CH', options);
        }

        // Setup event listeners
        function setupEventListeners() {
            // Tab switching
            dashboardTab.addEventListener('click', () => {
                dashboardTab.classList.add('text-blue-600', 'border-blue-600');
                dashboardTab.classList.remove('text-gray-500');
                addTab.classList.add('text-gray-500');
                addTab.classList.remove('text-blue-600', 'border-blue-600');
                statsTab.classList.add('text-gray-500');
                statsTab.classList.remove('text-blue-600', 'border-blue-600');
                
                dashboardContent.classList.remove('hidden');
                addContent.classList.add('hidden');
                statsContent.classList.add('hidden');
            });
            
            addTab.addEventListener('click', () => {
                addTab.classList.add('text-blue-600', 'border-blue-600');
                addTab.classList.remove('text-gray-500');
                dashboardTab.classList.add('text-gray-500');
                dashboardTab.classList.remove('text-blue-600', 'border-blue-600');
                statsTab.classList.add('text-gray-500');
                statsTab.classList.remove('text-blue-600', 'border-blue-600');
                
                addContent.classList.remove('hidden');
                dashboardContent.classList.add('hidden');
                statsContent.classList.add('hidden');
                
                // Set today's date as default
                const today = new Date().toISOString().split('T')[0];
                document.getElementById('date').value = today;
            });
            
            statsTab.addEventListener('click', () => {
                statsTab.classList.add('text-blue-600', 'border-blue-600');
                statsTab.classList.remove('text-gray-500');
                dashboardTab.classList.add('text-gray-500');
                dashboardTab.classList.remove('text-blue-600', 'border-blue-600');
                addTab.classList.add('text-gray-500');
                addTab.classList.remove('text-blue-600', 'border-blue-600');
                
                statsContent.classList.remove('hidden');
                dashboardContent.classList.add('hidden');
                addContent.classList.add('hidden');
            });
            
            // Form submission
            trackingForm.addEventListener('submit', (e) => {
                e.preventDefault();
                
                const type = document.querySelector('input[name="contact-type"]:checked').value;
                const date = document.getElementById('date').value;
                const beneficiary = document.getElementById('beneficiary').value;
                const pillar = document.getElementById('pillar').value;
                const details = document.getElementById('details').value;
                
                if (!beneficiary || !pillar) {
                    alert('Veuillez remplir tous les champs obligatoires');
                    return;
                }
                
                const newTracking = {
                    id: trackings.length + 1,
                    type,
                    date,
                    beneficiary,
                    pillar,
                    details
                };
                
                trackings.unshift(newTracking);
                
                // Reset form
                trackingForm.reset();
                
                // Update UI
                updateCounts();
                renderActivities();
                renderStatsTable();
                updateCharts();
                
                // Switch to dashboard
                dashboardTab.click();
            });
            
            // Cancel button
            cancelBtn.addEventListener('click', () => {
                trackingForm.reset();
                dashboardTab.click();
            });

            // Export button
            document.getElementById('export-btn').addEventListener('click', exportToCSV);
        }

        // Update charts with new data
        function updateCharts() {
            // Update pillar chart
            pillarChart.data.datasets[0].data = [
                trackings.filter(t => t.pillar === '1').length,
                trackings.filter(t => t.pillar === '2').length,
                trackings.filter(t => t.pillar === '3').length,
                trackings.filter(t => t.pillar === '4').length
            ];
            pillarChart.update();
            
            // Update type chart
            typeChart.data.datasets[0].data = [
                trackings.filter(t => t.type === 'call').length,
                trackings.filter(t => t.type === 'meeting').length,
                trackings.filter(t => t.type === 'email').length
            ];
            typeChart.update();
            
            // Update beneficiary chart
            const beneficiaries = [...new Set(trackings.map(t => t.beneficiary))];
            beneficiaryChart.data.labels = beneficiaries;
            beneficiaryChart.data.datasets[0].data = beneficiaries.map(b => 
                trackings.filter(t => t.beneficiary === b).length
            );
            beneficiaryChart.update();
        }

        // Initialize the app when DOM is loaded
        document.addEventListener('DOMContentLoaded', initApp);
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=masterseb/pic" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>