import { cn } from '@/lib/utils'
import { InputHTMLAttributes, forwardRef } from 'react'

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

export const Input = forwardRef<HTMLInputElement, InputProps>(
  ({ className, label, error, id, ...props }, ref) => {
    return (
      <div className="flex flex-col gap-1.5">
        {label && (
          <label htmlFor={id} className="text-[10px] font-medium text-[#888] tracking-[0.2em] uppercase">
            {label}
          </label>
        )}
        <input
          ref={ref}
          id={id}
          className={cn(
            'w-full bg-[#0a0a0a] border-b border-[#333] px-0 py-3 text-sm text-white placeholder:text-[#333]',
            'focus:outline-none focus:border-[#C9A84C] transition-colors duration-200',
            'disabled:opacity-40 disabled:cursor-not-allowed',
            error && 'border-red-700',
            className
          )}
          {...props}
        />
        {error && <p className="text-xs text-red-500 tracking-wide">{error}</p>}
      </div>
    )
  }
)

Input.displayName = 'Input'
