/**
 * @flow
 */

import React, { Component } from 'react';
import { AppState, Text, SafeAreaView } from 'react-native';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/es/integration/react';
import configureStore from './basicStore';
import BasicNavigator from './BasicNavigator';
import StyleSheet from './utils/StyleSheet';

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

const { store, persistor } = configureStore()

class MainApp extends Component {
  componentDidMount() {
    //if (AssetsModule.dismisToast) {
    //  AssetsModule.dismisToast()
    //}

    AppState.addEventListener('change', this.handleAppChange);
  }

  componentWillUnmount() {
    AppState.removeEventListener('change', this.handleAppChange);
    //if (AssetsModule.dismisToast) {
    //  AssetsModule.dismisToast()
    //}
  }

  handleAppChange = (currentAppState : string) => {
    //console.log('handleAppChange:')
    if (currentAppState === 'active') {
      //checkForUpdate(true)
    }
  }


  render() {
    return (
      <Provider store={store}>
        <PersistGate loading={<Text>Loading...</Text>} persistor={persistor}>
          <SafeAreaView style={styles.container}>
            <BasicNavigator param={this.props} />
          </SafeAreaView>
        </PersistGate>
      </Provider>
    );
  }
}

export default MainApp;
