import * as React from "react";
import { cn } from "@/utils/helpers";
import { useTranslations } from "next-intl";

export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
  error?: { message?: string } | null;
  placeholder?: string;
  CustomChilderen?: React.ReactNode;
}

const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
  ({ className, placeholder, error, CustomChilderen, ...props }, ref) => {
    const t = useTranslations("LABELS");

    return (
      <div className="relative">
        <textarea
          ref={ref}
          className={cn(
            "flex min-h-[100px] w-full rounded-md border border-input bg-popover px-4 py-2 text-sm ring-offset-popover placeholder:text-muted-foreground focus-visible:underline-offset-0 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 disabled:bg-gray-200",
            className,
            error && error?.message && "border border-[#ef233c]",
          )}
          placeholder={t("enter", { name: t(placeholder || "") })}
          {...props}
        />
        {CustomChilderen}
      </div>
    );
  },
);

Textarea.displayName = "Textarea";

export { Textarea };
