"use client"; import { useState } from "react"; import { useWatch } from "react-hook-form"; import type { FieldConfig, SelectOption } from "@/types/form"; import type { UseFormRegister, UseFormSetValue, FieldValues, FieldErrors, Control, } from "react-hook-form"; interface FieldRendererProps { field: FieldConfig; register: UseFormRegister; /** RHF setValue — file fields use it to write the uploaded {id, file_name} * back into form state after /api/upload returns. */ setValue: UseFormSetValue; errors: FieldErrors; /** Form control — required for currency live-preview formatting. */ control: Control; /** For readonly display fields, the value to render. */ readonlyValue?: unknown; /** * Options resolved at runtime (from /api/data). When `field.optionGroupId` * is set, look up options here first; fall back to the field's hard-coded * `options` array if absent. */ resolvedOptions?: SelectOption[]; /** Form auth pair, threaded through to file fields for /api/upload. */ cid: string; cs: string; /** Called by file fields when an upload starts (+1) / finishes (-1). The * form uses the running count to block submit while uploads are in flight. */ onUploadStateChange?: (delta: 1 | -1) => void; } const DATE_MIN_DEFAULT = "1900-01-01"; const DATE_MAX_DEFAULT = "2100-12-31"; /** * Renders a single field appropriate to its `type`. All inputs share a common * accessibility scaffold: a real