'use client' import type { FieldPath, FieldValues, UseFormReturn } from 'react-hook-form' import { useWatch } from 'react-hook-form' function hasValue(value: unknown): boolean { if (value === null || value === undefined) return false if (typeof value === 'string') return value.trim().length > 0 if (Array.isArray(value)) return value.length > 0 return true } export function useFieldErrorVisible( form: UseFormReturn, name: FieldPath ): boolean { const value = useWatch({ control: form.control, name }) const { error, isTouched } = form.getFieldState(name, form.formState) if (!error) return false if (form.formState.isSubmitted) return true return isTouched && hasValue(value) }