import React from 'react';
import TextareaAutosize from 'react-textarea-autosize';
import { cn } from '@/lib/utils';

type TextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement>;

const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps & { autoSize?: boolean }>(
  ({ className, autoSize, ...props }, ref) => {
    const classNameFinal = cn(
      'border-neutral-5 bg-neutral-3 ring-offset-neutral-2 placeholder:text-neutral-10 focus-visible:ring-ring flex min-h-[80px] w-full rounded-md border px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
      autoSize && 'min-h-[0px]',
      className,
    );

    if (autoSize) {
      return <TextareaAutosize className={classNameFinal} ref={ref} {...(props as any)} />;
    }

    return <textarea className={classNameFinal} ref={ref} {...props} />;
  },
);
Textarea.displayName = 'Textarea';

export { Textarea };
