import React from 'react';
import { createStackNavigator } from '@react-navigation/stack';
import { useSelector } from 'react-redux';
import type { RootState } from '@/store/store';
import CrmDashboardScreen from '@/modules/crm/zoho/screens/CrmDashboardScreen';
import ZohoCrmDataScreen from '@/modules/crm/zoho/screens/ZohoCrmDataScreen';
import SalesforceCrmDashboardScreen from '@/modules/crm/salesforce/screens/SalesforceCrmDashboardScreen';
import SalesforceDataScreen from '@/modules/crm/salesforce/screens/SalesforceDataScreen';

const Stack = createStackNavigator();

const CrmNavigator = () => {
  // Get the selected service from Redux to determine initial screen
  const selectedService = useSelector((state: RootState) => state.integrations.selectedService);
  
  // Determine initial route based on selected CRM service
  const initialRouteName = selectedService === 'salesforce' ? 'SalesforceDashboard' : 'CrmDashboard';
  
  return (
    <Stack.Navigator initialRouteName={initialRouteName}>
      <Stack.Screen name="CrmDashboard" component={CrmDashboardScreen} options={{headerShown:false}} />
      <Stack.Screen name="ZohoCrmData" component={ZohoCrmDataScreen} options={{headerShown:false}} />
      <Stack.Screen name="SalesforceDashboard" component={SalesforceCrmDashboardScreen} options={{headerShown:false}} />
      <Stack.Screen name="SalesforceData" component={SalesforceDataScreen} options={{headerShown:false}} />
    </Stack.Navigator>
  );
};

export default CrmNavigator;


