import * as React from "react"
import { cn } from "@/lib/utils"

export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
  label?: string
  error?: string
}

const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
  ({ className, label, error, id, ...props }, ref) => {
    const generatedId = React.useId()
    const textareaId = id || generatedId
    
    return (
      <div className="w-full">
        {label && (
          <label
            htmlFor={textareaId}
            className="block text-sm font-medium text-[#4A5568] mb-2"
          >
            {label}
            {props.required && <span className="text-[#C41E3A] ml-1">*</span>}
          </label>
        )}
        <textarea
          id={textareaId}
          data-slot="textarea"
          className={cn(
            "placeholder:text-[#A0AEC0] selection:bg-[#005EB8] selection:text-white min-h-16 w-full rounded-lg border border-[#E2E8F0] bg-white px-4 py-3 text-base text-[#1A1A2E] shadow-sm transition-all duration-300 outline-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm resize-none",
            "focus-visible:border-[#005EB8] focus-visible:ring-2 focus-visible:ring-[#005EB8]/50 focus-visible:shadow-lg focus-visible:shadow-[#005EB8]/20",
            "hover:border-[#005EB8]",
            error && "border-[#DC2626] focus-visible:border-[#DC2626] focus-visible:ring-[#DC2626]/50",
            className
          )}
          ref={ref}
          aria-invalid={error ? "true" : "false"}
          {...props}
        />
        {error && (
          <p className="mt-1 text-sm text-[#DC2626]">{error}</p>
        )}
      </div>
    )
  }
)
Textarea.displayName = "Textarea"

export { Textarea }
