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

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

// On retire `size` du HTMLInputElement (qui est un `number` natif pour les
// inputs text, peu utilise) pour reutiliser le nom au sens design system.
type Props = Omit<React.InputHTMLAttributes<HTMLInputElement>, "size"> & {
  invalid?: boolean;
  /** Alignement de spec avec Button : sm 36px, md 40px, lg 44px (44 garanti mobile). */
  size?: Size;
};

const sizeClasses: Record<Size, string> = {
  sm: "min-h-11 md:min-h-9 h-11 md:h-9 px-3 text-xs",
  md: "min-h-11 md:min-h-10 h-11 md:h-10 px-3 py-2.5 text-sm",
  lg: "min-h-11 h-11 px-3.5 text-sm",
};

export const Input = React.forwardRef<HTMLInputElement, Props>(
  ({ className, invalid, size = "md", ...props }, ref) => {
    return (
      <input
        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 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}
      />
    );
  },
);
Input.displayName = "Input";
