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

import style from './fancyTextArea.module.sass';

const FancyInput = (props) => {
    const {
        input,
        label,
        type,
        onClick,
        isValidation = true,
        meta: { asyncValidating, touched, error }
    } = props;


    const styleValidationHandler = () => {

        if(touched && error && isValidation) {
            return style.inputError;
        }else if(touched && !error && isValidation) {
            return style.inputValid
        }
    };

    // const onChange = (e) => {
    //     const { input: { onChange } } = props;
    //     onChange(e.target.files[0])
    // };

    return(
        <>
            <label htmlFor={input.name} onClick={onClick}>
                {label}
            </label>
            <div className={asyncValidating ? 'async-validating' : style.mainContainer}>
                <textarea
                    {...input}
                    id={input.name}
                    className={ styleValidationHandler() }
                />

                {touched && error && <span>{error}</span>}
            </div>
        </>
    );
};


export default (FancyInput);