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

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

    interface Props_data {
        name: string;
        value: string;
        onClick: () => void;
      }

      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);
            }); */
     }
    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={''}>Войти</Button>
            <SmallText>{information}</SmallText>
            <LinkButton onClick={() => reset}>Забыл/Сбросить пароль</LinkButton>
        </>
    )
}

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