import React from 'react'; import { TouchableOpacity, View, Text } from 'react-native'; import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { DrawerNavigationProp } from '@react-navigation/drawer'; import Icon from 'react-native-vector-icons/Ionicons'; import { route, RouteParams } from '@utils'; import { DashboardScreen, AddLeadScreen, ProfileScreen, NotificationScreen, } from '@features'; import { LeadsStack } from './leadsStack'; import { CustomersStack } from './customersStack'; import { useTheme } from '@theme'; import { useAppSelector, RootState } from '@store'; import { getStyles } from './tabStack.styles'; export type TabStackParamList = Pick< RouteParams, 'dashboard' | 'leads' | 'addLead' | 'customers' | 'profile' >; const Tab = createBottomTabNavigator(); const DashboardStackNav = createNativeStackNavigator(); const DashboardStack = () => { const { theme: colors } = useTheme(); const styles = getStyles(colors); const userData = useAppSelector((state: RootState) => state.auth.user_data); const { items: notificationItems, hasFetched } = useAppSelector((state: RootState) => state.notifications); // Calculate unread count from actual items if they've been fetched, otherwise fallback to userData's initial count const unreadCount = hasFetched ? notificationItems.filter(n => String(n.isread) === '0').length : parseInt(userData?.total_unread_notifications ?? '0', 10); return ( ({ headerTitle: 'Convex CRM', headerLeft: () => ( { const parentNav = navigation.getParent>(); if (parentNav) { parentNav.openDrawer(); } else { (navigation as any).openDrawer?.(); } }}> ), headerRight: () => ( { // Navigate to notification screen if exists, or profile/other suitable route navigation.navigate(route.notifications); }}> {unreadCount > 0 ? ( {unreadCount > 99 ? '99+' : unreadCount} ) : null} ), })} /> ); }; const AddLeadStackNav = createNativeStackNavigator(); const AddLeadStack = () => { const { theme: colors } = useTheme(); const styles = getStyles(colors); return ( ({ headerTitle: 'Add Lead', headerLeft: () => ( { const parentNav = navigation.getParent>(); if (parentNav) { parentNav.openDrawer(); } else { (navigation as any).openDrawer?.(); } }}> ), })} /> ); }; const ProfileStackNav = createNativeStackNavigator(); const ProfileStack = () => { const { theme: colors } = useTheme(); const styles = getStyles(colors); return ( ({ headerTitle: 'Profile', headerLeft: () => ( { const parentNav = navigation.getParent>(); if (parentNav) { parentNav.openDrawer(); } else { (navigation as any).openDrawer?.(); } }}> ), })} /> ); }; export const TabStack = () => { const { theme: colors } = useTheme(); const styles = getStyles(colors); return ( ({ tabBarIcon: ({ focused, color }) => { if (tabRoute.name === route.addLead) { return ( ); } let iconName = 'square'; if (tabRoute.name === route.dashboard) { iconName = focused ? 'grid' : 'grid-outline'; } else if (tabRoute.name === route.leads) { iconName = focused ? 'funnel' : 'funnel-outline'; } else if (tabRoute.name === route.customers) { iconName = focused ? 'people' : 'people-outline'; } else if (tabRoute.name === route.profile) { iconName = focused ? 'person' : 'person-outline'; } return ( ); }, tabBarActiveTintColor: colors.icon, tabBarInactiveTintColor: colors.textMuted, tabBarStyle: styles.tabBar, tabBarLabelStyle: styles.tabBarLabel, headerShown: false, })}> ); };