import React, {useState} from 'react';
import {
  View,
  Text,
  Image,
  TouchableOpacity,
  StyleSheet,
  Alert,
} from 'react-native';
import R from '../../../assets/R';

import TextField from '../../../components/Input/TextField';
import TextMulti from '../../../components/Input/TextMulti';
import PickerDate from '../../../components/Picker/PickerDate';
import PickerImg from '../../../components/Picker/PickerImg';

import {checkFormatArray} from '../../../Config/Functions';

const GeneralInfor = (props) => {
  const [email, setEmail] = useState('');
  const [sponsorID, setSponsorID] = useState('');
  const [lastName, setLastName] = useState('');
  const [firstName, setFirstName] = useState('');
  const [phone, setPhone] = useState('');
  const [adress, setAdress] = useState('');
  const [birth, setBirth] = useState(new Date());

  const onNextPress = () => {
    const titles = ['email', 'tên', 'họ', 'số điện thoại', 'địa chỉ'];
    const index = checkFormatArray([email, lastName, firstName, phone, adress]);
    console.log(props);
    if (index === true) {
      props.navigation.navigate('Profile', {
        email,
        lastName,
        firstName,
        phone,
        adress,
        sponsorID,
        birth,
      });
    } else {
      Alert.alert('Vui lòng điền ' + titles[index]);
    }
  };

  return (
    <View style={{flex: 1, paddingHorizontal: 10, paddingTop: 10}}>
      <TextField title={'Email'} onChangeText={(val) => setEmail(val)} />
      <TextField
        title={'Sponsor ID'}
        onChangeText={(val) => setSponsorID(val)}
      />
      <View style={{flexDirection: 'row'}}>
        <View style={{flex: 1}}>
          <TextField title={'Tên'} onChangeText={(val) => setLastName(val)} />
        </View>
        <View style={{width: 20}} />
        <View style={{flex: 1}}>
          <TextField title={'Họ'} onChangeText={(val) => setFirstName(val)} />
        </View>
      </View>
      <TextField
        title={'Số điện thoại'}
        onChangeText={(val) => setPhone(val)}
      />
      <PickerDate
        value={birth}
        onValueChange={(val) => setBirth(val)}
        title={'Ngày sinh'}
      />

      <TextMulti title={'Địa chỉ'} onChangeText={(val) => setAdress(val)} />
      <TouchableOpacity onPress={onNextPress} style={styles.btnNext}>
        <Image style={{width: 30, height: 30}} source={R.images.iconRight1} />
      </TouchableOpacity>
      <View style={{height: 100}} />
    </View>
  );
};

const styles = StyleSheet.create({
  btnNext: {
    borderRadius: 30,
    backgroundColor: '#1473E6',
    width: 50,
    height: 50,
    justifyContent: 'center',
    alignItems: 'center',
    marginTop: 20,
    alignSelf: 'flex-end',
    elevation: 2,
    shadowColor: '#000',
    shadowOffset: {
      width: 0,
      height: 1,
    },
    shadowOpacity: 0.15,
    shadowRadius: 1.84,
  },
});

export default GeneralInfor;
