import React from 'react';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import AuthStack from './auth-navigator';
import AppStack from './app-navigator';
import {useSelector} from 'react-redux';

const RootStack = createNativeStackNavigator();

const RootStackScreen = ({userToken}) => {
  return (
    <RootStack.Navigator screenOptions={{headerShown: false}}>
      <RootStack.Screen name="Unauthorized" component={AuthStack} />
      {/* {userToken ? (
        <RootStack.Screen name="App" component={AppStack} />
      ) : (
        <RootStack.Screen name="Unauthorized" component={AuthStack} />
      )} */}
    </RootStack.Navigator>
  );
};

const RootNavigator = () => {
  const userToken = useSelector(state => state.auth.userToken);
  return (
    <NavigationContainer>
      <RootStackScreen userToken={userToken} />
    </NavigationContainer>
  );
};

export default RootNavigator;
