// src/navigation/WebContentNavigator.tsx
import React from 'react';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { useTheme } from 'react-native-paper';

import DashboardScreen from '../screens/DashboardScreen';
import ChatScreen from '../screens/ChatScreen';
import CalendarScreen from '../screens/CalendarScreen';
import ProfileScreen from '../screens/ProfileScreen';
import EventFormScreen from '../screens/EventFormScreen';
import AdminScreen from '../screens/AdminScreen'; // Import AdminScreen
import { useAuth, UserRole } from '../contexts/AuthContext'; // Import useAuth and UserRole

import { WebContentStackParamList } from '../types/navigation';

const Stack = createNativeStackNavigator<WebContentStackParamList>();

const WebContentNavigator = () => {
  const theme = useTheme();
  const { user } = useAuth(); // Get user data
  const isAdmin = user?.role === UserRole.ADMIN;

  return (
    <Stack.Navigator
      initialRouteName="Dashboard"
      screenOptions={{
        headerStyle: {
          backgroundColor: theme.colors.surface,
        },
        headerTintColor: theme.colors.onSurface, // Use onSurface instead of text
        headerTitleStyle: {
          fontWeight: 'bold',
        },
        contentStyle: {
          backgroundColor: theme.colors.background,
        },
        // Keep headers visible within the content area
        headerShown: true,
      }}
    >
      <Stack.Screen name="Dashboard" component={DashboardScreen} options={{ title: 'MAIA Dashboard' }}/>
      <Stack.Screen name="Chat" component={ChatScreen} options={{ title: 'MAIA Chat' }}/>
      <Stack.Screen name="Calendar" component={CalendarScreen} />
      <Stack.Screen name="Profile" component={ProfileScreen} />
      <Stack.Screen name="EventForm" component={EventFormScreen} />
      {/* Conditionally add Admin screen */}
      {isAdmin && (
        <Stack.Screen name="Admin" component={AdminScreen} options={{ title: 'Admin Controls' }}/>
      )}
    </Stack.Navigator>
  );
};

export default WebContentNavigator;