import { StatusBar } from 'expo-status-bar';
import React, { useEffect } from 'react';
import { Platform } from 'react-native';
import * as NavigationBar from 'expo-navigation-bar';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { SessionProvider } from './src/auth/session';
import { getDb } from './src/db/database';
import { RootNavigator } from './src/navigation';

export default function App() {
  // Abre y migra la BD local al arrancar.
  useEffect(() => {
    void getDb();

    // Configuración global de la barra de navegación en Android (Edge-to-Edge)
    if (Platform.OS === 'android') {
      void NavigationBar.setPositionAsync('absolute');
      void NavigationBar.setBackgroundColorAsync('#ffffff00'); // Transparente
      void NavigationBar.setButtonStyleAsync('dark'); // Iconos oscuros por defecto
    }
  }, []);

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