import React from 'react';

import { Form } from 'antd';
import classNames from 'classnames';

import styles from './index.less';
import LoginContext from './LoginContext';
import LoginItem from './LoginItem';
import LoginSubmit from './LoginSubmit';
import i18n from '../../../../../utils/share';
const pages = i18n.getI18n('pages');
const Login = props => {
  const { className } = props;
  const otherChildren = [];
  React.Children.forEach(props.children, child => {
    if (!child) {
      return;
    }
    otherChildren.push(child);
  });
  return (
    <LoginContext.Provider>
      <div className={classNames(className, styles.login)}>
        <div className={styles.desc}>{pages.get('login.welcome')}</div>
        <Form
          form={props.from}
          onFinish={values => {
            if (props.onSubmit) {
              props.onSubmit(values);
            }
          }}
        >
          {props.children}
        </Form>
      </div>
    </LoginContext.Provider>
  );
};

Login.Submit = LoginSubmit;

Login.UserName = LoginItem.UserName;
Login.Password = LoginItem.Password;
Login.Mobile = LoginItem.Mobile;
Login.Captcha = LoginItem.Captcha;

export default Login;
