import * as React from "react";

import { cn } from "@/lib/utils";

export type InputProps = React.ComponentProps<"input">;

/**
 * Base text input.
 *
 * Previously this hard-coded `bg-white` (with a `dark:bg-white/5` patch) and a
 * literal `#428B4D` focus border, which meant it could not follow the theme and
 * duplicated the brand colour outside the token system. It now uses the
 * semantic tokens, so light/dark and any future brand change flow through
 * automatically.
 *
 * `text-base` below `md` is deliberate: anything under 16px makes iOS Safari
 * zoom the viewport when the field takes focus.
 */
const INPUT_BASE_CLASS =
  "file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground h-9 w-full min-w-0 rounded-md border border-input bg-card px-3 py-1 text-base shadow-xs transition-[color,box-shadow,border-color] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-70 md:text-sm";
const INPUT_FOCUS_CLASS =
  "focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/20 focus-visible:outline-none";
const INPUT_INVALID_CLASS =
  "aria-invalid:border-destructive aria-invalid:focus-visible:ring-destructive/20";

function Input({ className, type, ...props }: InputProps) {
  return (
    <input
      type={type}
      data-slot="input"
      className={cn(INPUT_BASE_CLASS, INPUT_FOCUS_CLASS, INPUT_INVALID_CLASS, className)}
      {...props}
    />
  );
}

export { Input };
