File size: 20,452 Bytes
399fd10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
// Demo Patient Data
const patients = [
    {
        id: 1,
        firstName: "John",
        lastName: "Smith",
        mrn: "839214",
        status: "active",
        insurance: "BlueCross",
        insuranceProvider: "BlueCross",
        nextAppointment: "2026-04-02",
        expirationDate: "2026-05-12",
        clinic: "Los Angeles",
        lastVisit: "2026-03-01",
        phoneVerified: true,
        emailVerified: true,
        provider: "Dr. Smith",
        tags: ["new"]
    },
    {
        id: 2,
        firstName: "Maria",
        lastName: "Gonzalez",
        mrn: "481992",
        status: "pending",
        insurance: "UnitedHealth",
        insuranceProvider: "UnitedHealth",
        nextAppointment: "2026-03-18",
        expirationDate: "2026-04-10",
        clinic: "San Diego",
        lastVisit: "2026-02-15",
        phoneVerified: true,
        emailVerified: false,
        provider: "Dr. Johnson",
        tags: ["followup"]
    },
    {
        id: 3,
        firstName: "David",
        lastName: "Chen",
        mrn: "673204",
        status: "active",
        insurance: "Aetna",
        insuranceProvider: "Aetna",
        nextAppointment: "2026-04-06",
        expirationDate: "2026-06-02",
        clinic: "San Francisco",
        lastVisit: "2026-03-05",
        phoneVerified: true,
        emailVerified: true,
        provider: "Dr. Smith",
        tags: ["telehealth"]
    },
    {
        id: 4,
        firstName: "Sarah",
        lastName: "Johnson",
        mrn: "904211",
        status: "approved",
        insurance: "Kaiser Permanente",
        insuranceProvider: "Kaiser",
        nextAppointment: "2026-04-01",
        expirationDate: "2026-05-20",
        clinic: "Los Angeles",
        lastVisit: "2026-03-10",
        phoneVerified: true,
        emailVerified: true,
        provider: "Dr. Williams",
        tags: []
    },
    {
        id: 5,
        firstName: "Michael",
        lastName: "Patel",
        mrn: "510992",
        status: "expired",
        insurance: "Medicare",
        insuranceProvider: "Medicare",
        nextAppointment: null,
        expirationDate: "2026-02-10",
        clinic: "San Jose",
        lastVisit: "2026-01-20",
        phoneVerified: false,
        emailVerified: true,
        provider: "Dr. Brown",
        tags: ["billing"]
    },
    {
        id: 6,
        firstName: "Lisa",
        lastName: "Nguyen",
        mrn: "482311",
        status: "active",
        insurance: "BlueShield",
        insuranceProvider: "BlueShield",
        nextAppointment: "2026-03-29",
        expirationDate: "2026-07-08",
        clinic: "Sacramento",
        lastVisit: "2026-02-28",
        phoneVerified: true,
        emailVerified: true,
        provider: "Dr. Johnson",
        tags: []
    },
    {
        id: 7,
        firstName: "Robert",
        lastName: "Walker",
        mrn: "881420",
        status: "active",
        insurance: "UnitedHealth",
        insuranceProvider: "UnitedHealth",
        nextAppointment: "2026-04-05",
        expirationDate: "2026-06-14",
        clinic: "Los Angeles",
        lastVisit: "2026-03-08",
        phoneVerified: true,
        emailVerified: false,
        provider: "Dr. Smith",
        tags: ["allergy"]
    },
    {
        id: 8,
        firstName: "Emily",
        lastName: "Carter",
        mrn: "640199",
        status: "pending",
        insurance: "Aetna",
        insuranceProvider: "Aetna",
        nextAppointment: "2026-03-20",
        expirationDate: "2026-04-22",
        clinic: "San Diego",
        lastVisit: "2026-02-25",
        phoneVerified: true,
        emailVerified: true,
        provider: "Dr. Williams",
        tags: ["new"]
    },
    {
        id: 9,
        firstName: "Daniel",
        lastName: "Kim",
        mrn: "777200",
        status: "approved",
        insurance: "BlueCross",
        insuranceProvider: "BlueCross",
        nextAppointment: "2026-04-03",
        expirationDate: "2026-05-30",
        clinic: "San Francisco",
        lastVisit: "2026-03-12",
        phoneVerified: true,
        emailVerified: true,
        provider: "Dr. Brown",
        tags: ["telehealth"]
    },
    {
        id: 10,
        firstName: "Jessica",
        lastName: "Brown",
        mrn: "223901",
        status: "archived",
        insurance: "Kaiser Permanente",
        insuranceProvider: "Kaiser",
        nextAppointment: null,
        expirationDate: null,
        clinic: "Fresno",
        lastVisit: "2025-12-15",
        phoneVerified: false,
        emailVerified: false,
        provider: "Dr. Johnson",
        tags: []
    },
    {
        id: 11,
        firstName: "Carlos",
        lastName: "Ramirez",
        mrn: "100239",
        status: "active",
        insurance: "Medicare",
        insuranceProvider: "Medicare",
        nextAppointment: "2026-03-25",
        expirationDate: "2026-05-05",
        clinic: "San Jose",
        lastVisit: "2026-02-20",
        phoneVerified: true,
        emailVerified: true,
        provider: "Dr. Smith",
        tags: []
    },
    {
        id: 12,
        firstName: "Olivia",
        lastName: "Taylor",
        mrn: "564009",
        status: "active",
        insurance: "BlueShield",
        insuranceProvider: "BlueShield",
        nextAppointment: "2026-04-04",
        expirationDate: "2026-06-18",
        clinic: "Los Angeles",
        lastVisit: "2026-03-15",
        phoneVerified: true,
        emailVerified: true,
        provider: "Dr. Williams",
        tags: ["new", "telehealth"]
    }
];

// State Management
let currentPage = 1;
let pageSize = 12;
let selectedRows = new Set();
let filteredPatients = [...patients];
let currentFilters = {
    search: '',
    status: 'all',
    tag: 'all',
    insurance: 'all',
    provider: 'all',
    date: 'all'
};

// Avatar Color Generator
function getAvatarColor(id) {
    const colors = [
        { bg: '#DBEAFE', text: '#1D4ED8' },
        { bg: '#EDE9FE', text: '#6D28D9' },
        { bg: '#FCE7F3', text: '#BE185D' },
        { bg: '#D1FAE5', text: '#047857' },
        { bg: '#FEF3C7', text: '#B45309' },
        { bg: '#E0E7FF', text: '#4338CA' }
    ];
    return colors[id % colors.length];
}

// Date Formatting
function formatDate(dateString) {
    if (!dateString) return '—';
    const date = new Date(dateString);
    return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
}

// Check if date is within 30 days or past due
function getExpirationClass(dateString) {
    if (!dateString) return '';
    const expDate = new Date(dateString);
    const today = new Date();
    const diffTime = expDate - today;
    const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
    
    if (diffDays < 0) return 'expiration-danger';
    if (diffDays <= 30) return 'expiration-warning';
    return '';
}

function getExpirationText(dateString) {
    if (!dateString) return '—';
    const expDate = new Date(dateString);
    const today = new Date();
    const diffTime = expDate - today;
    const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
    
    if (diffDays < 0) return 'Expired';
    return formatDate(dateString);
}

// Render Patient Row
function renderPatientRow(patient) {
    const avatarColors = getAvatarColor(patient.id);
    const initials = `${patient.firstName[0]}${patient.lastName[0]}`;
    const isSelected = selectedRows.has(patient.id);
    const expirationClass = getExpirationClass(patient.expirationDate);
    const expirationText = getExpirationText(patient.expirationDate);
    
    return `
        <div class="patient-row grid grid-cols-12 gap-4 px-6 py-4 items-center bg-white border-l-3 border-transparent cursor-pointer ${isSelected ? 'selected' : ''}" 
             onclick="handleRowClick(event, ${patient.id})" 
             data-id="${patient.id}">
            
            <!-- Patient Column -->
            <div class="col-span-4 flex items-center gap-3">
                <input type="checkbox" 
                       class="row-checkbox w-4 h-4 rounded border-gray-300 text-brand-600 focus:ring-brand-600 cursor-pointer"
                       ${isSelected ? 'checked' : ''} 
                       onclick="event.stopPropagation(); toggleRowSelection(${patient.id})">
                
                <div class="relative flex-shrink-0">
                    <div class="w-10 h-10 rounded-full flex items-center justify-center text-sm font-semibold"
                         style="background-color: ${avatarColors.bg}; color: ${avatarColors.text};">
                        ${initials}
                    </div>
                    <div class="avatar-status ${patient.status}"></div>
                </div>
                
                <div class="min-w-0 flex-1">
                    <div class="flex items-center gap-2">
                        <span class="text-sm font-semibold text-gray-900 truncate">
                            ${patient.firstName} ${patient.lastName}
                        </span>
                        ${patient.phoneVerified ? '<i data-lucide="phone" class="w-3 h-3 text-green-500"></i>' : ''}
                        ${patient.emailVerified ? '<i data-lucide="mail" class="w-3 h-3 text-blue-500"></i>' : ''}
                    </div>
                    <div class="text-xs text-gray-500 mt-0.5">MRN ${patient.mrn}</div>
                    <div class="text-xs text-gray-400 mt-0.5 truncate">
                        Last visit ${formatDate(patient.lastVisit)}${patient.clinic} Clinic
                    </div>
                </div>
            </div>

            <!-- Status Column -->
            <div class="col-span-1">
                <span class="status-chip ${patient.status}">
                    ${patient.status.charAt(0).toUpperCase() + patient.status.slice(1)}
                </span>
            </div>

            <!-- Insurance Column -->
            <div class="col-span-2 flex items-center gap-2 text-sm text-gray-700">
                <i data-lucide="shield" class="w-4 h-4 text-gray-400"></i>
                <span class="truncate">${patient.insurance}</span>
            </div>

            <!-- Next Appointment Column -->
            <div class="col-span-2 text-sm text-gray-700">
                ${formatDate(patient.nextAppointment)}
            </div>

            <!-- Expires Column -->
            <div class="col-span-1 text-sm ${expirationClass}">
                ${expirationText}
            </div>

            <!-- Clinic Column -->
            <div class="col-span-1 text-sm text-gray-700">
                ${patient.clinic}
            </div>

            <!-- Actions Column -->
            <div class="col-span-1 flex justify-end relative">
                <button onclick="event.stopPropagation(); toggleDropdown(event, ${patient.id})" 
                        class="p-2 hover:bg-gray-100 rounded-lg transition-colors">
                    <i data-lucide="more-vertical" class="w-4 h-4 text-gray-500"></i>
                </button>
            </div>
        </div>
    `;
}

// Filter Logic
function applyFilters() {
    filteredPatients = patients.filter(patient => {
        // Search filter
        if (currentFilters.search) {
            const searchLower = currentFilters.search.toLowerCase();
            const fullName = `${patient.firstName} ${patient.lastName}`.toLowerCase();
            const match = fullName.includes(searchLower) || 
                         patient.mrn.includes(searchLower) ||
                         patient.clinic.toLowerCase().includes(searchLower);
            if (!match) return false;
        }

        // Status filter
        if (currentFilters.status !== 'all' && patient.status !== currentFilters.status) {
            return false;
        }

        // Insurance filter
        if (currentFilters.insurance !== 'all' && patient.insuranceProvider !== currentFilters.insurance) {
            return false;
        }

        // Provider filter
        if (currentFilters.provider !== 'all' && patient.provider !== currentFilters.provider) {
            return false;
        }

        // Tag filter
        if (currentFilters.tag !== 'all' && !patient.tags.includes(currentFilters.tag)) {
            return false;
        }

        return true;
    });

    currentPage = 1;
    render();
}

// Render List
function render() {
    const container = document.getElementById('patientList');
    const start = (currentPage - 1) * pageSize;
    const end = start + pageSize;
    const pagePatients = filteredPatients.slice(start, end);

    if (pagePatients.length === 0) {
        container.innerHTML = '';
        document.getElementById('emptyState').classList.remove('hidden');
    } else {
        document.getElementById('emptyState').classList.add('hidden');
        container.innerHTML = pagePatients.map(p => renderPatientRow(p)).join('');
        lucide.createIcons();
    }

    updatePagination();
    updateBulkActions();
}

// Pagination
function updatePagination() {
    const total = filteredPatients.length;
    const start = (currentPage - 1) * pageSize + 1;
    const end = Math.min(currentPage * pageSize, total);

    document.getElementById('showingStart').textContent = total === 0 ? 0 : start;
    document.getElementById('showingEnd').textContent = end;
    document.getElementById('totalCount').textContent = total;

    document.getElementById('prevBtn').disabled = currentPage === 1;
    document.getElementById('nextBtn').disabled = end >= total;

    // Page numbers
    const totalPages = Math.ceil(total / pageSize);
    const pageContainer = document.getElementById('pageNumbers');
    let html = '';
    
    for (let i = 1; i <= totalPages; i++) {
        if (i === 1 || i === totalPages || (i >= currentPage - 1 && i <= currentPage + 1)) {
            html += `<button onclick="goToPage(${i})" class="w-8 h-8 flex items-center justify-center rounded-lg text-sm font-medium transition-colors ${i === currentPage ? 'bg-brand-600 text-white' : 'text-gray-700 hover:bg-gray-100'}">${i}</button>`;
        } else if (i === currentPage - 2 || i === currentPage + 2) {
            html += `<span class="px-1 text-gray-400">...</span>`;
        }
    }
    pageContainer.innerHTML = html;
}

function changePage(delta) {
    currentPage += delta;
    render();
    window.scrollTo({ top: 0, behavior: 'smooth' });
}

function goToPage(page) {
    currentPage = page;
    render();
    window.scrollTo({ top: 0, behavior: 'smooth' });
}

function changePageSize() {
    pageSize = parseInt(document.getElementById('pageSize').value);
    currentPage = 1;
    render();
}

// Row Selection
function toggleRowSelection(id) {
    if (selectedRows.has(id)) {
        selectedRows.delete(id);
    } else {
        selectedRows.add(id);
    }
    render();
}

function handleRowClick(event, id) {
    // Navigate to patient details
    showToast(`Navigating to /patients/${id}`, 'info');
    // Simulate navigation
    console.log(`Navigate to /patients/${id}`);
}

function toggleSelectAll() {
    const checkboxes = document.querySelectorAll('.row-checkbox');
    const allSelected = selectedRows.size === filteredPatients.length;
    
    if (allSelected) {
        selectedRows.clear();
    } else {
        filteredPatients.forEach(p => selectedRows.add(p.id));
    }
    render();
}

function clearSelection() {
    selectedRows.clear();
    render();
}

function updateBulkActions() {
    const bar = document.getElementById('bulkActionsBar');
    const count = document.getElementById('selectedCount');
    
    if (selectedRows.size > 0) {
        bar.classList.remove('hidden');
        count.textContent = selectedRows.size;
    } else {
        bar.classList.add('hidden');
    }

    // Update select all checkbox
    const selectAllCheckbox = document.getElementById('selectAll');
    if (filteredPatients.length > 0 && selectedRows.size === filteredPatients.length) {
        selectAllCheckbox.checked = true;
        selectAllCheckbox.indeterminate = false;
    } else if (selectedRows.size > 0) {
        selectAllCheckbox.checked = false;
        selectAllCheckbox.indeterminate = true;
    } else {
        selectAllCheckbox.checked = false;
        selectAllCheckbox.indeterminate = false;
    }
}

function bulkAction(action) {
    showToast(`${action.charAt(0).toUpperCase() + action.slice(1)} ${selectedRows.size} patients (demo)`, 'success');
    if (action === 'archive') {
        clearSelection();
    }
}

// Dropdown Menu
let activeDropdown = null;

function toggleDropdown(event, patientId) {
    event.stopPropagation();
    
    // Close existing
    if (activeDropdown) {
        activeDropdown.remove();
        activeDropdown = null;
        return;
    }

    // Create new dropdown
    const template = document.getElementById('dropdownTemplate');
    const dropdown = template.cloneNode(true);
    dropdown.id = 'activeDropdown';
    dropdown.classList.remove('hidden');
    
    // Position
    const button = event.currentTarget;
    const rect = button.getBoundingClientRect();
    dropdown.style.position = 'fixed';
    dropdown.style.top = `${rect.bottom + 4}px`;
    dropdown.style.right = `${window.innerWidth - rect.right}px`;
    dropdown.style.zIndex = '100';
    
    document.body.appendChild(dropdown);
    activeDropdown = dropdown;
    lucide.createIcons();

    // Close on outside click
    setTimeout(() => {
        document.addEventListener('click', closeDropdown, { once: true });
    }, 0);
}

function closeDropdown() {
    if (activeDropdown) {
        activeDropdown.remove();
        activeDropdown = null;
    }
}

function handleAction(action) {
    closeDropdown();
    const messages = {
        view: 'Viewing patient details',
        edit: 'Opening patient editor',
        schedule: 'Opening scheduler',
        telehealth: 'Starting telehealth session',
        invoice: 'Invoice created (demo)',
        message: 'Message composer opened',
        upload: 'Document upload opened',
        archive: 'Patient archived (demo)'
    };
    showToast(messages[action] || 'Action completed', action === 'archive' ? 'warning' : 'success');
}

// More Filters Toggle
function toggleMoreFilters() {
    const panel = document.getElementById('moreFilters');
    panel.classList.toggle('hidden');
}

// Toast Notifications
function showToast(message, type = 'info') {
    const container = document.getElementById('toast-container');
    const toast = document.createElement('div');
    
    const colors = {
        success: 'bg-green-50 text-green-800 border-green-200',
        warning: 'bg-amber-50 text-amber-800 border-amber-200',
        error: 'bg-red-50 text-red-800 border-red-200',
        info: 'bg-blue-50 text-blue-800 border-blue-200'
    };

    const icons = {
        success: 'check-circle',
        warning: 'alert-triangle',
        error: 'x-circle',
        info: 'info'
    };
    
    toast.className = `${colors[type]} border rounded-lg px-4 py-3 shadow-lg flex items-center gap-3 min-w-[300px] animate-fade-up`;
    toast.innerHTML = `
        <i data-lucide="${icons[type]}" class="w-5 h-5"></i>
        <span class="text-sm font-medium">${message}</span>
    `;
    
    container.appendChild(toast);
    lucide.createIcons();
    
    setTimeout(() => {
        toast.style.opacity = '0';
        toast.style.transform = 'translateX(100%)';
        toast.style.transition = 'all 300ms ease';
        setTimeout(() => toast.remove(), 300);
    }, 3000);
}

// Event Listeners
document.getElementById('searchInput').addEventListener('input', (e) => {
    currentFilters.search = e.target.value;
    applyFilters();
});

document.getElementById('statusFilter').addEventListener('change', (e) => {
    currentFilters.status = e.target.value;
    applyFilters();
});

document.getElementById('insuranceFilter').addEventListener('change', (e) => {
    currentFilters.insurance = e.target.value;
    applyFilters();
});

document.getElementById('providerFilter').addEventListener('change', (e) => {
    currentFilters.provider = e.target.value;
    applyFilters();
});

document.getElementById('tagFilter').addEventListener('change', (e) => {
    currentFilters.tag = e.target.value;
    applyFilters();
});

document.getElementById('selectAll').addEventListener('change', toggleSelectAll);

// Initialize
document.addEventListener('DOMContentLoaded', () => {
    render();
    lucide.createIcons();
});