import { Input } from '@admin/components/ui/input';
import { cn } from '@admin/utils/common';
import { Controller, useFormContext } from 'react-hook-form';

interface TextFieldProps {
    name: string;
    type: 'text' | 'email' | 'url' | 'tel' | 'number';
    placeholder?: string;
    disabled?: boolean;
    className?: string;
}

export const TextField = ({ name, type, placeholder, disabled, className }: TextFieldProps) => {
    const { control } = useFormContext();

    return (
        <Controller
            control={control}
            name={name}
            render={({ field }) => (
                <Input {...field} type={type} placeholder={placeholder} disabled={disabled} className={cn(className)} value={field.value || ''} />
            )}
        />
    );
};
