File size: 3,030 Bytes
57d62ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Theme toggle functionality
document.addEventListener('DOMContentLoaded', () => {
    // Check for saved theme preference or use preferred color scheme
    const savedTheme = localStorage.getItem('theme') || 
                      (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
    document.documentElement.classList.add(savedTheme);
    
    // Initialize all tooltips
    const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
    tooltipTriggerList.map(function (tooltipTriggerEl) {
        return new bootstrap.Tooltip(tooltipTriggerEl);
    });
});

function toggleTheme() {
    const html = document.documentElement;
    const isDark = html.classList.contains('dark');
    
    if (isDark) {
        html.classList.remove('dark');
        localStorage.setItem('theme', 'light');
    } else {
        html.classList.add('dark');
        localStorage.setItem('theme', 'dark');
    }
}
// Form validation example
function validateLoginForm() {
    const username = document.getElementById('username').value;
    const password = document.getElementById('password').value;
    
    if (!username || !password) {
        showAlert('Please fill in all fields', 'error');
        return false;
    }
    
    // Hardcoded admin credentials
    if (username === 'admin' && password === 'admin123') {
        showAlert('Login successful!', 'success');
        // Redirect to dashboard after successful login
        setTimeout(() => {
            window.location.href = 'dashboard.html';
        }, 1000);
        return true;
    } else {
        showAlert('Invalid username or password', 'error');
        return false;
    }
}
function showAlert(message, type) {
    const alertDiv = document.createElement('div');
    alertDiv.className = `alert alert-${type} fixed top-4 right-4 z-50`;
    alertDiv.innerHTML = `
        <span class="block sm:inline">${message}</span>
        <span class="absolute top-0 bottom-0 right-0 px-4 py-3 cursor-pointer" onclick="this.parentElement.remove()">
            <i data-feather="x"></i>
        </span>
    `;
    document.body.appendChild(alertDiv);
    feather.replace();
    
    setTimeout(() => {
        alertDiv.remove();
    }, 5000);
}
// Simulate API calls
async function fetchPatients() {
    try {
        // In a real app, this would be a fetch to your backend API
        const response = await fetch('https://jsonplaceholder.typicode.com/users');
        const data = await response.json();
        return data.slice(0, 5); // Return first 5 as sample patient data
    } catch (error) {
        console.error('Error fetching patients:', error);
        return [];
    }
}

// Check if user is logged in when accessing dashboard
function checkAuth() {
    if (window.location.pathname.includes('dashboard.html') && !localStorage.getItem('loggedIn')) {
        window.location.href = 'login.html';
    }
}

// Run auth check when page loads
document.addEventListener('DOMContentLoaded', checkAuth);