import React, { useState } from 'react';
import { Button, Input, Label } from '../../../UI';

import Title from '../../component/Title';

const EnteringCode = (props) => {
    const [data, setData] = useState({'code': ''});
    const [information, setInformation] = useState('');
    const updateData = e => {
        setData({ ...data, [e.target.name]: e.target.value});
    }
    const handleEntrance = () => {
        props.data.code == data.code ? props.updateData({status:3, email:props.data.email, code:props.data.code}) : setInformation('Код введен не верно');
     }
    return(
        <>
            <Title> Введите код из письма </Title>
            <Input
              label={'Код'}
              name={'code'}
              type={'number'}
              onChange={updateData}
              value={data.code}
            />
            <Button name={'Entrance'} onClick={handleEntrance}>Проверить код</Button>
            <Label>{information}</Label>
        </>
    )
}

export default EnteringCode;
