import { Controller, Control, FieldError } from "react-hook-form";

interface FormTextareaProps {
  name: string;
  control: Control<any>;
  label: string;
  placeholder?: string;
  rows?: number;
  required?: boolean;
  disabled?: boolean;
  error?: FieldError;
  className?: string;
}

export default function FormTextarea({
  name,
  control,
  label,
  placeholder,
  rows = 4,
  required = false,
  disabled = false,
  error,
  className = "",
}: FormTextareaProps) {
  return (
    <div>
      <label className="text-sm font-medium text-gray-700 mb-1 block">
        {label}
        {required && <span className="text-red-500">*</span>}
      </label>
      <Controller
        name={name}
        control={control}
        render={({ field }) => (
          <textarea
            {...field}
            rows={rows}
            placeholder={placeholder}
            disabled={disabled}
            className={`w-full border rounded-md px-4 py-2 outline-none transition-colors resize-vertical ${
              disabled
                ? "bg-gray-100 cursor-not-allowed text-gray-600 border-gray-200"
                : "focus:ring-1 focus:ring-teal-500 border-gray-300"
            } ${error ? "border-red-500" : ""} ${className}`}
          />
        )}
      />
      {error && (
        <p className="text-red-500 text-xs mt-1">{error.message}</p>
      )}
    </div>
  );
}