File size: 23,957 Bytes
23f3fa4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436892e
 
 
 
 
 
 
 
 
 
 
 
 
23f3fa4
436892e
 
 
 
 
 
 
 
 
 
23f3fa4
436892e
 
 
 
 
 
 
 
 
23f3fa4
436892e
23f3fa4
436892e
 
 
 
 
23f3fa4
436892e
 
 
 
 
 
 
23f3fa4
436892e
23f3fa4
436892e
 
 
 
 
 
23f3fa4
436892e
 
23f3fa4
436892e
 
 
 
23f3fa4
 
 
 
 
 
 
436892e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23f3fa4
075ff85
 
 
 
 
 
23f3fa4
436892e
 
 
 
 
 
 
 
 
23f3fa4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436892e
 
 
23f3fa4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436892e
23f3fa4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436892e
23f3fa4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436892e
23f3fa4
 
436892e
 
 
 
 
23f3fa4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436892e
 
 
 
 
 
 
 
 
 
23f3fa4
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Pest Detection Admin Panel</title>
    <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --bg-color: #0b0f19;
            --card-bg: #151d30;
            --card-border: #232d45;
            --text-main: #f3f4f6;
            --text-muted: #9ca3af;
            --accent-primary: #10b981;
            --accent-secondary: #059669;
            --accent-glow: rgba(16, 185, 129, 0.15);
            --danger: #ef4444;
            --warning: #f59e0b;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Outfit', sans-serif;
        }

        body {
            background-color: var(--bg-color);
            color: var(--text-main);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        header {
            background: linear-gradient(135deg, #111827 0%, #1f2937 100%);
            border-bottom: 1px solid var(--card-border);
            padding: 1.5rem 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .logo-container {
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }

        .logo-icon {
            font-size: 2rem;
        }

        h1 {
            font-size: 1.5rem;
            font-weight: 700;
            background: linear-gradient(to right, #10b981, #34d399);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .nav-stats {
            display: flex;
            gap: 1.5rem;
        }

        .stat-badge {
            background-color: var(--card-bg);
            border: 1px solid var(--card-border);
            padding: 0.5rem 1rem;
            border-radius: 9999px;
            font-size: 0.875rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .stat-count {
            font-weight: 700;
            color: var(--accent-primary);
        }

        .stat-count.pending {
            color: var(--warning);
        }

        main {
            flex: 1;
            max-width: 1400px;
            width: 100%;
            margin: 0 auto;
            padding: 2rem;
        }

        .notification-banner {
            background: rgba(16, 185, 129, 0.1);
            border: 1px solid rgba(16, 185, 129, 0.2);
            padding: 1rem;
            border-radius: 0.75rem;
            margin-bottom: 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .notification-banner button {
            background-color: var(--accent-primary);
            color: white;
            border: none;
            padding: 0.5rem 1rem;
            border-radius: 0.5rem;
            cursor: pointer;
            font-weight: 500;
            transition: all 0.2s ease;
        }

        .notification-banner button:hover {
            background-color: var(--accent-secondary);
        }

        .section-title {
            font-size: 1.25rem;
            font-weight: 600;
            margin-bottom: 1.5rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .reports-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(600px, 1fr));
            gap: 2rem;
            margin-bottom: 3rem;
        }

        @media (max-width: 768px) {
            .reports-grid {
                grid-template-columns: 1fr;
            }
        }

        .report-card {
            background-color: var(--card-bg);
            border: 1px solid var(--card-border);
            border-radius: 1rem;
            overflow: hidden;
            display: flex;
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            position: relative;
        }

        .report-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 10px 20px rgba(0,0,0,0.3), 0 0 15px var(--accent-glow);
        }

        .report-card.resolved-card {
            opacity: 0.85;
        }

        .report-image-container {
            width: 45%;
            position: relative;
            background-color: #0d121f;
        }

        .report-image {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .report-details {
            width: 55%;
            padding: 1.5rem;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
        }

        .meta-info {
            font-size: 0.8rem;
            color: var(--text-muted);
            margin-bottom: 0.75rem;
        }

        .meta-item {
            margin-bottom: 0.25rem;
            word-break: break-all;
        }

        .meta-label {
            font-weight: 500;
            color: var(--text-main);
        }

        .report-form {
            display: flex;
            flex-direction: column;
            gap: 0.75rem;
        }

        .form-group {
            display: flex;
            flex-direction: column;
            gap: 0.25rem;
        }

        label {
            font-size: 0.8rem;
            font-weight: 500;
            color: var(--text-muted);
        }

        input[type="text"], textarea {
            background-color: #0b0f19;
            border: 1px solid var(--card-border);
            border-radius: 0.375rem;
            padding: 0.5rem 0.75rem;
            color: var(--text-main);
            font-size: 0.875rem;
            outline: none;
            transition: border-color 0.2s ease;
        }

        input[type="text"]:focus, textarea:focus {
            border-color: var(--accent-primary);
        }

        textarea {
            resize: none;
            height: 80px;
        }

        .btn-resolve {
            background-color: var(--accent-primary);
            color: white;
            border: none;
            padding: 0.5rem 1rem;
            border-radius: 0.375rem;
            cursor: pointer;
            font-weight: 600;
            font-size: 0.875rem;
            transition: all 0.2s ease;
            margin-top: 0.25rem;
        }

        .btn-resolve:hover {
            background-color: var(--accent-secondary);
        }

        .resolved-display {
            border-top: 1px solid var(--card-border);
            padding-top: 1rem;
            margin-top: 1rem;
        }

        .resolved-badge {
            background-color: rgba(16, 185, 129, 0.15);
            color: var(--accent-primary);
            border: 1px solid rgba(16, 185, 129, 0.3);
            padding: 0.25rem 0.5rem;
            border-radius: 0.25rem;
            font-size: 0.75rem;
            font-weight: 600;
            display: inline-block;
            margin-bottom: 0.5rem;
        }

        .resolved-title {
            font-weight: 600;
            margin-bottom: 0.25rem;
        }

        .resolved-treatment {
            font-size: 0.875rem;
            color: var(--text-muted);
        }

        .empty-state {
            grid-column: 1 / -1;
            text-align: center;
            padding: 4rem 2rem;
            background-color: var(--card-bg);
            border: 1px dashed var(--card-border);
            border-radius: 1rem;
            color: var(--text-muted);
        }

        .empty-icon {
            font-size: 3rem;
            margin-bottom: 1rem;
        }

        footer {
            text-align: center;
            padding: 2rem;
            color: var(--text-muted);
            font-size: 0.875rem;
            border-top: 1px solid var(--card-border);
        }
    </style>
</head>
<body>
    <div id="login-view" style="display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; padding: 2rem; flex: 1;">
        <div style="background-color: var(--card-bg); border: 1px solid var(--card-border); border-radius: 1.5rem; padding: 3rem; width: 100%; max-width: 450px; text-align: center; box-shadow: 0 20px 40px rgba(0,0,0,0.5);">
            <span style="font-size: 3.5rem; display: block; margin-bottom: 1rem;">🌾</span>
            <h2 style="font-size: 1.75rem; margin-bottom: 0.5rem; font-weight: 700; background: linear-gradient(to right, #10b981, #34d399); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">Pest Detection Admin</h2>
            <p style="color: var(--text-muted); font-size: 0.875rem; margin-bottom: 2rem;">Enter admin password to access the console</p>
            <form onsubmit="handleLogin(event)" style="display: flex; flex-direction: column; gap: 1rem; width: 100%;">
                <div style="display: flex; flex-direction: column; text-align: left; gap: 0.5rem;">
                    <label for="admin-password">Admin Password</label>
                    <input type="password" id="admin-password" required placeholder="β€’β€’β€’β€’β€’β€’β€’β€’" style="background-color: #0b0f19; border: 1px solid var(--card-border); border-radius: 0.5rem; padding: 0.75rem 1rem; color: var(--text-main); font-size: 1rem; outline: none; transition: border-color 0.2s ease;">
                </div>
                <div id="login-error" style="color: var(--danger); font-size: 0.875rem; display: none; text-align: left; margin-top: 0.25rem;">❌ Incorrect password, please try again.</div>
                <button type="submit" style="background-color: var(--accent-primary); color: white; border: none; padding: 0.75rem 1.5rem; border-radius: 0.5rem; cursor: pointer; font-weight: 600; font-size: 1rem; transition: background-color 0.2s ease; margin-top: 0.5rem;">Access Dashboard</button>
            </form>
        </div>
    </div>

    <div id="dashboard-view" style="display: none; flex-direction: column; flex: 1; width: 100%;">
        <header>
            <div class="logo-container">
                <span class="logo-icon">🌾</span>
                <div>
                    <h1>Pest Detection Admin</h1>
                    <p style="font-size: 0.75rem; color: var(--text-muted);">Real-time Crop Diagnostics Console</p>
                </div>
            </div>
            <div class="nav-stats">
                <div class="stat-badge">
                    <span>Pending Review:</span>
                    <span class="stat-count pending" id="pending-count">0</span>
                </div>
                <div class="stat-badge">
                    <span>Resolved:</span>
                    <span class="stat-count" id="resolved-count">0</span>
                </div>
            </div>
        </header>

        <main>
            <div class="notification-banner" id="notif-banner" style="display: none;">
                <p>πŸ”” Enable desktop notifications to receive instant audio and visual alerts when users report unrecognized pests.</p>
                <button onclick="requestNotificationPermission()">Enable Notifications</button>
            </div>

            <section>
                <h2 class="section-title">πŸ•’ Pending User Submissions</h2>
                <div class="reports-grid" id="pending-reports-grid">
                    <div class="empty-state">
                        <div class="empty-icon">πŸŽ‰</div>
                        <p>All clear! There are no pending unrecognized pest reports.</p>
                    </div>
                </div>
            </section>

            <section style="margin-top: 4rem;">
                <h2 class="section-title">βœ… Resolved Submissions</h2>
                <div class="reports-grid" id="resolved-reports-grid">
                    <div class="empty-state">
                        <p>No reports resolved yet.</p>
                    </div>
                </div>
            </section>
        </main>

        <footer>
            <p>Administered by Fadhili and Didas</p>
        </footer>
    </div>

    <audio id="alert-sound" src="https://assets.mixkit.co/active_storage/sfx/911/911-500.wav" preload="auto"></audio>

    <script>
        let previousPendingIds = new Set();
        let isInitialLoad = true;

        function getAuthHeaders() {
            const password = sessionStorage.getItem('adminPassword') || '';
            return {
                'X-Admin-Password': password
            };
        }

        async function handleLogin(event) {
            event.preventDefault();
            const passwordInput = document.getElementById('admin-password').value;
            const errorDiv = document.getElementById('login-error');
            
            try {
                const response = await fetch('/admin/api/reports', {
                    headers: { 'X-Admin-Password': passwordInput }
                });
                
                if (response.status === 200) {
                    sessionStorage.setItem('adminPassword', passwordInput);
                    errorDiv.style.display = 'none';
                    showDashboard();
                } else {
                    errorDiv.style.display = 'block';
                }
            } catch (err) {
                console.error("Login failed:", err);
                errorDiv.style.display = 'block';
            }
        }

        function showDashboard() {
            document.getElementById('login-view').style.display = 'none';
            document.getElementById('dashboard-view').style.display = 'flex';
            checkNotificationPermission();
            fetchReports();
            setInterval(fetchReports, 10000);
        }

        async function fetchReports() {
            // Do not refresh reports while the user is actively typing to avoid losing form input
            const activeEl = document.activeElement;
            if (activeEl && (activeEl.tagName === 'INPUT' || activeEl.tagName === 'TEXTAREA')) {
                return;
            }

            try {
                const response = await fetch('/admin/api/reports', {
                    headers: getAuthHeaders()
                });
                if (response.status === 401) {
                    // Password expired or changed, kick back to login
                    sessionStorage.removeItem('adminPassword');
                    location.reload();
                    return;
                }
                const data = await response.json();
                if (data.status === 'success') {
                    renderReports(data.reports);
                }
            } catch (err) {
                console.error("Failed to fetch reports:", err);
            }
        }

        function renderReports(reports) {
            const pendingGrid = document.getElementById('pending-reports-grid');
            const resolvedGrid = document.getElementById('resolved-reports-grid');
            
            const pendingReports = reports.filter(r => r.status === 'pending');
            const resolvedReports = reports.filter(r => r.status === 'resolved');

            const password = sessionStorage.getItem('adminPassword') || '';
            const passwordParam = `?password=${encodeURIComponent(password)}`;

            // Update stats in header
            document.getElementById('pending-count').textContent = pendingReports.length;
            document.getElementById('resolved-count').textContent = resolvedReports.length;

            // Update page tab title badge count
            if (pendingReports.length > 0) {
                document.title = `(${pendingReports.length}) Pest Detection Admin`;
            } else {
                document.title = "Pest Detection Admin Panel";
            }

            // Check for new pending reports to trigger alerts
            const currentPendingIds = new Set(pendingReports.map(r => r.id));
            if (!isInitialLoad) {
                let hasNew = false;
                for (let id of currentPendingIds) {
                    if (!previousPendingIds.has(id)) {
                        hasNew = true;
                        break;
                    }
                }
                if (hasNew) {
                    playAlert();
                    triggerNotification(pendingReports.length);
                }
            }
            previousPendingIds = currentPendingIds;
            isInitialLoad = false;

            // Render Pending Grid
            if (pendingReports.length === 0) {
                pendingGrid.innerHTML = `
                    <div class="empty-state">
                        <div class="empty-icon">πŸŽ‰</div>
                        <p>All clear! There are no pending unrecognized pest reports.</p>
                    </div>
                `;
            } else {
                pendingGrid.innerHTML = pendingReports.map(r => `
                    <div class="report-card" id="card-${r.id}">
                        <div class="report-image-container">
                            <img class="report-image" src="/admin/image/${r.image_path}${passwordParam}" alt="Unrecognized pest">
                        </div>
                        <div class="report-details">
                            <div>
                                <div class="meta-info">
                                    <div class="meta-item"><span class="meta-label">ID:</span> #${r.id}</div>
                                    <div class="meta-item"><span class="meta-label">Device:</span> ${r.device_id}</div>
                                    <div class="meta-item"><span class="meta-label">Date:</span> ${new Date(r.created_at).toLocaleString()}</div>
                                </div>
                            </div>
                            <form class="report-form" onsubmit="resolveReport(event, ${r.id})">
                                <div class="form-group">
                                    <label for="pest-${r.id}">Identified Pest Name</label>
                                    <input type="text" id="pest-${r.id}" required placeholder="e.g. Stem Borer / Maize Weevil">
                                </div>
                                <div class="form-group">
                                    <label for="treat-${r.id}">Treatment Recommendation Plan</label>
                                    <textarea id="treat-${r.id}" required placeholder="Provide step-by-step chemical/biological treatment plan..."></textarea>
                                </div>
                                <button type="submit" class="btn-resolve">Resolve & Notify Farmer</button>
                            </form>
                        </div>
                    </div>
                `).join('');
            }

            // Render Resolved Grid
            if (resolvedReports.length === 0) {
                resolvedGrid.innerHTML = `
                    <div class="empty-state">
                        <p>No reports resolved yet.</p>
                    </div>
                `;
            } else {
                resolvedGrid.innerHTML = resolvedReports.map(r => `
                    <div class="report-card resolved-card">
                        <div class="report-image-container">
                            <img class="report-image" src="/admin/image/${r.image_path}${passwordParam}" alt="Resolved pest">
                        </div>
                        <div class="report-details">
                            <div>
                                <span class="resolved-badge">Resolved</span>
                                <div class="meta-info">
                                    <div class="meta-item"><span class="meta-label">ID:</span> #${r.id}</div>
                                    <div class="meta-item"><span class="meta-label">Device:</span> ${r.device_id}</div>
                                    <div class="meta-item"><span class="meta-label">Date:</span> ${new Date(r.created_at).toLocaleString()}</div>
                                </div>
                                <div class="resolved-display">
                                    <div class="resolved-title">${r.pest_name}</div>
                                    <div class="resolved-treatment">${r.treatment}</div>
                                </div>
                            </div>
                        </div>
                    </div>
                `).join('');
            }
        }

        async function resolveReport(event, id) {
            event.preventDefault();
            const pestName = document.getElementById(`pest-${id}`).value;
            const treatment = document.getElementById(`treat-${id}`).value;

            const formData = new FormData();
            formData.append('pest_name', pestName);
            formData.append('treatment', treatment);

            try {
                const response = await fetch(`/admin/api/resolve/${id}`, {
                    method: 'POST',
                    headers: getAuthHeaders(),
                    body: formData
                });
                if (response.status === 401) {
                    sessionStorage.removeItem('adminPassword');
                    location.reload();
                    return;
                }
                const data = await response.json();
                if (data.status === 'success') {
                    // Remove card with visual fade effect
                    const card = document.getElementById(`card-${id}`);
                    card.style.transition = "opacity 0.5s ease, transform 0.5s ease";
                    card.style.opacity = 0;
                    card.style.transform = "scale(0.9)";
                    setTimeout(() => {
                        fetchReports();
                    }, 500);
                }
            } catch (err) {
                alert("Failed to resolve report: " + err);
            }
        }

        function playAlert() {
            const sound = document.getElementById('alert-sound');
            if (sound) {
                sound.play().catch(e => console.log("Audio play blocked by browser."));
            }
        }

        function requestNotificationPermission() {
            Notification.requestPermission().then(permission => {
                if (permission === 'granted') {
                    document.getElementById('notif-banner').style.display = 'none';
                    new Notification("Notifications Enabled!", {
                        body: "You will now receive alerts for new unrecognized pest scans.",
                        icon: "🌾"
                    });
                }
            });
        }

        function checkNotificationPermission() {
            if (Notification.permission === 'default') {
                document.getElementById('notif-banner').style.display = 'flex';
            }
        }

        function triggerNotification(pendingCount) {
            if (Notification.permission === 'granted') {
                new Notification("New Unrecognized Pest Scan!", {
                    body: `There are currently ${pendingCount} pending reports waiting for identification.`,
                    icon: "🌾"
                });
            }
        }

        // Initialize session check
        window.addEventListener('DOMContentLoaded', () => {
            const savedPassword = sessionStorage.getItem('adminPassword');
            if (savedPassword) {
                showDashboard();
            } else {
                document.getElementById('login-view').style.display = 'flex';
                document.getElementById('dashboard-view').style.display = 'none';
            }
        });
    </script>
</body>
</html>