import React, {useEffect} from 'react';
import {LogBox, StyleSheet} from 'react-native';
import {AuthProvider} from './context/authContext';
import {BluetoothProvider} from './context/bluetoothContext';
import {ChatProvider} from './context/chatContext';
import {SocialProvider} from './context/socialContext';
import InitialSettings from './InitialSettings';
import OneSignal from 'react-native-onesignal';
import MapboxGL from '@rnmapbox/maps';

import {MAPBOX_ACCES_TOKEN, ONESIGNAL_TOKEN} from '@env';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import * as Sentry from '@sentry/react-native';
import {enableFreeze} from 'react-native-screens';

// mapbox acces token
MapboxGL.setWellKnownTileServer(MapboxGL.TileServers.Mapbox);
MapboxGL.setAccessToken(MAPBOX_ACCES_TOKEN);

//OneSignal Init Code
OneSignal.setLogLevel(6, 0);
OneSignal.setAppId(ONESIGNAL_TOKEN);
//END OneSignal Init Code

LogBox.ignoreLogs(['new NativeEventEmitter']);
// LogBox.ignoreAllLogs(); //Ignore all log notifications
// LogBox.ignoreLogs([
//   '`new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.',
// ]);

const App = () => {
  useEffect(() => {
    // will disable re-rendering for inactive screens, thus improving performance
    // this call will make freezeOnBlur to be true by default for all the screens
    enableFreeze();
  }, []);

  return (
    <GestureHandlerRootView style={styles.container}>
      <AuthProvider>
        <BluetoothProvider>
          <SocialProvider>
            <ChatProvider>
              <InitialSettings />
            </ChatProvider>
          </SocialProvider>
        </BluetoothProvider>
      </AuthProvider>
    </GestureHandlerRootView>
  );
};

const styles = StyleSheet.create({
  container: {flex: 1},
});

export default Sentry.wrap(App);
