import React, { Component } from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import PI from "./src/PI";
import ThankYou from "./src/Screens/ThankYou";
import Header from "./src/Screens/Header";
import DocumentUpload from "./src/common/DocumentUpload";
import { Provider as PaperProvider, DefaultTheme } from "react-native-paper";
import { navigationRef } from "./src/common/RootNavigation";
import { StatusBar } from "react-native";
import { Provider } from "react-redux";
import store from "./src/redux/store";
import Progress from "./src/Screens/Progress";
// import Tutorial from "./src/Screens/Tutorial";
import Camera from "./src/Screens/Camera";
import PreviewImage from "./src/Screens/PreviewImage";
import Orientation from "../../node_modules/react-native-orientation";
import Toturial from "./src/Screens/Toturial";
import InvalidImages from "./src/Screens/InvalidImages";
import Geolocation from "react-native-geolocation-service";
import { Alert, Platform, StyleSheet } from "react-native";
import Colors from "react-native-digitcamera/src/common/Colors";
// Localization
const { setI18nConfig, translate } = require("./src/common/localize/i18n");

import * as RNLocalize from "react-native-localize";
import WithQuote from "./src/Screens/WithQuote";
import WithoutQuoteScreen from "./src/Screens/WithoutQuoteScreen";
import { SELFSURVEYSERVICE_DOCUMENT_URL } from "./src/Api/ApiUrls";
import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
const iOS = Platform.OS === "ios";

class App extends Component {
  constructor(props) {
    super(props);
    setI18nConfig();
  }
  componentDidMount() {
    this.setState();
    // this.test()
    Orientation.lockToPortrait();
    RNLocalize.addEventListener("change", this.handleLocalizationChange);
  }
  componentWillUnmount() {
    RNLocalize.removeEventListener("change", this.handleLocalizationChange);
  }
  handleLocalizationChange = () => {
    this.forceUpdate();
    setI18nConfig();
  };
  render() {
    const Stack = createStackNavigator();
    return (
      <SafeAreaProvider>
        <SafeAreaView
          edges={iOS ? ["top", "bottom"] : []}
          style={styles.safeArea}
        >
          <StatusBar backgroundColor={"white"} barStyle={"dark-content"} />
          <NavigationContainer
            ref={navigationRef}
            theme={DefaultTheme}
            independent={true}
          >
            <PaperProvider theme={DefaultTheme}>
              <Provider store={store}>
                <Stack.Navigator
                  screenOptions={{ headerShown: false, gestureEnabled: false }}
                >
                  {this.props.toWithQuote == true && (
                    <Stack.Screen
                      name="WithQuote"
                      component={WithQuote}
                      initialParams={this.props}
                    />
                  )}
                  <Stack.Screen
                    name="Toturial"
                    component={Toturial}
                    initialParams={this.props}
                  />
                  <Stack.Screen
                    name="WithoutQuoteScreen"
                    component={WithoutQuoteScreen}
                    initialParams={this.props}
                  />
                  <Stack.Screen
                    name="PI"
                    component={PI}
                    initialParams={this.props}
                  />
                  <Stack.Screen
                    name="Progress"
                    component={Progress}
                    initialParams={this.props}
                  />
                  <Stack.Screen
                    name="ThankYou"
                    component={ThankYou}
                    initialParams={this.props}
                  />
                  <Stack.Screen
                    name="InvalidImages"
                    component={InvalidImages}
                  />
                  <Stack.Screen
                    name="Camera"
                    component={Camera}
                    options={{ gestureEnabled: false }}
                  />
                  <Stack.Screen
                    name="PreviewImage"
                    component={PreviewImage}
                    initialParams={this.props}
                  />
                </Stack.Navigator>
              </Provider>
            </PaperProvider>
          </NavigationContainer>
        </SafeAreaView>
      </SafeAreaProvider>
    );
  }
}

const styles = StyleSheet.create({
  safeArea: {
    flex: 1,
    backgroundColor: Colors.white,
  },
});

export default App;
