import PropTypes from 'prop-types';
import React from 'react';
import FieldGroup from './FieldGroup';

export default function Input (props) {
    const { containerClassName, labelText, type, name, error, required, hidden, ...inputProps } = props;
    if (hidden) return false;
    return (
        <FieldGroup containerClassName={containerClassName} labelText={labelText} error={error} required={required}>
            <input className="cheryl__field" type={type} name={name} aria-required={required} {...inputProps} />
        </FieldGroup>
    );
}

Input.defaultProps = {
    type: 'text',
};

Input.propTypes = {
    containerClassName: PropTypes.string,
    labelText: PropTypes.string,
    type: PropTypes.string,
    name: PropTypes.string,
    error: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
    required: PropTypes.bool,
    hidden: PropTypes.bool
};
