import React from 'react';

import { Form, Input, Button, Checkbox } from 'antd';

import _auth from '@netuno/auth-client';

const layout = {
    labelCol: { span: 8 },
    wrapperCol: { span: 16 },
};
const tailLayout = {
    wrapperCol: { offset: 8, span: 16 },
};

export default ()=> {
    const onFinish = (values) => {
        console.log('Success:', values);
        _auth.login({
            ...values,
            success: ()=> {
                window.location = '/main';
            },
            fail: ()=> {
                alert("Fail.");
            }
        });
    };

    const onFinishFailed = (errorInfo) => {
        console.log('Failed:', errorInfo);
    };

    return (
    <Form
        {...layout}
        name="basic"
        initialValues={{ remember: true }}
        onFinish={onFinish}
        onFinishFailed={onFinishFailed}
    >
        <Form.Item
        label="Utilizador"
        name="username"
        rules={[{ required: true, message: 'Please input your username!' }]}
        >
        <Input />
        </Form.Item>

        <Form.Item
        label="Password"
        name="password"
        rules={[{ required: true, message: 'Please input your password!' }]}
        >
        <Input.Password />
        </Form.Item>

        <Form.Item {...tailLayout}>
        <Button type="primary" htmlType="submit">
            Entrar
        </Button>
        </Form.Item>
    </Form>
    );
};