// Main entry point for Calendar Plantempus import { eventBus } from './core/EventBus'; import { calendarConfig } from './core/CalendarConfig'; import { CalendarTypeFactory } from './factories/CalendarTypeFactory'; import { ManagerFactory } from './factories/ManagerFactory'; import { URLManager } from './utils/URLManager'; import { CalendarManagers } from './types/ManagerTypes'; /** * Handle deep linking functionality after managers are initialized */ async function handleDeepLinking(managers: CalendarManagers): Promise { try { const urlManager = new URLManager(eventBus); const eventId = urlManager.parseEventIdFromURL(); if (eventId) { console.log(`Deep linking to event ID: ${eventId}`); // Wait a bit for managers to be fully ready setTimeout(() => { const success = managers.eventManager.navigateToEvent(eventId); if (!success) { console.warn(`Deep linking failed: Event with ID ${eventId} not found`); } }, 500); } } catch (error) { console.warn('Deep linking failed:', error); } } /** * Initialize the calendar application with simple direct calls */ async function initializeCalendar(): Promise { try { // Use the singleton calendar configuration const config = calendarConfig; // Initialize the CalendarTypeFactory before creating managers CalendarTypeFactory.initialize(); // Create managers using factory pattern const managerFactory = ManagerFactory.getInstance(); const managers = managerFactory.createManagers(eventBus); // Enable debug mode for development eventBus.setDebug(true); // Initialize all managers await managerFactory.initializeManagers(managers); // Handle deep linking after managers are initialized await handleDeepLinking(managers); // Expose to window for debugging (with proper typing) (window as Window & { calendarDebug?: { eventBus: typeof eventBus; } & CalendarManagers; }).calendarDebug = { eventBus, ...managers }; } catch (error) { throw error; } } // Initialize when DOM is ready - now handles async properly if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { initializeCalendar().catch(error => { }); }); } else { initializeCalendar().catch(error => { }); }