/**
 * Force Global Module Initialization Test
 * Run this to manually trigger global module setup
 */

window.testForceGlobals = async function() {
    console.log('🔧 Force initializing global modules...');

    try {
        // Check if app exists
        if (!window.app) {
            console.error('❌ window.app not found');
            return false;
        }

        // Check app status
        const status = window.app.getStatus();
        console.log('📱 App status:', status);

        if (!status.isRunning) {
            console.error('❌ App not running, isRunning:', status.isRunning);
            return false;
        }

        // Get module loader
        const moduleLoader = window.app.getCore().moduleLoader;
        console.log('📦 ModuleLoader:', !!moduleLoader);

        // Check orchestrator
        const orchestrator = moduleLoader.getModule('smartPreviewOrchestrator');
        console.log('🎭 Orchestrator:', !!orchestrator);

        if (!orchestrator) {
            console.error('❌ SmartPreviewOrchestrator not found');
            return false;
        }

        // Check orchestrator initialization
        const isInitialized = orchestrator._isInitialized;
        console.log('🔄 Orchestrator initialized:', isInitialized);

        // Check shared services
        console.log('🔗 Checking sharedServices...');
        const sharedServices = orchestrator.sharedServices;
        console.log('📋 SharedServices:', sharedServices);

        if (!sharedServices) {
            console.error('❌ SharedServices not available');
            return false;
        }

        // Set global variables manually
        console.log('🌐 Setting global variables...');
        window.unifiedDRS = moduleLoader.getModule('unifiedDRS');
        window.iaEngine = sharedServices.llmValidator;
        window.llmValidator = sharedServices.llmValidator;
        window.prerequisiteEngine = sharedServices.prerequisiteEngine;

        console.log('✅ Global variables set:');
        console.log('  - contentLoader:', !!window.contentLoader);
        console.log('  - unifiedDRS:', !!window.unifiedDRS);
        console.log('  - iaEngine:', !!window.iaEngine);
        console.log('  - llmValidator:', !!window.llmValidator);
        console.log('  - prerequisiteEngine:', !!window.prerequisiteEngine);

        return true;

    } catch (error) {
        console.error('❌ Error in force globals:', error);
        return false;
    }
};

console.log('🔧 Force globals test loaded. Run: testForceGlobals()');