import React, { useEffect } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { ThemeProvider } from '@rneui/themed';
import { TasksProvider } from './src/context/TasksContext';
import AppNavigator from './src/navigation/AppNavigator';
import { clearCachedConfig } from './src/services/configService';

function App(): React.JSX.Element {
  // 检测新架构
  useEffect(() => {
    const globalAny = global as any;
    const isFabricEnabled = globalAny.nativeFabricUIManager != null;
    const isTurboModuleEnabled = globalAny.__turboModuleProxy != null;

    console.log('🏗️ 架构检测结果:');
    console.log(
      'Fabric (新渲染器):',
      isFabricEnabled ? '✅ 已启用' : '❌ 未启用',
    );
    console.log(
      'TurboModules (新模块系统):',
      isTurboModuleEnabled ? '✅ 已启用' : '❌ 未启用',
    );
    console.log(
      '新架构状态:',
      isFabricEnabled && isTurboModuleEnabled
        ? '🎉 完全启用'
        : '⚠️ 部分启用或未启用',
    );
  }, []);

  useEffect(() => {
    const clearCacheOnStart = async () => {
      try {
        await clearCachedConfig();
        console.log('配置缓存已清理');
      } catch (error) {
        console.error('清理配置缓存失败:', error);
      }
    };

    clearCacheOnStart();
  }, []);

  return (
    <ThemeProvider>
      <TasksProvider>
        <NavigationContainer>
          <AppNavigator />
        </NavigationContainer>
      </TasksProvider>
    </ThemeProvider>
  );
}

export default App;
