import { forwardRef, type TextareaHTMLAttributes } from 'react';
import { cn } from '@lib/utils/cn';

export interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
  state?: 'default' | 'error' | 'success';
}

export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
  ({ className, state = 'default', ...props }, ref) => {
    const stateClass = {
      default: 'border-slate-600/40',
      error: 'border-red-500/60 focus:border-red-500 focus:ring-red-500/30',
      success: 'border-green-500/60 focus:border-green-500 focus:ring-green-500/30',
    }[state];
    return (
      <textarea
        ref={ref}
        className={cn(
          'w-full bg-surface-overlay border rounded-md px-3 py-2 text-sm text-label placeholder:text-hint',
          'focus:outline-none focus:border-blue-500/60 focus:ring-1 focus:ring-blue-500/30',
          'transition-colors resize-y min-h-[4rem]',
          'disabled:opacity-50 disabled:cursor-not-allowed',
          stateClass,
          className,
        )}
        {...props}
      />
    );
  },
);
Textarea.displayName = 'Textarea';
