import { useContext } from 'react'
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { AuthContext } from '../login/AuthContext';
import { ProductFormScreen } from './ProductFormScreen';
import { ProductListScreen } from './ProductListScreen';

export type RootStackParams = {
    ProductListScreen: undefined,
    ProductFormScreen: { id: number }
}
const Stack = createNativeStackNavigator<RootStackParams>();

export const ProductStack = () => {
    const { isAuthenticated } = useContext(AuthContext)

    return (
        <Stack.Navigator
            screenOptions={{
                headerShown: true,
            }}
        >
            {isAuthenticated && (
                <>
                    <Stack.Screen name="ProductListScreen" component={ProductListScreen} />
                    <Stack.Screen name="ProductFormScreen" component={ProductFormScreen} />
                </>
            )}
        </Stack.Navigator>
    )
}