File size: 26,945 Bytes
aedea59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfba19b
 
 
aedea59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfba19b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aedea59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfba19b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aedea59
 
 
4ab736b
 
 
 
 
 
 
aedea59
 
 
 
 
 
 
 
 
 
dfba19b
aedea59
 
dfba19b
aedea59
 
dfba19b
aedea59
 
 
 
 
 
 
 
 
 
 
 
 
dfba19b
 
 
 
 
 
 
 
 
 
aedea59
 
 
dfba19b
055f3c6
 
 
 
 
 
 
dfba19b
055f3c6
 
 
 
 
 
 
 
 
 
 
 
 
 
dfba19b
 
aedea59
 
 
 
055f3c6
aedea59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfba19b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aedea59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfba19b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aedea59
 
 
 
 
dfba19b
aedea59
 
 
 
dfba19b
 
aedea59
 
 
 
 
 
dfba19b
aedea59
 
 
 
dfba19b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aedea59
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SweetOasis Admin</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
    <script src="https://www.gstatic.com/firebasejs/9.6.0/firebase-app-compat.js"></script>
    <script src="https://www.gstatic.com/firebasejs/9.6.0/firebase-auth-compat.js"></script>
    <script src="https://www.gstatic.com/firebasejs/9.6.0/firebase-firestore-compat.js"></script>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
        body {
            font-family: 'Poppins', sans-serif;
        }
    </style>
</head>
<body class="bg-gray-100">
    <!-- Admin Navigation -->
    <nav class="bg-white shadow-sm">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between h-16 items-center">
                <span class="text-xl font-bold text-pink-600">SweetOasis Admin</span>
                <button id="logoutBtn" class="text-gray-600 hover:text-pink-600 flex items-center">
                    <i data-feather="log-out" class="mr-1"></i> Logout
                </button>
            </div>
        </div>
    </nav>

    <!-- Admin Content -->
    <main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
        <div class="grid grid-cols-1 lg:grid-cols-4 gap-8">
            <!-- Sidebar -->
            <div class="lg:col-span-1">
                <div class="bg-white rounded-lg shadow p-6 sticky top-8">
                    <h2 class="text-xl font-bold mb-4">Admin Panel</h2>
                    <nav class="space-y-2">
                        <a href="#" id="productsTab" class="block px-4 py-2 rounded-lg bg-pink-100 text-pink-600 font-medium">
                            <i data-feather="shopping-bag" class="inline mr-2"></i> Products
                        </a>
                        <a href="#" id="ordersTab" class="block px-4 py-2 rounded-lg text-gray-600 hover:bg-gray-100">
                            <i data-feather="package" class="inline mr-2"></i> Orders
                        </a>
                        <a href="#" id="usersTab" class="block px-4 py-2 rounded-lg text-gray-600 hover:bg-gray-100">
                            <i data-feather="users" class="inline mr-2"></i> Users
                        </a>
                    </nav>
                </div>
            </div>

            <!-- Main Content -->
            <div class="lg:col-span-3">
                <!-- Products Management -->
                <div id="productsSection">
                    <div class="flex justify-between items-center mb-6">
                        <h2 class="text-2xl font-bold">Products Management</h2>
                        <button id="addProductBtn" class="bg-pink-500 hover:bg-pink-600 text-white px-4 py-2 rounded-lg font-medium flex items-center">
                            <i data-feather="plus" class="mr-1"></i> Add Product
                        </button>
                    </div>

                    <div class="bg-white rounded-lg shadow overflow-hidden">
                        <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">Image</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Price</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
                                </tr>
                            </thead>
                            <tbody id="productsTable" class="bg-white divide-y divide-gray-200">
                                <!-- Products will be loaded here -->
                            </tbody>
                        </table>
                    </div>
                </div>

                <!-- Orders Management -->
                <div id="ordersSection" class="hidden">
                    <h2 class="text-2xl font-bold mb-6">Orders Management</h2>
                    <div class="bg-white rounded-lg shadow">
                        <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">Order ID</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Customer</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Total</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
                                </tr>
                            </thead>
                            <tbody id="ordersTable" class="bg-white divide-y divide-gray-200">
                                <!-- Orders will be loaded here -->
                            </tbody>
                        </table>
                    </div>
                </div>

                <!-- Users Management -->
                <div id="usersSection" class="hidden">
                    <h2 class="text-2xl font-bold mb-6">Users Management</h2>
                    <div class="bg-white rounded-lg shadow">
                        <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">Email</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Role</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
                                </tr>
                            </thead>
                            <tbody id="usersTable" class="bg-white divide-y divide-gray-200">
                                <!-- Users will be loaded here -->
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <!-- Add/Edit Product Modal -->
    <div id="productModal" class="fixed inset-0 bg-black bg-opacity-50 z-50 hidden flex items-center justify-center p-4">
        <div class="bg-white rounded-lg shadow-xl w-full max-w-md">
            <div class="p-6">
                <h3 class="text-xl font-bold mb-4" id="modalTitle">Add New Product</h3>
                <form id="productForm">
                    <input type="hidden" id="productId">
                    <div class="mb-4">
                        <label class="block text-gray-700 mb-2">Product Name</label>
                        <input type="text" id="productName" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300" required>
                    </div>
                    <div class="mb-4">
                        <label class="block text-gray-700 mb-2">Description</label>
                        <textarea id="productDescription" rows="3" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300"></textarea>
                    </div>
                    <div class="mb-4">
                        <label class="block text-gray-700 mb-2">Price ($)</label>
                        <input type="number" id="productPrice" step="0.01" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300" required>
                    </div>
                    <div class="mb-4">
                        <label class="block text-gray-700 mb-2">Image URL</label>
                        <input type="url" id="productImage" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300" required>
                    </div>
                    <div class="flex items-center mb-4">
                        <input type="checkbox" id="productIsNew" class="mr-2">
                        <label class="text-gray-700">Mark as New</label>
                    </div>
                    <div class="flex justify-end space-x-3">
                        <button type="button" id="cancelProductBtn" class="px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-100">Cancel</button>
                        <button type="submit" id="saveProductBtn" class="px-4 py-2 bg-pink-500 text-white rounded-lg hover:bg-pink-600">Save</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- Add/Edit User Modal -->
    <div id="userModal" class="fixed inset-0 bg-black bg-opacity-50 z-50 hidden flex items-center justify-center p-4">
        <div class="bg-white rounded-lg shadow-xl w-full max-w-md">
            <div class="p-6">
                <h3 class="text-xl font-bold mb-4" id="userModalTitle">Add New User</h3>
                <form id="userForm">
                    <input type="hidden" id="userId">
                    <div class="mb-4">
                        <label class="block text-gray-700 mb-2">Email</label>
                        <input type="email" id="userEmail" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300" required>
                    </div>
                    <div class="mb-4">
                        <label class="block text-gray-700 mb-2">Name</label>
                        <input type="text" id="userName" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300" required>
                    </div>
                    <div class="mb-4">
                        <label class="block text-gray-700 mb-2">Password</label>
                        <input type="password" id="userPassword" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300">
                    </div>
                    <div class="mb-4">
                        <label class="block text-gray-700 mb-2">Role</label>
                        <select id="userRole" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-pink-300">
                            <option value="user">User</option>
                            <option value="admin">Admin</option>
                        </select>
                    </div>
                    <div class="flex justify-end space-x-3">
                        <button type="button" id="cancelUserBtn" class="px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-100">Cancel</button>
                        <button type="submit" id="saveUserBtn" class="px-4 py-2 bg-pink-500 text-white rounded-lg hover:bg-pink-600">Save</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script>
        // Firebase configuration - REPLACE WITH YOUR ACTUAL CONFIG
        const firebaseConfig = {
        apiKey: "AIzaSyCZqw9_svj6Qc9op6U6MqCLuuhbR-BTZm0",
  authDomain: "kkkk-aa173.firebaseapp.com",
  projectId: "kkkk-aa173",
  storageBucket: "kkkk-aa173.firebasestorage.app",
  messagingSenderId: "751348817218",
  appId: "1:751348817218:web:108d2b506f524332af7cdb",
  measurementId: "G-GYV2NVT3H6"
        };

        // Initialize Firebase
        firebase.initializeApp(firebaseConfig);
        const auth = firebase.auth();
        const db = firebase.firestore();

        // DOM Elements
        const productsSection = document.getElementById('productsSection');
        const ordersSection = document.getElementById('ordersSection');
        const usersSection = document.getElementById('usersSection');
        const productsTab = document.getElementById('productsTab');
        const ordersTab = document.getElementById('ordersTab');
        const usersTab = document.getElementById('usersTab');
        const productsTable = document.getElementById('productsTable');
        const ordersTable = document.getElementById('ordersTable');
        const usersTable = document.getElementById('usersTable');
        const addProductBtn = document.getElementById('addProductBtn');
        const logoutBtn = document.getElementById('logoutBtn');
        const productModal = document.getElementById('productModal');
        const productForm = document.getElementById('productForm');
        const modalTitle = document.getElementById('modalTitle');
        const productId = document.getElementById('productId');
        const productName = document.getElementById('productName');
        const productDescription = document.getElementById('productDescription');
        const productPrice = document.getElementById('productPrice');
        const productImage = document.getElementById('productImage');
        const productIsNew = document.getElementById('productIsNew');
        const saveProductBtn = document.getElementById('saveProductBtn');
        const cancelProductBtn = document.getElementById('cancelProductBtn');
        const userModal = document.getElementById('userModal');
        const userForm = document.getElementById('userForm');
        const userModalTitle = document.getElementById('userModalTitle');
        const userId = document.getElementById('userId');
        const userEmail = document.getElementById('userEmail');
        const userName = document.getElementById('userName');
        const userPassword = document.getElementById('userPassword');
        const userRole = document.getElementById('userRole');
        const saveUserBtn = document.getElementById('saveUserBtn');
        const cancelUserBtn = document.getElementById('cancelUserBtn');
        // Check auth state and load data
        auth.onAuthStateChanged(user => {
            if (user) {
                db.collection('users').doc(user.uid).get().then(doc => {
                    if (doc.exists) {
                        const userData = doc.data();
                        if (userData.role === 'admin') {
                            loadProducts();
                        } else {
                            window.location.href = 'index.html';
                        }
                    } else {
                        // If user doc doesn't exist, check if it's the first user
                        db.collection('users').get().then(snapshot => {
                            if (snapshot.empty) {
                                // First user - automatically make admin
                                db.collection('users').doc(user.uid).set({
                                    displayName: user.displayName,
                                    email: user.email,
                                    role: 'admin',
                                    createdAt: firebase.firestore.FieldValue.serverTimestamp()
                                }).then(() => loadProducts());
                            } else {
                                window.location.href = 'index.html';
                            }
                        });
                    }
                });
            } else {
                window.location.href = 'index.html';
            }
        });
// Load products
        function loadProducts() {
            db.collection('products').get().then(querySnapshot => {
                productsTable.innerHTML = '';
                querySnapshot.forEach(doc => {
                    const product = doc.data();
                    productsTable.innerHTML += `
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <img src="${product.image}" alt="${product.name}" class="h-10 w-10 rounded-full object-cover">
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="text-sm font-medium text-gray-900">${product.name}</div>
                                ${product.description ? `<div class="text-sm text-gray-500">${product.description}</div>` : ''}
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="text-sm text-pink-600 font-bold">$${product.price.toFixed(2)}</div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 space-x-2">
                                <button onclick="editProduct('${doc.id}')" class="text-blue-500 hover:text-blue-700">
                                    <i data-feather="edit" class="w-4 h-4"></i>
                                </button>
                                <button onclick="deleteProduct('${doc.id}')" class="text-red-500 hover:text-red-700">
                                    <i data-feather="trash-2" class="w-4 h-4"></i>
                                </button>
                            </td>
                        </tr>
                    `;
                });
                feather.replace();
            });
        }

        // Load users
        function loadUsers() {
            db.collection('users').get().then(querySnapshot => {
                usersTable.innerHTML = '';
                querySnapshot.forEach(doc => {
                    const user = doc.data();
                    usersTable.innerHTML += `
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="text-sm font-medium text-gray-900">${user.email}</div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="text-sm text-gray-900">${user.displayName || '-'}</div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <span class="px-2 py-1 text-xs rounded-full ${user.role === 'admin' ? 'bg-pink-100 text-pink-800' : 'bg-gray-100 text-gray-800'}">
                                    ${user.role || 'user'}
                                </span>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 space-x-2">
                                <button onclick="editUser('${doc.id}')" class="text-blue-500 hover:text-blue-700">
                                    <i data-feather="edit" class="w-4 h-4"></i>
                                </button>
                                <button onclick="deleteUser('${doc.id}')" class="text-red-500 hover:text-red-700">
                                    <i data-feather="trash-2" class="w-4 h-4"></i>
                                </button>
                            </td>
                        </tr>
                    `;
                });
                feather.replace();
            });
        }

        // Open add product modal
        addProductBtn.addEventListener('click', () => {
            modalTitle.textContent = 'Add New Product';
            productForm.reset();
            productId.value = '';
            productModal.classList.remove('hidden');
        });

        // Cancel product edit/add
        cancelProductBtn.addEventListener('click', () => {
            productModal.classList.add('hidden');
        });

        // Save product
        productForm.addEventListener('submit', (e) => {
            e.preventDefault();
            
            const productData = {
                name: productName.value,
                description: productDescription.value,
                price: parseFloat(productPrice.value),
                image: productImage.value,
                isNew: productIsNew.checked,
                createdAt: firebase.firestore.FieldValue.serverTimestamp()
            };

            if (productId.value) {
                // Update existing product
                db.collection('products').doc(productId.value).update(productData)
                    .then(() => {
                        productModal.classList.add('hidden');
                        loadProducts();
                    });
            } else {
                // Add new product
                db.collection('products').add(productData)
                    .then(() => {
                        productModal.classList.add('hidden');
                        loadProducts();
                    });
            }
        });

        // Edit product
        window.editProduct = (id) => {
            db.collection('products').doc(id).get().then(doc => {
                if (doc.exists) {
                    const product = doc.data();
                    modalTitle.textContent = 'Edit Product';
                    productId.value = doc.id;
                    productName.value = product.name;
                    productDescription.value = product.description || '';
                    productPrice.value = product.price;
                    productImage.value = product.image;
                    productIsNew.checked = product.isNew || false;
                    productModal.classList.remove('hidden');
                }
            });
        };

        // Delete product
        window.deleteProduct = (id) => {
            if (confirm('Are you sure you want to delete this product?')) {
                db.collection('products').doc(id).delete()
                    .then(() => {
                        loadProducts();
                    });
            }
        };

        // Edit user
        window.editUser = (id) => {
            db.collection('users').doc(id).get().then(doc => {
                if (doc.exists) {
                    const user = doc.data();
                    userModalTitle.textContent = 'Edit User';
                    userId.value = doc.id;
                    userEmail.value = user.email;
                    userName.value = user.displayName || '';
                    userRole.value = user.role || 'user';
                    userModal.classList.remove('hidden');
                }
            });
        };

        // Delete user
        window.deleteUser = (id) => {
            if (confirm('Are you sure you want to delete this user?')) {
                db.collection('users').doc(id).delete()
                    .then(() => {
                        loadUsers();
                    });
            }
        };

        // Save user
        userForm.addEventListener('submit', async (e) => {
            e.preventDefault();
            
            const userData = {
                email: userEmail.value,
                displayName: userName.value,
                role: userRole.value
            };

            try {
                if (userId.value) {
                    // Update existing user
                    await db.collection('users').doc(userId.value).update(userData);
                } else {
                    // Create new user
                    const { user } = await auth.createUserWithEmailAndPassword(userEmail.value, userPassword.value);
                    await user.updateProfile({
                        displayName: userName.value
                    });
                    await db.collection('users').doc(user.uid).set({
                        ...userData,
                        uid: user.uid
                    });
                }
                userModal.classList.add('hidden');
                loadUsers();
            } catch (error) {
                alert(error.message);
            }
        });

        // Cancel user edit/add
        cancelUserBtn.addEventListener('click', () => {
            userModal.classList.add('hidden');
        });

        // Switch between tabs
        productsTab.addEventListener('click', (e) => {
            e.preventDefault();
            productsSection.classList.remove('hidden');
            ordersSection.classList.add('hidden');
            usersSection.classList.add('hidden');
            productsTab.classList.add('bg-pink-100', 'text-pink-600');
            productsTab.classList.remove('text-gray-600', 'hover:bg-gray-100');
            ordersTab.classList.remove('bg-pink-100', 'text-pink-600');
            ordersTab.classList.add('text-gray-600', 'hover:bg-gray-100');
            usersTab.classList.remove('bg-pink-100', 'text-pink-600');
            usersTab.classList.add('text-gray-600', 'hover:bg-gray-100');
        });

        ordersTab.addEventListener('click', (e) => {
            e.preventDefault();
            ordersSection.classList.remove('hidden');
            productsSection.classList.add('hidden');
            usersSection.classList.add('hidden');
            ordersTab.classList.add('bg-pink-100', 'text-pink-600');
            ordersTab.classList.remove('text-gray-600', 'hover:bg-gray-100');
            productsTab.classList.remove('bg-pink-100', 'text-pink-600');
            productsTab.classList.add('text-gray-600', 'hover:bg-gray-100');
            usersTab.classList.remove('bg-pink-100', 'text-pink-600');
            usersTab.classList.add('text-gray-600', 'hover:bg-gray-100');
        });

        usersTab.addEventListener('click', (e) => {
            e.preventDefault();
            usersSection.classList.remove('hidden');
            productsSection.classList.add('hidden');
            ordersSection.classList.add('hidden');
            usersTab.classList.add('bg-pink-100', 'text-pink-600');
            usersTab.classList.remove('text-gray-600', 'hover:bg-gray-100');
            productsTab.classList.remove('bg-pink-100', 'text-pink-600');
            productsTab.classList.add('text-gray-600', 'hover:bg-gray-100');
            ordersTab.classList.remove('bg-pink-100', 'text-pink-600');
            ordersTab.classList.add('text-gray-600', 'hover:bg-gray-100');
            loadUsers();
        });

        // Logout
        logoutBtn.addEventListener('click', () => {
            auth.signOut();
        });

        // Initialize
        document.addEventListener('DOMContentLoaded', () => {
            feather.replace();
        });
    </script>
</body>
</html>