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

export interface InputProps
  extends React.InputHTMLAttributes<HTMLInputElement> {
  label?: string;
  error?: string;
}

export const Input = React.forwardRef<HTMLInputElement, InputProps>(
  ({ className, label, error, id, type = "text", ...props }, ref) => {
    return (
      <div className="w-full space-y-1.5">
        {label && (
          <label
            htmlFor={id}
            className="block text-xs font-semibold text-slate-700 select-none"
          >
            {label}
          </label>
        )}
        <input
          ref={ref}
          id={id}
          type={type}
          className={cn(
            // PRD §20: h-10 rounded-lg border border-slate-200 px-3 text-sm focus:border-[#C8A45D] focus:ring-2 focus:ring-[#C8A45D]/20
            "h-10 w-full rounded-lg border border-slate-200 bg-white px-3 text-sm text-slate-900 placeholder:text-slate-400 transition-colors focus:outline-none focus:border-[#C8A45D] focus:ring-2 focus:ring-[#C8A45D]/20 disabled:cursor-not-allowed disabled:bg-slate-50 disabled:text-slate-400",
            error && "border-[#B94A48] focus:border-[#B94A48] focus:ring-[#B94A48]/20",
            className
          )}
          {...props}
        />
        {error && (
          <p className="text-xs text-[#B94A48] font-medium">{error}</p>
        )}
      </div>
    );
  }
);
Input.displayName = "Input";
