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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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Panel | MindBloom</title>
    <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
    <script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
    <script src="https://unpkg.com/feather-icons"></script>
    <style>
        .sidebar {
            width: 280px;
            transition: all 0.3s ease;
        }
        .main-content {
            margin-left: 280px;
            transition: all 0.3s ease;
        }
        .collapsed .sidebar {
            width: 80px;
        }
        .collapsed .main-content {
            margin-left: 80px;
        }
        .nav-item:hover {
            background-color: rgba(139, 92, 246, 0.1);
        }
        .active-nav {
            background-color: rgba(139, 92, 246, 0.2);
            border-left: 4px solid #8b5cf6;
        }
        .table-row:hover {
            background-color: #f9fafb;
        }
    </style>
</head>
<body class="bg-gray-100 font-sans antialiased">
    <div class="flex" id="admin-layout">
        <!-- Sidebar -->
        <div class="sidebar bg-white shadow-lg fixed h-full overflow-y-auto">
            <div class="p-6 border-b border-gray-200">
                <div class="flex items-center justify-between">
                    <div class="flex items-center">
                        <i data-feather="heart" class="text-purple-600 h-6 w-6"></i>
                        <span class="ml-2 text-xl font-bold text-gray-900">Admin</span>
                    </div>
                    <button id="toggle-sidebar" class="text-gray-600 hover:text-purple-600">
                        <i data-feather="chevron-left"></i>
                    </button>
                </div>
            </div>
            
            <nav class="mt-6">
                <div class="px-4 space-y-1">
                    <a href="#dashboard" class="nav-item active-nav flex items-center px-4 py-3 text-gray-700 rounded-lg">
                        <i data-feather="grid" class="h-5 w-5"></i>
                        <span class="ml-3">Dashboard</span>
                    </a>
                    <a href="#products" class="nav-item flex items-center px-4 py-3 text-gray-700 rounded-lg">
                        <i data-feather="shopping-bag" class="h-5 w-5"></i>
                        <span class="ml-3">Products</span>
                    </a>
                    <a href="#content" class="nav-item flex items-center px-4 py-3 text-gray-700 rounded-lg">
                        <i data-feather="file-text" class="h-5 w-5"></i>
                        <span class="ml-3">Content</span>
                    </a>
                    <a href="#therapy" class="nav-item flex items-center px-4 py-3 text-gray-700 rounded-lg">
                        <i data-feather="activity" class="h-5 w-5"></i>
                        <span class="ml-3">Therapy</span>
                    </a>
                    <a href="#users" class="nav-item flex items-center px-4 py-3 text-gray-700 rounded-lg">
                        <i data-feather="users" class="h-5 w-5"></i>
                        <span class="ml-3">Users</span>
                    </a>
                    <a href="#settings" class="nav-item flex items-center px-4 py-3 text-gray-700 rounded-lg">
                        <i data-feather="settings" class="h-5 w-5"></i>
                        <span class="ml-3">Settings</span>
                    </a>
                </div>
            </nav>
            
            <div class="absolute bottom-0 w-full p-4 border-t border-gray-200">
                <button class="w-full flex items-center justify-center px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700">
                    <i data-feather="log-out" class="h-4 w-4 mr-2"></i>
                    <span>Logout</span>
                </button>
            </div>
        </div>

        <!-- Main Content -->
        <div class="main-content w-full min-h-screen">
            <!-- Header -->
            <header class="bg-white shadow-sm">
                <div class="flex items-center justify-between p-6">
                    <h1 class="text-2xl font-bold text-gray-900">Dashboard</h1>
                    <div class="flex items-center space-x-4">
                        <div class="relative">
                            <input type="text" placeholder="Search..." class="pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-600 focus:border-transparent">
                            <i data-feather="search" class="absolute left-3 top-2.5 h-5 w-5 text-gray-400"></i>
                        </div>
                        <div class="flex items-center space-x-3">
                            <button class="p-2 text-gray-600 hover:text-purple-600">
                                <i data-feather="bell"></i>
                            </button>
                            <div class="w-10 h-10 bg-purple-600 rounded-full flex items-center justify-center text-white font-semibold">
                                A
                            </div>
                        </div>
                    </div>
                </div>
            </header>

            <!-- Dashboard Content -->
            <main class="p-6">
                <!-- Stats Cards -->
                <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
                    <div class="bg-white rounded-lg shadow p-6" data-aos="fade-up">
                        <div class="flex items-center">
                            <div class="p-3 bg-purple-100 rounded-lg">
                                <i data-feather="users" class="h-6 w-6 text-purple-600"></i>
                            </div>
                            <div class="ml-4">
                                <p class="text-sm font-medium text-gray-600">Total Users</p>
                                <p class="text-2xl font-bold text-gray-900">1,248</p>
                            </div>
                        </div>
                    </div>
                    <div class="bg-white rounded-lg shadow p-6" data-aos="fade-up" data-aos-delay="100">
                        <div class="flex items-center">
                            <div class="p-3 bg-green-100 rounded-lg">
                                <i data-feather="shopping-bag" class="h-6 w-6 text-green-600"></i>
                            </div>
                            <div class="ml-4">
                                <p class="text-sm font-medium text-gray-600">Products</p>
                                <p class="text-2xl font-bold text-gray-900">89</p>
                            </div>
                        </div>
                    </div>
                    <div class="bg-white rounded-lg shadow p-6" data-aos="fade-up" data-aos-delay="200">
                        <div class="flex items-center">
                            <div class="p-3 bg-blue-100 rounded-lg">
                                <i data-feather="file-text" class="h-6 w-6 text-blue-600"></i>
                            </div>
                            <div class="ml-4">
                                <p class="text-sm font-medium text-gray-600">Articles</p>
                                <p class="text-2xl font-bold text-gray-900">156</p>
                            </div>
                        </div>
                    </div>
                    <div class="bg-white rounded-lg shadow p-6" data-aos="fade-up" data-aos-delay="300">
                        <div class="flex items-center">
                            <div class="p-3 bg-orange-100 rounded-lg">
                                <i data-feather="calendar" class="h-6 w-6 text-orange-600"></i>
                            </div>
                            <div class="ml-4">
                                <p class="text-sm font-medium text-gray-600">Sessions</p>
                                <p class="text-2xl font-bold text-gray-900">324</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Recent Products -->
                <div class="bg-white rounded-lg shadow mb-8" data-aos="fade-up">
                    <div class="p-6 border-b border-gray-200">
                        <h2 class="text-lg font-semibold text-gray-900">Recent Products</h2>
                    </div>
                    <div class="p-6">
                        <table class="w-full">
                            <thead>
                                <tr class="text-left text-sm text-gray-500">
                                    <th class="pb-4">Product</th>
                                    <th class="pb-4">Category</th>
                                    <th class="pb-4">Price</th>
                                    <th class="pb-4">Status</th>
                                    <th class="pb-4 text-right">Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr class="table-row border-b border-gray-200">
                                    <td class="py-4">
                                        <div class="flex items-center">
                                            <img src="http://static.photos/cosmetic/64x64/1" alt="Product" class="w-10 h-10 rounded-lg object-cover">
                                            <div class="ml-4">
                                                <p class="font-medium text-gray-900">Calming Face Serum</p>
                                                <p class="text-sm text-gray-600">SKU: MB-SER-001</p>
                                            </div>
                                        </div>
                                    </td>
                                    <td class="py-4">Skincare</td>
                                    <td class="py-4">$42.99</td>
                                    <td class="py-4">
                                        <span class="px-2 py-1 text-xs font-semibold bg-green-100 text-green-800 rounded-full">Active</span>
                                    </td>
                                    <td class="py-4 text-right">
                                        <div class="flex justify-end space-x-2">
                                            <button class="p-1 text-blue-600 hover:text-blue-800">
                                                <i data-feather="edit" class="h-4 w-4"></i>
                                            </button>
                                            <button class="p-1 text-red-600 hover:text-red-800">
                                                <i data-feather="trash" class="h-4 w-4"></i>
                                            </button>
                                        </div>
                                    </td>
                                </tr>
                                <tr class="table-row border-b border-gray-200">
                                    <td class="py-4">
                                        <div class="flex items-center">
                                            <img src="http://static.photos/cosmetic/64x64/2" alt="Product" class="w-10 h-10 rounded-lg object-cover">
                                            <div class="ml-4">
                                                <p class="font-medium text-gray-900">Mindful Lip Balm</p>
                                                <p class="text-sm text-gray-600">SKU: MB-LIP-002</p>
                                            </div>
                                        </div>
                                    </td>
                                    <td class="py-4">Beauty</td>
                                    <td class="py-4">$18.50</td>
                                    <td class="py-4">
                                        <span class="px-2 py-1 text-xs font-semibold bg-green-100 text-green-800 rounded-full">Active</span>
                                    </td>
                                    <td class="py-4 text-right">
                                        <div class="flex justify-end space-x-2">
                                            <button class="p-1 text-blue-600 hover:text-blue-800">
                                                <i data-feather="edit" class="h-4 w-4"></i>
                                            </button>
                                            <button class="p-1 text-red-600 hover:text-red-800">
                                                <i data-feather="trash" class="h-4 w-4"></i>
                                            </button>
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="p-6 border-t border-gray-200">
                        <button class="w-full bg-purple-600 text-white py-2 px-4 rounded-lg hover:bg-purple-700">
                            Add New Product
                        </button>
                    </div>
                </div>

                <!-- Quick Actions -->
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div class="bg-white rounded-lg shadow p-6" data-aos="fade-up">
                        <h3 class="text-lg font-semibold text-gray-900 mb-4">Create New Content</h3>
                        <div class="space-y-3">
                            <button class="w-full flex items-center justify-between p-4 border border-gray-200 rounded-lg hover:border-purple-600 hover:bg-purple-50">
                                <span>Write Article</span>
                                <i data-feather="arrow-right" class="h-5 w-5"></i>
                            </button>
                            <button class="w-full flex items-center justify-between p-4 border border-gray-200 rounded-lg hover:border-purple-600 hover:bg-purple-50">
                                <span>Add Therapy Session</span>
                                <i data-feather="arrow-right" class="h-5 w-5"></i>
                            </button>
                            <button class="w-full flex items-center justify-between p-4 border border-gray-200 rounded-lg hover:border-purple-600 hover:bg-purple-50">
                                <span>Create Beauty Guide</span>
                                <i data-feather="arrow-right" class="h-5 w-5"></i>
                            </button>
                        </div>
                    </div>

                    <div class="bg-white rounded-lg shadow p-6" data-aos="fade-up" data-aos-delay="100">
                        <h3 class="text-lg font-semibold text-gray-900 mb-4">System Status</h3>
                        <div class="space-y-4">
                            <div class="flex items-center justify-between">
                                <span class="text-gray-600">Database</span>
                                <span class="px-2 py-1 text-xs font-semibold bg-green-100 text-green-800 rounded-full">Online</span>
                            </div>
                            <div class="flex items-center justify-between">
                                <span class="text-gray-600">Storage</span>
                                <span class="text-sm text-gray-900">2.4GB / 10GB used</span>
                            </div>
                            <div class="flex items-center justify-between">
                                <span class="text-gray-600">Last Backup</span>
                                <span class="text-sm text-gray-900">2 hours ago</span>
                            </div>
                            <div class="pt-4">
                                <button class="w-full bg-gray-100 text-gray-700 py-2 px-4 rounded-lg hover:bg-gray-200">
                                    Run System Check
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </main>
        </div>
    </div>

    <script>
        let authToken = localStorage.getItem('authToken');
        let currentUser = JSON.parse(localStorage.getItem('currentUser'));
        
        // Check authentication
        if (!authToken || !currentUser) {
            window.location.href = 'login.html';
        }
        
        AOS.init({
            duration: 800,
            easing: 'ease-in-out',
            once: true
        });
        
        feather.replace();
        
        // Toggle sidebar
        document.getElementById('toggle-sidebar').addEventListener('click', function() {
            document.getElementById('admin-layout').classList.toggle('collapsed');
            const icon = this.querySelector('i');
            if (document.getElementById('admin-layout').classList.contains('collapsed')) {
                icon.setAttribute('data-feather', 'chevron-right');
            } else {
                icon.setAttribute('data-feather', 'chevron-left');
            }
            feather.replace();
        });

        // Navigation active state
        document.querySelectorAll('.nav-item').forEach(item => {
            item.addEventListener('click', function() {
                document.querySelectorAll('.nav-item').forEach(i => i.classList.remove('active-nav'));
                this.classList.add('active-nav');
            });
        });

        // Logout functionality
        document.querySelector('button[onclick="logout()"]').addEventListener('click', logout);
        
        function logout() {
            localStorage.removeItem('authToken');
            localStorage.removeItem('currentUser');
            window.location.href = 'login.html';
        }

        // Load dashboard data
        async function loadDashboardData() {
            try {
                const response = await fetch('/api/admin/stats', {
                    headers: {
                        'Authorization': `Bearer ${authToken}`
                    }
                });
                
                if (response.status === 401) {
                    logout();
                    return;
                }
                
                const data = await response.json();
                
                // Update stats cards
                document.querySelector('[data-stat="users"]').textContent = data.totalUsers.toLocaleString();
                document.querySelector('[data-stat="products"]').textContent = data.totalProducts.toLocaleString();
                document.querySelector('[data-stat="articles"]').textContent = data.totalArticles.toLocaleString();
                document.querySelector('[data-stat="sessions"]').textContent = data.publishedArticles.toLocaleString();
                
            } catch (error) {
                console.error('Error loading dashboard data:', error);
            }
        }

        // Load products
        async function loadProducts() {
            try {
                const response = await fetch('/api/products?limit=5', {
                    headers: {
                        'Authorization': `Bearer ${authToken}`
                    }
                });
                
                if (response.status === 401) {
                    logout();
                    return;
                }
                
                const data = await response.json();
                const productsTable = document.getElementById('products-table-body');
                
                productsTable.innerHTML = data.products.map(product => `
                    <tr class="table-row border-b border-gray-200">
                        <td class="py-4">
                            <div class="flex items-center">
                                <img src="${product.image || 'http://static.photos/cosmetic/64x64/1'}" alt="${product.name}" class="w-10 h-10 rounded-lg object-cover">
                                <div class="ml-4">
                                    <p class="font-medium text-gray-900">${product.name}</p>
                                    <p class="text-sm text-gray-600">SKU: ${product.sku}</p>
                                </div>
                            </div>
                        </td>
                        <td class="py-4">${product.category}</td>
                        <td class="py-4">${product.price.toFixed(2)}</td>
                        <td class="py-4">
                            <span class="px-2 py-1 text-xs font-semibold ${product.status === 'active' ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-800'} rounded-full">
                                ${product.status}
                            </span>
                        </td>
                        <td class="py-4 text-right">
                            <div class="flex justify-end space-x-2">
                                <button onclick="editProduct('${product._id}')" class="p-1 text-blue-600 hover:text-blue-800">
                                    <i data-feather="edit" class="h-4 w-4"></i>
                                </button>
                                <button onclick="deleteProduct('${product._id}')" class="p-1 text-red-600 hover:text-red-800">
                                    <i data-feather="trash" class="h-4 w-4"></i>
                                </button>
                            </div>
                        </td>
                    </tr>
                `).join('');
                
                feather.replace();
                
            } catch (error) {
                console.error('Error loading products:', error);
            }
        }

        // Initialize dashboard
        loadDashboardData();
        loadProducts();
        
        function editProduct(id) {
            // Redirect to product edit page or open modal
            console.log('Edit product:', id);
        }
        
        async function deleteProduct(id) {
            if (confirm('Are you sure you want to delete this product?')) {
                try {
                    const response = await fetch(`/api/products/${id}`, {
                        method: 'DELETE',
                        headers: {
                            'Authorization': `Bearer ${authToken}`
                        }
                    });
                    
                    if (response.ok) {
                        loadProducts();
                        loadDashboardData();
                    } else {
                        alert('Error deleting product');
                    }
                } catch (error) {
                    console.error('Error deleting product:', error);
                }
            }
        }
    </script>
</body>
</html>