import React,{useState,useEffect} from 'react';
import {StatusBar} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
// import {PrimaryTheme} from '../../styles/Themes';
import { GetPageTheme } from "../../styles/Global";
import { AuthStack } from './Routes';
import { connect } from 'react-redux';
import { mapStateToProps,mapDispatchToProps } from '../../reducers/contextProvider';
import {get_item,set_item,clear_item} from '../../components/localStorage';
import { LogBox } from 'react-native';
import NetInfo from "@react-native-community/netinfo";

LogBox.ignoreLogs(['new NativeEventEmitter']); // Ignore log notification by message
LogBox.ignoreAllLogs(); //Ignore all log notifications
LogBox.ignoreLogs([
    "[react-native-gesture-handler] Seems like you\'re using an old API with gesture components, check out new Gestures system!",
]);
const Navigator = (props)=>{
    const PageTheme=GetPageTheme(false,'');
    const {DarkMode}=props;
    const [state, setState] = useState({});
    
    useEffect(() => {   
        
        const unsubscribe = NetInfo.addEventListener(state => {
            
            // console.log("Is connected?", state.isConnected);
           
            var isAlreadyConnected=props.isInternetAvailable==true
            // console.log("check if already connected ",isAlreadyConnected);
            if(isAlreadyConnected==false || (isAlreadyConnected!=state.isConnected)){
                props.show_ConnChange({showConnChange:true})
            }
            props.set_networkStatus({isInternetAvailable:state.isConnected});
            
            
        });

        return ()=>{
            unsubscribe();
        }
    }, []);

    
    
   return (   
    <NavigationContainer>
        <StatusBar barStyle={"dark-content"} backgroundColor={PageTheme.$status_bar_color} />
        <AuthStack {...props}/>
    </NavigationContainer>
   )

    
};


  
export default connect(mapStateToProps, mapDispatchToProps)(Navigator)