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

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

const Input = React.forwardRef<HTMLInputElement, InputProps>(
  ({ className, type, label, error, id, ...props }, ref) => {
    const generatedId = React.useId()
    const inputId = id || generatedId
    
    return (
      <div className="w-full">
        {label && (
          <label
            htmlFor={inputId}
            className="block text-sm font-medium text-[#4A5568] mb-2"
          >
            {label}
            {props.required && <span className="text-[#C41E3A] ml-1">*</span>}
          </label>
        )}
        <input
          type={type}
          id={inputId}
          data-slot="input"
          className={cn(
            "file:text-foreground placeholder:text-[#A0AEC0] selection:bg-[#005EB8] selection:text-white h-10 w-full min-w-0 rounded-lg border border-[#E2E8F0] bg-white px-4 py-2 text-base text-[#1A1A2E] shadow-sm transition-all duration-300 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:opacity-50 md:text-sm",
            "focus-visible:border-[#005EB8] focus-visible:ring-2 focus-visible:ring-[#005EB8]/50 focus-visible:shadow-lg focus-visible:shadow-[#005EB8]/20",
            "hover:border-[#005EB8]",
            error && "border-[#DC2626] focus-visible:border-[#DC2626] focus-visible:ring-[#DC2626]/50",
            className
          )}
          ref={ref}
          aria-invalid={error ? "true" : "false"}
          {...props}
        />
        {error && (
          <p className="mt-1 text-sm text-[#DC2626]">{error}</p>
        )}
      </div>
    )
  }
)
Input.displayName = "Input"

export { Input }
