import React from 'react';
import { Field } from 'react-final-form';

// Redux part
import { useSelector, useDispatch } from 'react-redux';
import { StoreState } from 'store/rootReducer';

// Import actions here

import classNames from 'classnames/bind';
import Input from 'components/formItems/Input';
import Button from 'components/items/Button';
import ProjectInput from 'components/formItems/ProjectInput';
import ProjectButton from 'components/items/ProjectButton';
import { required, email, composeValidators } from 'store/utils/validation';
import styleIdentifiers from './changeEmailForm.scss';

const styles = classNames.bind(styleIdentifiers);

export interface StateProps {}

export interface DispatchProps {}

export interface OwnProps {
  onSubmit: Function;
}

export type ChangeEmailFormProps = StateProps & DispatchProps & OwnProps;

const ChangeEmailForm = (props: ChangeEmailFormProps) => {
  const { handleSubmit, submitting, valid, customClassName, initialValues } = props;

  // mapStateToProps
  const content = useSelector((state: StoreState) => state.content.raw);

  return (
    <form className={styles('ChangeEmailForm', customClassName)} onSubmit={handleSubmit}>
      <Field
        component={ProjectInput}
        initialValue={initialValues.email}
        name="newEmail"
        type="email"
        placeholder="example@mail.com"
        label="forms.settings.newMail"
        validate={composeValidators(required, email)}
      />

      <ProjectButton
        disabled={submitting || !valid}
        color="primary"
        label="forms.settings.edit"
        rounded
        type="submit"
      />
    </form>
  );
};

export default ChangeEmailForm;
