import React, { Component } from 'react'
import { bindActionCreators } from 'redux'
import {appSetDevice, appSetPushToken, appSetToken, appSetUser} from '../../redux/app/action'
import { connect } from 'react-redux'
import { View } from 'react-native'
import { switchLanguage } from '../../utils/i18n'

class AppLoading extends Component {

  constructor (props) {
    super(props)
    if (props.lang) {
      switchLanguage(props.lang)
      this.props.navigation.navigate('HomeScreen')
    } else {
      this.props.navigation.navigate('LanguageSelect')
    }
  }

  render () {
    return (<View></View>)
  }
}

const mapStateToProps = state => {
  return {
    lang: state.app.lang,
    user: state.app.user
  }
}
const setUser = dispatch => bindActionCreators({ appSetToken, appSetPushToken, appSetDevice, appSetUser }, dispatch)
export default connect(mapStateToProps, setUser)(AppLoading)
