/**
 * Application Status Diagnostic Tool
 * Deep dive into app initialization issues
 */

window.testAppStatus = function() {
    console.log('🔍 Deep Application Status Check...');

    // 1. Check if window.app exists
    console.log('1. window.app exists:', !!window.app);
    if (!window.app) {
        console.error('❌ window.app is not defined');
        return false;
    }

    // 2. Check app properties
    console.log('2. window.app properties:', Object.keys(window.app));

    // 3. Check getStatus method
    console.log('3. getStatus method exists:', typeof window.app.getStatus);

    if (typeof window.app.getStatus !== 'function') {
        console.error('❌ getStatus is not a function');
        return false;
    }

    // 4. Try to call getStatus
    try {
        const status = window.app.getStatus();
        console.log('4. Status object:', status);

        if (!status) {
            console.error('❌ getStatus returned null/undefined');
            return false;
        }

        console.log('5. Status properties:', Object.keys(status));
        console.log('6. Status.status value:', status.status);

        // 7. Check if app thinks it's running
        console.log('7. App _isRunning:', window.app._isRunning);
        console.log('8. App _isInitialized:', window.app._isInitialized);

        return status;

    } catch (error) {
        console.error('❌ Error calling getStatus:', error);
        return false;
    }
};

window.testAppRestart = async function() {
    console.log('🔄 Attempting to restart application...');

    try {
        if (window.app && typeof window.app.start === 'function') {
            await window.app.start();
            console.log('✅ App start() called');
        } else {
            console.error('❌ App start method not available');
        }
    } catch (error) {
        console.error('❌ Error restarting app:', error);
    }
};

console.log('🔍 App status diagnostic loaded. Run: testAppStatus() or testAppRestart()');