// Shared utility functions const formatDate = (dateString) => { const options = { year: 'numeric', month: 'short', day: 'numeric' }; return new Date(dateString).toLocaleDateString(undefined, options); }; const calculateProgress = (current, target) => { return Math.min(Math.round((current / target) * 100), 100); }; // Auth state management let currentUser = null; const setCurrentUser = (user) => { currentUser = user; localStorage.setItem('currentUser', JSON.stringify(user)); updateUIForUserRole(); }; const getCurrentUser = () => { if (!currentUser && localStorage.getItem('currentUser')) { currentUser = JSON.parse(localStorage.getItem('currentUser')); } return currentUser; }; const logout = () => { currentUser = null; localStorage.removeItem('currentUser'); window.location.href = '/'; }; const updateUIForUserRole = () => { const user = getCurrentUser(); if (!user) return; // Show/hide elements based on role document.querySelectorAll('[data-role="admin"]').forEach(el => { el.style.display = user.role === 'admin' ? 'block' : 'none'; }); document.querySelectorAll('[data-role="manager"]').forEach(el => { el.style.display = user.role === 'manager' ? 'block' : 'none'; }); document.querySelectorAll('[data-role="employee"]').forEach(el => { el.style.display = user.role === 'employee' ? 'block' : 'none'; }); }; // Initialize app when DOM is loaded document.addEventListener('DOMContentLoaded', () => { updateUIForUserRole(); });