/**
* STAR APP - React-Native STAR APP Starter(https://www.enappd.com)
*
* Copyright © 2019-present Enappd. All rights reserved.
*
* This source code is licensed as per the terms found in the
* LICENSE.md file in the root directory of this source .
*
*/
import React, { Component } from 'react';
import LoginView from './loginView';
import { NavigationStackScreenProps } from 'react-navigation-stack';




interface Iprops extends NavigationStackScreenProps {
    actions: any
}

interface Istates {
    phoneNumber: string,
    selectedCountry: string
}


class LoginContainer extends Component<Iprops, Istates> {

    state = {
        phoneNumber: '',
        selectedCountry: ''
    };

    onPhoneNumberChange = (phoneNumber: string) => this.setState({ phoneNumber })

    onCountrySelect = (selectedCountry: string) => this.setState({ selectedCountry })

    cancelSelect = () => {
        this.setState({ selectedCountry: '' })
    }

    skipLogin = () => {
        const { navigation } = this.props;
        navigation.navigate('AppLoad');
        console.log('skip is working')
    }

    gotoVerfiy = () => {
        const { navigation } = this.props;
        navigation.navigate('Verify');
    }

    render() {
        const {
            selectedCountry,
            phoneNumber
        } = this.state;
        const disableButton = !selectedCountry || phoneNumber.length < 10;
        return (
            <LoginView
                gotoVerfiy={this.gotoVerfiy}
                onPhoneNumberChange={this.onPhoneNumberChange}
                onCountrySelect={this.onCountrySelect}
                selectedCountry={selectedCountry}
                phoneNumber={phoneNumber}
                disableButton={disableButton}
                onPressToPage={this.skipLogin}
            />
        );
    }
}





export default LoginContainer;

