import React, { useEffect } from 'react';
import { StatusBar } from 'expo-status-bar';
import { NavigationContainer } from '@react-navigation/native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { useAuthStore } from '@/store/authStore';
import { AuthNavigator } from '@/navigation/AuthNavigator';
import { MainTabNavigator } from '@/navigation/MainTabNavigator';
import { usePushNotifications } from '@/hooks';
import '@/services/api';

export default function App() {
  const { isAuthenticated } = useAuthStore();
  const { registerForPushNotifications } = usePushNotifications();

  useEffect(() => {
    if (isAuthenticated) {
      registerForPushNotifications();
    }
  }, [isAuthenticated, registerForPushNotifications]);

  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <NavigationContainer>
        <StatusBar style="light" />
        {isAuthenticated ? <MainTabNavigator /> : <AuthNavigator />}
      </NavigationContainer>
    </GestureHandlerRootView>
  );
}
