import { Textarea as BaseTextArea, TextAreaProps } from "@nextui-org/react";
import { ControllerFieldState } from "react-hook-form";

type TextAreaCustomProps = {
  fieldProps: any;
  fieldState: ControllerFieldState;
  control?: any;
  name?: string;
};

type TextAreaComponentProps = TextAreaCustomProps & TextAreaProps;

function TextArea({
  children,
  minRows,
  maxRows,
  cacheMeasurements,
  variant = "faded",
  color,
  maxLength,
  minLength,
  size,
  label,
  defaultValue,
  placeholder,
  startContent,
  endContent,
  fullWidth,
  isDisabled,
  isInvalid,
  isReadOnly,
  isRequired = true,
  labelPlacement = "outside",
  disableAnimation,
  baseRef,
  type,
  value,
  className,
  autoComplete,
  description,
  classNames = {
    description:
      "font-inter font-regular text-[12px] text-gray-500 leading-tight",
    label: "block text-sm font-bold tracking-tight font-inter",
    base: "light",
    mainWrapper: "",
    inputWrapper: "h-full text-black",
    innerWrapper: "",
    input: "font-noto text-sm",
    clearButton: "text-saffron dark:text-persian-green",
    helperWrapper: "",
  },
  onChange,
  onValueChange,
  onClear,
  fieldProps,
  fieldState,
}: TextAreaComponentProps) {
  return (
    <BaseTextArea
      {...fieldProps}
      autoComplete={autoComplete}
      baseRef={baseRef}
      cacheMeasurements={cacheMeasurements}
      className={className}
      classNames={classNames}
      color={color}
      defaultValue={defaultValue}
      description={description}
      disableAnimation={disableAnimation}
      endContent={endContent}
      fullWidth={fullWidth}
      isDisabled={isDisabled}
      isInvalid={!!fieldState.error || isInvalid}
      isReadOnly={isReadOnly}
      isRequired={isRequired}
      label={label}
      labelPlacement={labelPlacement}
      maxLength={maxLength}
      maxRows={maxRows}
      minLength={minLength}
      minRows={minRows}
      placeholder={placeholder}
      radius="sm"
      size={size}
      startContent={startContent}
      type={type}
      value={fieldProps.value ?? value}
      variant={variant}
      onChange={fieldProps.onChange || onChange}
      onClear={onClear}
      onValueChange={fieldProps.onChange ?? onValueChange}
    >
      {children}
    </BaseTextArea>
  );
}

export default TextArea;
