import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Button, Input, Title, SmallText } from '../../../UI';
import postData from '../../function/postData';
//{setToken, updateData}

export const Entrance: React.FC = () => {
    const [_data, setData] = useState({login:'',password:''});
    const [information, setInformation] = useState('');

    const onChange = (name: string, value:string) => {
        setData({ ..._data, [name]: value});
    };

    const reset = (name: string, value:string) => {
        setData({ ..._data, [name]: value});
    };

    const handleEntrance = () => {
        console.log(_data);
        postData('/api/login', { _data })
            .then((data) => {
                console.log(data);
                //data.token ? setToken(data) : setInformation(data.error);
                setInformation(data.error);
            });
     }
    return(
        <>
            <Title> Вход в систему </Title>
            <Input label={'Логин'} name={'login'} type={'text'} onChange={onChange} value={_data.login}/>
            <Input label={'Пароль'} name={'password'} type={'password'} onChange={onChange} value={_data.password}/>
            <Button onClick={handleEntrance} align={''} styles={'yellow'}>Войти</Button>
            <Button onClick={handleEntrance} align={''} styles={'yellow'}>Забыл/Сбросить пароль</Button>
        </>
    )
}

Entrance.propTypes = {
    setToken: PropTypes.func.isRequired
  }
