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

const RootStack = createStackNavigator();

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;
