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

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

const Input = React.forwardRef<HTMLInputElement, InputProps>(
  ({ className, type, id, label, prefix, required, ...props }, ref) => {
    return (
      <div>
        {label && (
          <Label htmlFor={id}>{`${label}${required ? "*" : ""}`}</Label>
        )}
        <div className="flex items-center rounded-md border border-input bg-background w-full h-10 ">
          {prefix && (
            <span className="border-r border-input py-2 pr-2 px-3 text-gray-600">
              {prefix}
            </span>
          )}
          <input
            type={type}
            className={cn(
              "flex w-full focus-visible:outline-none text-sm ring-offset-background px-3 py-2 file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
              className
            )}
            id={id}
            required={required}
            ref={ref}
            {...props}
          />
        </div>
      </div>
    );
  }
);

Input.displayName = "Input";

export { Input };
