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

type Size = "sm" | "md" | "lg";

type Props = React.TextareaHTMLAttributes<HTMLTextAreaElement> & {
  invalid?: boolean;
  /** Alignement de spec avec Button/Input : sm 80px min, md 120px, lg 160px. */
  size?: Size;
};

// Textarea utilise min-h plutot qu'h fixe (pas de hauteur fermee).
const sizeClasses: Record<Size, string> = {
  sm: "min-h-20 px-3 py-2 text-xs",
  md: "min-h-[7.5rem] px-3 py-2.5 text-sm",
  lg: "min-h-40 px-3.5 py-3 text-sm",
};

export const Textarea = React.forwardRef<HTMLTextAreaElement, Props>(
  ({ className, invalid, size = "md", ...props }, ref) => {
    return (
      <textarea
        ref={ref}
        aria-invalid={invalid || undefined}
        className={cn(
          "input-ring w-full bg-surface border border-border rounded-md text-text placeholder:text-text-faint resize-none transition-[border-color,box-shadow,background-color] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)]",
          sizeClasses[size],
          "disabled:opacity-50 disabled:cursor-not-allowed",
          invalid && "border-danger/60",
          className,
        )}
        {...props}
      />
    );
  },
);
Textarea.displayName = "Textarea";
