import './style.scss'

import classNames from 'classnames'
import { HTMLInputTypeAttribute, HTMLProps, ReactNode } from 'react'
import Field from '../field'
import './style.scss'

interface TextAreaBaseProps {
	isInvalid?: boolean
	isLoading?: boolean
	required?: boolean
	className?: string
	id: string
	field: HTMLProps<HTMLTextAreaElement>
}

function TextAreaBase({
	isInvalid,
	isLoading,
	className,
	id,
	field,
	...rest
}: TextAreaBaseProps) {
	return (
		<textarea
			id={id}
			className={classNames(
				'hds-form-textarea',
				'hds-typography-body-200',
				'hds-font-weight-regular',
				{
					['hds-form-textarea--is-invalid']: isInvalid,
				},
				className
			)}
			{...field}
			{...rest}
		/>
	)
}

interface TextAreaFieldProps {
	isInvalid?: boolean
	isLoading?: boolean
	isRequired?: boolean
	isOptional?: boolean
	id: string
	label?: ReactNode
	helperText?: ReactNode
	error?: ReactNode
	field: HTMLProps<HTMLTextAreaElement>
}

export default function TextAreaField({
	isInvalid,
	isLoading,
	isRequired,
	isOptional,
	id,
	label,
	helperText,
	error,
	field,
	...rest
}: TextAreaFieldProps) {
	return (
		<Field
			label={label}
			helperText={helperText}
			error={error}
			isRequired={isRequired}
			isOptional={isOptional}
			id={id}
			layout="vertical"
		>
			<TextAreaBase
				id={id}
				isInvalid={isInvalid}
				isLoading={isLoading}
				required={isRequired}
				field={field}
				{...rest}
			/>
		</Field>
	)
}
