import React, { useEffect } from 'react';
import { StatusBar } from 'expo-status-bar';
import * as SplashScreen from 'expo-splash-screen';
import * as Font from 'expo-font';
{{#if includeNavigator}}
import { NavigationContainer } from '@react-navigation/native';
import AppNavigator from './src/navigation/AppNavigator';
{{else}}
import HomeScreen from './src/screens/HomeScreen';
{{/if}}
{{#if includeAuth}}
import { AuthProvider } from './src/auth/AuthContext';
{{/if}}

// Keep the splash screen visible while we fetch resources
SplashScreen.preventAutoHideAsync();

export default function App() {
  const [isLoadingComplete, setLoadingComplete] = React.useState(false);

  // Load any resources or data that we need prior to rendering the app
  useEffect(() => {
    async function loadResourcesAndDataAsync() {
      try {
        // Load fonts
        await Font.loadAsync({
          // Load custom fonts here
        });
      } catch (e) {
        // We might want to provide this error information to an error reporting service
        console.warn(e);
      } finally {
        setLoadingComplete(true);
        SplashScreen.hideAsync();
      }
    }

    loadResourcesAndDataAsync();
  }, []);

  if (!isLoadingComplete) {
    return null;
  }

  return (
    <>
      {{#if includeAuth}}
      <AuthProvider>
      {{/if}}
        {{#if includeNavigator}}
        <NavigationContainer>
          <AppNavigator />
        </NavigationContainer>
        {{else}}
        <HomeScreen />
        {{/if}}
        <StatusBar style="auto" />
      {{#if includeAuth}}
      </AuthProvider>
      {{/if}}
    </>
  );
}