import React, { useEffect } from 'react';
import { StatusBar } from 'expo-status-bar';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { AuthProvider } from '@/auth/AuthContext';
import { ThemeProvider } from '@/theme/ThemeContext';
import { RootNavigator } from '@/navigation/RootNavigator';
import { ps } from '@/api/client';
import { initFileLogging } from '@/features/diagnostics/fileLogger';

export default function App() {
  // Restore the file-logging preference; if on, also turn on request logging.
  useEffect(() => {
    void initFileLogging().then((on) => {
      if (on) ps.setLogRequests(true);
    });
  }, []);

  return (
    <SafeAreaProvider>
      <ThemeProvider>
        <AuthProvider>
          <RootNavigator />
          <StatusBar style="auto" />
        </AuthProvider>
      </ThemeProvider>
    </SafeAreaProvider>
  );
}
