import React from 'react';
import { Field } from 'react-final-form';
import classNames from 'classnames/bind';

import { required, email, composeValidators } from 'store/utils/validation';
import ProjectInput from 'components/formItems/ProjectInput';
import ProjectButton from 'components/items/ProjectButton/ProjectButton';
import styleIdentifiers from './appLoginForm.scss';

const styles = classNames.bind(styleIdentifiers);

export interface StateProps {}

export interface DispatchProps {}

export interface OwnProps {
  onSubmit: Function;
}

export type AppLoginFormProps = StateProps & DispatchProps & OwnProps;

const AppLoginForm = (props: AppLoginFormProps) => {
  const { handleSubmit, submitting, valid } = props;
  return (
    <form className={styles('AppLoginForm')} onSubmit={handleSubmit}>
      <Field
        component={ProjectInput}
        name="email"
        type="email"
        label="forms.login.email.email"
        validate={composeValidators(required, email)}
        placeholder="forms.login.email.placeholder"
      />
      <Field
        component={ProjectInput}
        seed="password"
        name="password"
        label="forms.login.password.password"
        validate={required}
        placeholder="forms.login.password.placeholder"
      />
      <ProjectButton
        color="secondary"
        disabled={submitting || !valid}
        label="forms.login.login"
        rounded
        type="submit"
      />
    </form>
  );
};

export default AppLoginForm;
