File size: 7,519 Bytes
606fb3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// VerifyMC Medical Admin - Notifications Page JavaScript

document.addEventListener('DOMContentLoaded', function() {
    // Initialize Lucide icons
    lucide.createIcons();
    
    // Mobile menu toggle
    const mobileMenuBtn = document.getElementById('mobile-menu-btn');
    const sidebar = document.getElementById('sidebar');
    const sidebarOverlay = document.getElementById('sidebar-overlay');
    
    function toggleMobileMenu() {
        const isOpen = !sidebar.classList.contains('-translate-x-full');
        if (isOpen) {
            sidebar.classList.add('-translate-x-full');
            sidebarOverlay.classList.add('hidden');
            document.body.style.overflow = '';
        } else {
            sidebar.classList.remove('-translate-x-full');
            sidebarOverlay.classList.remove('hidden');
            document.body.style.overflow = 'hidden';
        }
    }
    
    mobileMenuBtn?.addEventListener('click', toggleMobileMenu);
    sidebarOverlay?.addEventListener('click', toggleMobileMenu);
    
    // User dropdown toggle
    const userDropdownBtn = document.getElementById('user-dropdown-btn');
    const userDropdown = document.getElementById('user-dropdown');
    let dropdownOpen = false;
    
    userDropdownBtn?.addEventListener('click', function(e) {
        e.stopPropagation();
        dropdownOpen = !dropdownOpen;
        if (dropdownOpen) {
            userDropdown.classList.remove('hidden');
        } else {
            userDropdown.classList.add('hidden');
        }
    });
    
    // Close dropdown when clicking outside
    document.addEventListener('click', function() {
        if (dropdownOpen) {
            dropdownOpen = false;
            userDropdown?.classList.add('hidden');
        }
    });
    
    // Tab switching functionality
    const tabBtns = document.querySelectorAll('.tab-btn');
    const tabContents = document.querySelectorAll('.tab-content');
    
    tabBtns.forEach(btn => {
        btn.addEventListener('click', function() {
            const tabName = this.getAttribute('data-tab');
            
            // Update button styles
            tabBtns.forEach(b => {
                b.classList.remove('bg-primary', 'text-white', 'shadow-sm');
                b.classList.add('text-gray-600', 'hover:bg-gray-50');
            });
            this.classList.remove('text-gray-600', 'hover:bg-gray-50');
            this.classList.add('bg-primary', 'text-white', 'shadow-sm');
            
            // Show corresponding content
            tabContents.forEach(content => {
                content.classList.add('hidden');
            });
            const activeContent = document.getElementById(`tab-${tabName}`);
            if (activeContent) {
                activeContent.classList.remove('hidden');
            }
        });
    });
    
    // Toggle switches functionality
    const toggleSwitches = document.querySelectorAll('.toggle-switch');
    
    toggleSwitches.forEach(toggle => {
        toggle.addEventListener('click', function() {
            const isEnabled = this.classList.contains('bg-primary');
            const span = this.querySelector('span');
            
            if (isEnabled) {
                // Disable
                this.classList.remove('bg-primary');
                this.classList.add('bg-gray-200');
                span.classList.remove('translate-x-6');
                span.classList.add('translate-x-1');
            } else {
                // Enable
                this.classList.remove('bg-gray-200');
                this.classList.add('bg-primary');
                span.classList.remove('translate-x-1');
                span.classList.add('translate-x-6');
            }
        });
    });
    
    // Save Changes button interaction
    const saveBtn = document.querySelector('button:has([data-lucide="save"])');
    const cancelBtn = document.querySelector('button:contains("Cancel")') || 
                    Array.from(document.querySelectorAll('button')).find(b => b.textContent.includes('Cancel'));
    
    saveBtn?.addEventListener('click', function() {
        // Show loading state
        const originalContent = this.innerHTML;
        this.disabled = true;
        this.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> Saving...';
        lucide.createIcons();
        
        // Simulate API call
        setTimeout(() => {
            this.innerHTML = '<i data-lucide="check" class="w-4 h-4"></i> Saved!';
            lucide.createIcons();
            
            setTimeout(() => {
                this.innerHTML = originalContent;
                this.disabled = false;
                lucide.createIcons();
            }, 1500);
        }, 1000);
    });
    
    // Cancel button interaction
    if (cancelBtn) {
        cancelBtn.addEventListener('click', function() {
            // Reset all toggles to default state (all enabled)
            toggleSwitches.forEach(toggle => {
                toggle.classList.add('bg-primary');
                toggle.classList.remove('bg-gray-200');
                const span = toggle.querySelector('span');
                span.classList.add('translate-x-6');
                span.classList.remove('translate-x-1');
            });
        });
    }
    
    // Search functionality (basic implementation)
    const searchInput = document.querySelector('input[type="text"]');
    searchInput?.addEventListener('keypress', function(e) {
        if (e.key === 'Enter') {
            console.log('Searching for:', this.value);
            // Implement search logic here
        }
    });
    
    // Handle window resize to reset mobile menu state
    window.addEventListener('resize', function() {
        if (window.innerWidth >= 1024) {
            sidebar.classList.remove('-translate-x-full');
            sidebarOverlay.classList.add('hidden');
            document.body.style.overflow = '';
        } else {
            sidebar.classList.add('-translate-x-full');
        }
    });
    
    // Keyboard navigation for tabs
    document.addEventListener('keydown', function(e) {
        if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
            const activeTab = document.querySelector('.tab-btn.bg-primary');
            const tabs = Array.from(tabBtns);
            const currentIndex = tabs.indexOf(activeTab);
            
            let newIndex;
            if (e.key === 'ArrowLeft') {
                newIndex = currentIndex > 0 ? currentIndex - 1 : tabs.length - 1;
            } else {
                newIndex = currentIndex < tabs.length - 1 ? currentIndex + 1 : 0;
            }
            
            tabs[newIndex].click();
            tabs[newIndex].focus();
        }
    });
    
    // Notification badge animation
    const notificationBell = document.querySelector('[data-lucide="bell"]')?.parentElement;
    if (notificationBell) {
        notificationBell.addEventListener('click', function() {
            const badge = this.querySelector('span');
            if (badge) {
                badge.style.animation = 'pulse 0.5s ease-in-out';
                setTimeout(() => {
                    badge.style.animation = '';
                }, 500);
            }
        });
    }
});

// Add pulse animation keyframes dynamically
const style = document.createElement('style');
style.textContent = `
    @keyframes pulse {
        0%, 100% { transform: scale(1); }
        50% { transform: scale(1.2); }
    }
`;
document.head.appendChild(style);