import { useFormContext, useController, useFormState } from 'react-hook-form'
import { useId } from 'react';
function useAdmui({ name, required }) {
    const id = useId();
    if (!name) return { id };

    const { control, setValue } = useFormContext();
    const { errors, dirtyFields, isValid } = useFormState({ control, name: [name] });
    const { field } = useController({ name, control, rules: { required } });
    const isInvalid = !!errors[name];
    const isDirty = !!dirtyFields[name];
    return { control, field, isInvalid, id, setValue, isValid, isDirty };
}
export default useAdmui 