import React, { useEffect } from 'react';
import { Platform, StyleSheet, View } from 'react-native';
import Navigator from '../utils/navigations/Navigator';
import { Provider } from 'react-redux';
import store from '../store/configureStore';
import requestUserPermission from '../pushNotification';
import messaging from '@react-native-firebase/messaging';
import crashlytics from '@react-native-firebase/crashlytics';
import { gMap_key, Production } from '../constants/constants';
import Geocoder from 'react-native-geocoding';
import { VisionCameraProxy } from 'react-native-vision-camera';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { enableScreens } from 'react-native-screens';
enableScreens();

// ✅ Initialize Google Maps API
Geocoder.init(gMap_key);
const App = () => {
  if (!__DEV__) {
    console.log = () => { };
  }
  useEffect(() => {
    console.log(
      'Hermes:',
      !!global.HermesInternal,
      'FrameProcessors:',
      VisionCameraProxy?.setFrameProcessor != null
    );

    if (Platform.OS === 'android') {
      console.log('requestUserPermission-----');
      requestUserPermission('android');
    } else if (Platform.OS === 'ios') {
      requestUserPermission('ios');
    }
    // 🚫 Temporarily disable crashlytics if not imported
    if (Production) {
      crashlytics().setCrashlyticsCollectionEnabled(true);
    }
  }, []);
  // 🚫 Disable messaging block if not using Firebase
  useEffect(() => {
    messaging().onMessage(async remoteMessage => {
      console.log("📩 App Opened from Background:", remoteMessage);
    });
    messaging().onNotificationOpenedApp(remoteMessage => {
      console.log("📩 App Opened from Background:", remoteMessage);
    });
    messaging().getInitialNotification().then(remoteMessage => {
      if (remoteMessage) {
        console.log("📩 App Opened from Quit State:", remoteMessage);
      }
    });
    messaging().setBackgroundMessageHandler(async remoteMessage => {
      console.log("📩 Background Notification Received:", remoteMessage);
    });
  }, []);

  return (
    <View style={styles.rootFix}>
      <SafeAreaProvider>
        <Provider store={store}>
          <Navigator />
        </Provider>
      </SafeAreaProvider>
    </View>

  );
};

export default App;

const styles = StyleSheet.create({
  rootFix: {
    flex: 1,
    elevation: 1,              // forces Android to keep this as hardware layer
    zIndex: 1,
  },
});
