File size: 28,125 Bytes
a596e49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>User Management App</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>
        .fade-in {
            animation: fadeIn 0.3s ease-in-out;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .sidebar {
            transition: all 0.3s ease;
        }
        @media (max-width: 768px) {
            .sidebar {
                transform: translateX(-100%);
                position: fixed;
                z-index: 50;
                height: 100vh;
            }
            .sidebar.open {
                transform: translateX(0);
            }
        }
    </style>
</head>
<body class="bg-gray-100 font-sans">
    <!-- Mobile menu button -->
    <div class="md:hidden fixed top-4 left-4 z-50">
        <button id="menuBtn" class="p-2 rounded-md bg-indigo-600 text-white">
            <i class="fas fa-bars"></i>
        </button>
    </div>

    <!-- Sidebar -->
    <div id="sidebar" class="sidebar w-64 bg-white shadow-lg fixed h-full">
        <div class="p-4 flex items-center space-x-3 border-b border-gray-200">
            <div class="w-10 h-10 rounded-full bg-indigo-100 flex items-center justify-center">
                <i class="fas fa-user-cog text-indigo-600"></i>
            </div>
            <h1 class="text-xl font-bold text-gray-800">User Manager</h1>
        </div>
        <nav class="p-4">
            <ul class="space-y-2">
                <li>
                    <button id="dashboardBtn" class="w-full flex items-center space-x-3 p-3 rounded-lg bg-indigo-50 text-indigo-700">
                        <i class="fas fa-tachometer-alt"></i>
                        <span>Dashboard</span>
                    </button>
                </li>
                <li>
                    <button id="registerBtn" class="w-full flex items-center space-x-3 p-3 rounded-lg hover:bg-gray-100 text-gray-700">
                        <i class="fas fa-user-plus"></i>
                        <span>Registrar Usuario</span>
                    </button>
                </li>
                <li>
                    <button id="databaseBtn" class="w-full flex items-center space-x-3 p-3 rounded-lg hover:bg-gray-100 text-gray-700">
                        <i class="fas fa-database"></i>
                        <span>Base de Datos</span>
                    </button>
                </li>
            </ul>
        </nav>
        <div class="absolute bottom-0 w-full p-4 border-t border-gray-200">
            <button class="w-full flex items-center space-x-3 p-3 rounded-lg hover:bg-gray-100 text-gray-700">
                <i class="fas fa-sign-out-alt"></i>
                <span>Cerrar Sesión</span>
            </button>
        </div>
    </div>

    <!-- Main Content -->
    <div class="md:ml-64 min-h-screen">
        <!-- Header -->
        <header class="bg-white shadow-sm p-4">
            <div class="flex justify-between items-center">
                <h2 class="text-xl font-semibold text-gray-800" id="pageTitle">Dashboard</h2>
                <div class="flex items-center space-x-4">
                    <div class="relative">
                        <i class="fas fa-bell text-gray-500 hover:text-indigo-600 cursor-pointer"></i>
                        <span class="absolute -top-1 -right-1 w-2 h-2 bg-red-500 rounded-full"></span>
                    </div>
                    <div class="flex items-center space-x-2">
                        <div class="w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center">
                            <i class="fas fa-user text-indigo-600 text-sm"></i>
                        </div>
                        <span class="text-sm font-medium">Admin</span>
                    </div>
                </div>
            </div>
        </header>

        <!-- Content Area -->
        <main class="p-6">
            <!-- Dashboard Content -->
            <div id="dashboardContent" class="fade-in">
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
                    <div class="bg-white rounded-xl shadow-md p-6">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-gray-500">Usuarios registrados</p>
                                <h3 class="text-3xl font-bold" id="totalUsers">0</h3>
                            </div>
                            <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center">
                                <i class="fas fa-users text-indigo-600"></i>
                            </div>
                        </div>
                    </div>
                    <div class="bg-white rounded-xl shadow-md p-6">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-gray-500">Registros hoy</p>
                                <h3 class="text-3xl font-bold" id="todayUsers">0</h3>
                            </div>
                            <div class="w-12 h-12 rounded-full bg-green-100 flex items-center justify-center">
                                <i class="fas fa-calendar-day text-green-600"></i>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md p-6">
                    <h3 class="text-xl font-semibold mb-4">Acciones rápidas</h3>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <button id="quickRegisterBtn" class="flex items-center space-x-3 p-4 border border-gray-200 rounded-lg hover:border-indigo-300 hover:bg-indigo-50 transition-all">
                            <div class="w-10 h-10 rounded-full bg-indigo-100 flex items-center justify-center">
                                <i class="fas fa-user-plus text-indigo-600"></i>
                            </div>
                            <div>
                                <h4 class="font-medium">Registrar nuevo usuario</h4>
                                <p class="text-sm text-gray-500">Agrega un usuario a la base de datos</p>
                            </div>
                        </button>
                        <button id="quickDatabaseBtn" class="flex items-center space-x-3 p-4 border border-gray-200 rounded-lg hover:border-indigo-300 hover:bg-indigo-50 transition-all">
                            <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center">
                                <i class="fas fa-database text-purple-600"></i>
                            </div>
                            <div>
                                <h4 class="font-medium">Ver base de datos</h4>
                                <p class="text-sm text-gray-500">Consulta todos los usuarios registrados</p>
                            </div>
                        </button>
                    </div>
                </div>
            </div>

            <!-- Register Form Content -->
            <div id="registerContent" class="hidden fade-in">
                <div class="bg-white rounded-xl shadow-md p-6 max-w-2xl mx-auto">
                    <div class="flex items-center justify-between mb-6">
                        <h3 class="text-xl font-semibold">Registro de Usuario</h3>
                        <div class="w-10 h-10 rounded-full bg-indigo-100 flex items-center justify-center">
                            <i class="fas fa-user-plus text-indigo-600"></i>
                        </div>
                    </div>
                    
                    <form id="userForm" class="space-y-4">
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div>
                                <label for="firstName" class="block text-sm font-medium text-gray-700 mb-1">Nombre</label>
                                <input type="text" id="firstName" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-200 focus:border-indigo-500 outline-none transition">
                            </div>
                            <div>
                                <label for="lastName" class="block text-sm font-medium text-gray-700 mb-1">Apellido</label>
                                <input type="text" id="lastName" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-200 focus:border-indigo-500 outline-none transition">
                            </div>
                        </div>
                        
                        <div>
                            <label for="age" class="block text-sm font-medium text-gray-700 mb-1">Edad</label>
                            <input type="number" id="age" min="1" max="120" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-200 focus:border-indigo-500 outline-none transition">
                        </div>
                        
                        <div>
                            <label for="email" class="block text-sm font-medium text-gray-700 mb-1">Correo Electrónico</label>
                            <input type="email" id="email" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-200 focus:border-indigo-500 outline-none transition">
                        </div>
                        
                        <div class="pt-4">
                            <button type="submit" class="w-full bg-indigo-600 text-white py-2 px-4 rounded-lg hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition">
                                Registrar Usuario
                            </button>
                        </div>
                    </form>
                </div>
            </div>

            <!-- Database Content -->
            <div id="databaseContent" class="hidden fade-in">
                <div class="bg-white rounded-xl shadow-md p-6">
                    <div class="flex items-center justify-between mb-6">
                        <h3 class="text-xl font-semibold">Base de Datos de Usuarios</h3>
                        <div class="flex items-center space-x-3">
                            <div class="relative">
                                <input type="text" id="searchInput" placeholder="Buscar..." class="pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-200 focus:border-indigo-500 outline-none transition">
                                <i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
                            </div>
                            <button class="p-2 rounded-lg bg-gray-100 hover:bg-gray-200">
                                <i class="fas fa-filter text-gray-600"></i>
                            </button>
                        </div>
                    </div>
                    
                    <div class="overflow-x-auto">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nombre</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Apellido</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Edad</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Fecha Registro</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Acciones</th>
                                </tr>
                            </thead>
                            <tbody id="usersTableBody" class="bg-white divide-y divide-gray-200">
                                <!-- Users will be inserted here dynamically -->
                                <tr>
                                    <td colspan="6" class="px-6 py-4 text-center text-gray-500">No hay usuarios registrados</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    
                    <div class="flex items-center justify-between mt-4">
                        <div class="text-sm text-gray-500">
                            Mostrando <span id="showingFrom">0</span> a <span id="showingTo">0</span> de <span id="totalRecords">0</span> registros
                        </div>
                        <div class="flex space-x-2">
                            <button id="prevPage" disabled class="px-3 py-1 border rounded-lg text-gray-500 bg-gray-100 cursor-not-allowed">Anterior</button>
                            <button id="nextPage" disabled class="px-3 py-1 border rounded-lg text-gray-500 bg-gray-100 cursor-not-allowed">Siguiente</button>
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </div>

    <!-- Toast Notification -->
    <div id="toast" class="fixed bottom-4 right-4 hidden">
        <div class="bg-green-500 text-white px-4 py-2 rounded-lg shadow-lg flex items-center space-x-2">
            <i class="fas fa-check-circle"></i>
            <span id="toastMessage">Usuario registrado exitosamente!</span>
        </div>
    </div>

    <script>
        // Local storage for users database
        let usersDB = JSON.parse(localStorage.getItem('usersDB')) || [];
        
        // DOM Elements
        const menuBtn = document.getElementById('menuBtn');
        const sidebar = document.getElementById('sidebar');
        const pageTitle = document.getElementById('pageTitle');
        
        // Content areas
        const dashboardContent = document.getElementById('dashboardContent');
        const registerContent = document.getElementById('registerContent');
        const databaseContent = document.getElementById('databaseContent');
        
        // Navigation buttons
        const dashboardBtn = document.getElementById('dashboardBtn');
        const registerBtn = document.getElementById('registerBtn');
        const databaseBtn = document.getElementById('databaseBtn');
        const quickRegisterBtn = document.getElementById('quickRegisterBtn');
        const quickDatabaseBtn = document.getElementById('quickDatabaseBtn');
        
        // Form elements
        const userForm = document.getElementById('userForm');
        
        // Database elements
        const usersTableBody = document.getElementById('usersTableBody');
        const searchInput = document.getElementById('searchInput');
        const prevPage = document.getElementById('prevPage');
        const nextPage = document.getElementById('nextPage');
        const showingFrom = document.getElementById('showingFrom');
        const showingTo = document.getElementById('showingTo');
        const totalRecords = document.getElementById('totalRecords');
        
        // Dashboard counters
        const totalUsers = document.getElementById('totalUsers');
        const todayUsers = document.getElementById('todayUsers');
        
        // Toast
        const toast = document.getElementById('toast');
        const toastMessage = document.getElementById('toastMessage');
        
        // Pagination
        let currentPage = 1;
        const usersPerPage = 5;
        
        // Initialize app
        document.addEventListener('DOMContentLoaded', () => {
            updateDashboardCounters();
            showDashboard();
            
            // Mobile menu toggle
            menuBtn.addEventListener('click', () => {
                sidebar.classList.toggle('open');
            });
            
            // Navigation
            dashboardBtn.addEventListener('click', showDashboard);
            registerBtn.addEventListener('click', showRegister);
            databaseBtn.addEventListener('click', showDatabase);
            quickRegisterBtn.addEventListener('click', showRegister);
            quickDatabaseBtn.addEventListener('click', showDatabase);
            
            // Form submission
            userForm.addEventListener('submit', registerUser);
            
            // Database search
            searchInput.addEventListener('input', filterUsers);
            
            // Pagination
            prevPage.addEventListener('click', () => {
                if (currentPage > 1) {
                    currentPage--;
                    renderUsersTable();
                }
            });
            
            nextPage.addEventListener('click', () => {
                const totalPages = Math.ceil(usersDB.length / usersPerPage);
                if (currentPage < totalPages) {
                    currentPage++;
                    renderUsersTable();
                }
            });
        });
        
        function showDashboard() {
            dashboardContent.classList.remove('hidden');
            registerContent.classList.add('hidden');
            databaseContent.classList.add('hidden');
            
            // Update active button in sidebar
            dashboardBtn.classList.add('bg-indigo-50', 'text-indigo-700');
            dashboardBtn.classList.remove('hover:bg-gray-100', 'text-gray-700');
            
            registerBtn.classList.remove('bg-indigo-50', 'text-indigo-700');
            registerBtn.classList.add('hover:bg-gray-100', 'text-gray-700');
            
            databaseBtn.classList.remove('bg-indigo-50', 'text-indigo-700');
            databaseBtn.classList.add('hover:bg-gray-100', 'text-gray-700');
            
            pageTitle.textContent = 'Dashboard';
            
            // Close mobile menu if open
            sidebar.classList.remove('open');
            
            // Update counters
            updateDashboardCounters();
        }
        
        function showRegister() {
            dashboardContent.classList.add('hidden');
            registerContent.classList.remove('hidden');
            databaseContent.classList.add('hidden');
            
            // Update active button in sidebar
            dashboardBtn.classList.remove('bg-indigo-50', 'text-indigo-700');
            dashboardBtn.classList.add('hover:bg-gray-100', 'text-gray-700');
            
            registerBtn.classList.add('bg-indigo-50', 'text-indigo-700');
            registerBtn.classList.remove('hover:bg-gray-100', 'text-gray-700');
            
            databaseBtn.classList.remove('bg-indigo-50', 'text-indigo-700');
            databaseBtn.classList.add('hover:bg-gray-100', 'text-gray-700');
            
            pageTitle.textContent = 'Registrar Usuario';
            
            // Close mobile menu if open
            sidebar.classList.remove('open');
            
            // Reset form
            userForm.reset();
        }
        
        function showDatabase() {
            dashboardContent.classList.add('hidden');
            registerContent.classList.add('hidden');
            databaseContent.classList.remove('hidden');
            
            // Update active button in sidebar
            dashboardBtn.classList.remove('bg-indigo-50', 'text-indigo-700');
            dashboardBtn.classList.add('hover:bg-gray-100', 'text-gray-700');
            
            registerBtn.classList.remove('bg-indigo-50', 'text-indigo-700');
            registerBtn.classList.add('hover:bg-gray-100', 'text-gray-700');
            
            databaseBtn.classList.add('bg-indigo-50', 'text-indigo-700');
            databaseBtn.classList.remove('hover:bg-gray-100', 'text-gray-700');
            
            pageTitle.textContent = 'Base de Datos';
            
            // Close mobile menu if open
            sidebar.classList.remove('open');
            
            // Render users table
            currentPage = 1;
            renderUsersTable();
        }
        
        function registerUser(e) {
            e.preventDefault();
            
            const firstName = document.getElementById('firstName').value;
            const lastName = document.getElementById('lastName').value;
            const age = document.getElementById('age').value;
            const email = document.getElementById('email').value;
            
            const newUser = {
                id: Date.now(),
                firstName,
                lastName,
                age,
                email,
                registrationDate: new Date().toLocaleDateString('es-ES')
            };
            
            usersDB.push(newUser);
            localStorage.setItem('usersDB', JSON.stringify(usersDB));
            
            // Show success toast
            showToast('Usuario registrado exitosamente!');
            
            // Reset form
            userForm.reset();
            
            // Update dashboard counters
            updateDashboardCounters();
            
            // If on database view, refresh the table
            if (!databaseContent.classList.contains('hidden')) {
                currentPage = 1;
                renderUsersTable();
            }
        }
        
        function renderUsersTable(filteredUsers = null) {
            const usersToDisplay = filteredUsers || usersDB;
            const startIndex = (currentPage - 1) * usersPerPage;
            const endIndex = Math.min(startIndex + usersPerPage, usersToDisplay.length);
            const paginatedUsers = usersToDisplay.slice(startIndex, endIndex);
            
            // Clear table
            usersTableBody.innerHTML = '';
            
            if (paginatedUsers.length === 0) {
                const row = document.createElement('tr');
                row.innerHTML = `
                    <td colspan="6" class="px-6 py-4 text-center text-gray-500">No se encontraron usuarios</td>
                `;
                usersTableBody.appendChild(row);
            } else {
                paginatedUsers.forEach(user => {
                    const row = document.createElement('tr');
                    row.className = 'hover:bg-gray-50';
                    row.innerHTML = `
                        <td class="px-6 py-4 whitespace-nowrap">${user.firstName}</td>
                        <td class="px-6 py-4 whitespace-nowrap">${user.lastName}</td>
                        <td class="px-6 py-4 whitespace-nowrap">${user.age}</td>
                        <td class="px-6 py-4 whitespace-nowrap">${user.email}</td>
                        <td class="px-6 py-4 whitespace-nowrap">${user.registrationDate}</td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <button onclick="deleteUser(${user.id})" class="text-red-500 hover:text-red-700">
                                <i class="fas fa-trash-alt"></i>
                            </button>
                        </td>
                    `;
                    usersTableBody.appendChild(row);
                });
            }
            
            // Update pagination info
            showingFrom.textContent = usersToDisplay.length > 0 ? startIndex + 1 : 0;
            showingTo.textContent = endIndex;
            totalRecords.textContent = usersToDisplay.length;
            
            // Update pagination buttons
            prevPage.disabled = currentPage === 1;
            nextPage.disabled = endIndex >= usersToDisplay.length;
            
            if (prevPage.disabled) {
                prevPage.classList.add('bg-gray-100', 'cursor-not-allowed');
                prevPage.classList.remove('bg-white', 'hover:bg-gray-50', 'cursor-pointer');
            } else {
                prevPage.classList.remove('bg-gray-100', 'cursor-not-allowed');
                prevPage.classList.add('bg-white', 'hover:bg-gray-50', 'cursor-pointer');
            }
            
            if (nextPage.disabled) {
                nextPage.classList.add('bg-gray-100', 'cursor-not-allowed');
                nextPage.classList.remove('bg-white', 'hover:bg-gray-50', 'cursor-pointer');
            } else {
                nextPage.classList.remove('bg-gray-100', 'cursor-not-allowed');
                nextPage.classList.add('bg-white', 'hover:bg-gray-50', 'cursor-pointer');
            }
        }
        
        function filterUsers() {
            const searchTerm = searchInput.value.toLowerCase();
            
            if (searchTerm === '') {
                renderUsersTable();
                return;
            }
            
            const filteredUsers = usersDB.filter(user => 
                user.firstName.toLowerCase().includes(searchTerm) ||
                user.lastName.toLowerCase().includes(searchTerm) ||
                user.email.toLowerCase().includes(searchTerm) ||
                user.age.toString().includes(searchTerm)
            );
            
            currentPage = 1;
            renderUsersTable(filteredUsers);
        }
        
        function deleteUser(userId) {
            if (confirm('¿Estás seguro de que deseas eliminar este usuario?')) {
                usersDB = usersDB.filter(user => user.id !== userId);
                localStorage.setItem('usersDB', JSON.stringify(usersDB));
                
                // Update dashboard counters
                updateDashboardCounters();
                
                // Re-render table
                renderUsersTable();
                
                // Show toast
                showToast('Usuario eliminado correctamente');
            }
        }
        
        function updateDashboardCounters() {
            totalUsers.textContent = usersDB.length;
            
            const today = new Date().toLocaleDateString('es-ES');
            const todayRegistrations = usersDB.filter(user => user.registrationDate === today).length;
            todayUsers.textContent = todayRegistrations;
        }
        
        function showToast(message) {
            toastMessage.textContent = message;
            toast.classList.remove('hidden');
            
            setTimeout(() => {
                toast.classList.add('hidden');
            }, 3000);
        }
        
        // Close sidebar when clicking outside on mobile
        document.addEventListener('click', (e) => {
            if (window.innerWidth <= 768 && !sidebar.contains(e.target) && e.target !== menuBtn) {
                sidebar.classList.remove('open');
            }
        });
    </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=styvencm/base-de-datos" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>