import { Checkbox } from 'antd';
import React from 'react';
import LoginForm from '../components/Login';
import LoginMessage from './loginMessage';
import { useIntl } from '@/locales/localeExports';
/* eslint-disable */
const { UserName, Password, Submit } = LoginForm;
const useAccount = props => (
  <LoginForm onSubmit={props.onSubmit}>
    {props.status === 'error' && props.type === 'account' && !props.submitting && (
      <LoginMessage
        content={useIntl().formatMessage({
          id: 'pages.login.accountLogin.errorMessage',
        })}
      />
    )}
    <UserName
      name="userName"
      placeholder={useIntl().formatMessage({
        id: 'pages.login.username.placeholder',
      })}
      rules={[
        {
          required: true,
          message: useIntl().formatMessage({
            id: 'pages.login.username.required',
          }),
        },
      ]}
    />
    <Password
      name="password"
      placeholder={useIntl().formatMessage({
        id: 'pages.login.password.placeholder',
      })}
      rules={[
        {
          required: true,
          message: useIntl().formatMessage({
            id: 'pages.login.password.required',
          }),
        },
      ]}
    />
    <div>
      <Checkbox
        checked={props.autoLogin}
        onChange={e => props.setAutoLogin(e.target.checked)}
      >
        {useIntl().formatMessage({ id: 'pages.login.rememberMe' })}
      </Checkbox>
    </div>
    <Submit loading={props.submitting}>
      {useIntl().formatMessage({ id: 'pages.login.submit' })}
    </Submit>
  </LoginForm>
);

export default useAccount;
