// Layout Manager - Maneja el layout común de las páginas const LayoutManager = { config: { title: '', flag: '', country: '', user: '' }, // Inicializar layout init: function(config) { this.config = { ...this.config, ...config }; this.renderNavbar(); this.renderFooter(); this.updateHeader(); this.setupEventListeners(); this.startClock(); this.protectPage(); }, // Renderizar navbar renderNavbar: function() { const navbarHTML = ` `; const navbarContainer = document.getElementById('navbar'); if (navbarContainer) { navbarContainer.outerHTML = navbarHTML; } else { document.body.insertAdjacentHTML('afterbegin', navbarHTML); } this.updateNavbar(); }, // Renderizar footer renderFooter: function() { const footerHTML = ` `; const footerContainer = document.getElementById('footer'); if (footerContainer) { footerContainer.outerHTML = footerHTML; } else { document.body.insertAdjacentHTML('beforeend', footerHTML); } }, // Proteger página (require autenticación) protectPage: async function() { const sesionActiva = await authManager.protegerPagina(); if (sesionActiva) { const usuario = authManager.obtenerUsuario(); document.getElementById('nombreUsuario').textContent = usuario; } }, // Actualizar navbar con país activo updateNavbar: function() { const navLinks = document.querySelectorAll('.nav-link'); navLinks.forEach(link => { const country = link.dataset.country; if (country === this.config.country) { link.classList.remove('hover:bg-indigo-700'); link.classList.add('bg-indigo-700'); } else { link.classList.remove('bg-indigo-700'); link.classList.add('hover:bg-indigo-700'); } }); }, // Actualizar header updateHeader: function() { const flagElement = document.getElementById('country-flag'); const titleElement = document.getElementById('page-title'); if (flagElement) flagElement.textContent = this.config.flag; if (titleElement) titleElement.textContent = this.config.title; }, // Configurar event listeners setupEventListeners: function() { // Logout desktop const logoutBtn = document.getElementById('logoutBtn'); if (logoutBtn) { logoutBtn.addEventListener('click', () => { authManager.cerrarSesion(); }); } // Logout mobile const logoutBtnMobile = document.getElementById('logoutBtnMobile'); if (logoutBtnMobile) { logoutBtnMobile.addEventListener('click', () => { authManager.cerrarSesion(); }); } // Mobile menu toggle const mobileMenuBtn = document.getElementById('mobileMenuBtn'); const mobileMenu = document.getElementById('mobileMenu'); const menuIcon = document.getElementById('menuIcon'); const closeIcon = document.getElementById('closeIcon'); if (mobileMenuBtn && mobileMenu) { mobileMenuBtn.addEventListener('click', () => { const isHidden = mobileMenu.classList.contains('hidden'); if (isHidden) { mobileMenu.classList.remove('hidden'); menuIcon.classList.add('hidden'); closeIcon.classList.remove('hidden'); } else { mobileMenu.classList.add('hidden'); menuIcon.classList.remove('hidden'); closeIcon.classList.add('hidden'); } }); // Cerrar menú al hacer click en un link const mobileLinks = mobileMenu.querySelectorAll('a'); mobileLinks.forEach(link => { link.addEventListener('click', () => { mobileMenu.classList.add('hidden'); menuIcon.classList.remove('hidden'); closeIcon.classList.add('hidden'); }); }); } }, // Mostrar loading showLoading: function() { const spinner = document.getElementById('loadingSpinner'); const content = document.getElementById('pageContent'); if (spinner) spinner.classList.remove('hidden'); if (content) content.classList.add('hidden'); }, // Ocultar loading hideLoading: function() { const spinner = document.getElementById('loadingSpinner'); const content = document.getElementById('pageContent'); if (spinner) spinner.classList.add('hidden'); if (content) content.classList.remove('hidden'); }, // Insertar contenido en el área principal insertContent: function(html) { const content = document.getElementById('pageContent'); if (content) { content.innerHTML = html; content.classList.remove('hidden'); } }, // Actualizar timestamp de última actualización updateLastUpdate: function() { const lastUpdate = document.getElementById('lastUpdate'); if (lastUpdate) { const now = new Date(); lastUpdate.textContent = now.toLocaleTimeString('es-AR'); } }, // Reloj en el footer startClock: function() { const updateTime = () => { const currentTime = document.getElementById('currentTime'); if (currentTime) { const now = new Date(); currentTime.textContent = now.toLocaleTimeString('es-AR'); } }; updateTime(); setInterval(updateTime, 1000); }, // Mostrar notificación toast showToast: function(message, type = 'info') { const colors = { success: 'bg-green-500', error: 'bg-red-500', warning: 'bg-yellow-500', info: 'bg-blue-500' }; const toast = document.createElement('div'); toast.className = `fixed bottom-4 right-4 ${colors[type]} text-white px-6 py-3 rounded-lg shadow-lg z-50 animate-fade-in`; toast.textContent = message; document.body.appendChild(toast); setTimeout(() => { toast.classList.add('animate-fade-out'); setTimeout(() => toast.remove(), 300); }, 3000); } }; // Exportar para uso global window.LayoutManager = LayoutManager;