/** * Main Entry Point - ES6 Modules * Initializes the application with modular architecture */ // Core imports import { loadPreferences } from './core/storage.js'; import { applyUserPreferences } from './ui/theme.js'; import { showSection } from './ui/navigation.js'; // UI imports import './ui/mobile-menu.js'; import './ui/csv-manager-ui.js'; /** * Initialize application */ async function initializeApp() { console.log('🚀 SteelBase v7.5 - Inicializando (Modular)...'); try { // 1. Load user preferences loadPreferences(); // 2. Apply preferences (theme, colors, fonts) applyUserPreferences(); // 3. Load initial section await showSection('cev'); // 4. Initialize optional functions safely initializeOptionalFeatures(); // 5. Apply admin config if (typeof window.applyAdminConfig === 'function') { window.applyAdminConfig(); } // 6. Filter tools by mode if (typeof window.filterToolsByMode === 'function') { window.filterToolsByMode(); } console.log('✅ Aplicativo inicializado com sucesso (Modular)!'); } catch (error) { console.error('❌ Erro na inicialização:', error); } finally { // Remove loading screen removeLoadingScreen(); } } /** * Initialize optional features that may not exist */ function initializeOptionalFeatures() { const optionalFunctions = [ 'mostrarEquivalencias', 'gerarChecklistCertificado', 'updatePaintFields', 'updateWeightFields' ]; optionalFunctions.forEach(funcName => { if (typeof window[funcName] === 'function') { try { window[funcName](); } catch (error) { console.warn(`⚠️ Erro ao inicializar ${funcName}:`, error); } } }); } /** * Remove loading screen with animation */ function removeLoadingScreen() { setTimeout(() => { const loadingScreen = document.getElementById('app-loading'); if (loadingScreen) { loadingScreen.style.opacity = '0'; loadingScreen.style.transition = 'opacity 0.3s ease'; setTimeout(() => loadingScreen.remove(), 300); } }, 500); } /** * Setup event listeners */ function setupEventListeners() { // Budget observer const observer = new MutationObserver(() => { if (window.appState && window.appState.currentSection === 'orcamento') { if (typeof window.initializeBudget === 'function') { setTimeout(window.initializeBudget, 100); } } }); // Removido: adminModal legado } // Initialize when DOM is ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { initializeApp(); setupEventListeners(); }); } else { initializeApp(); setupEventListeners(); } // Export for debugging if (typeof window !== 'undefined') { window.__appModules = { version: '7.5.0', modular: true, initialized: true }; }