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

type TextareaProps = TextareaHTMLAttributes<HTMLTextAreaElement> & {
    invalid?: boolean;
};

export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
    ({ className, invalid, rows = 3, ...props }, ref) => (
        <textarea
            ref={ref}
            rows={rows}
            aria-invalid={invalid || undefined}
            className={cn(
                'block w-full resize-y rounded-lg border bg-card px-3 py-2 text-sm text-foreground shadow-sm transition-colors',
                'placeholder:text-muted-foreground/60',
                'focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/30',
                invalid ? 'border-destructive' : 'border-border',
                className,
            )}
            {...props}
        />
    ),
);

Textarea.displayName = 'Textarea';
