import { jsx as _jsx } from "react/jsx-runtime";
import { useMemo } from "react";
import { useFormContext } from "react-hook-form";
import { nanoid } from "nanoid";
export const IdField = ({ name = "id", value, generator = "nanoid", ...rest }) => {
    const { register, formState: { submitCount }, } = useFormContext();
    const actualValue = useMemo(() => {
        if (value !== undefined)
            return value;
        if (typeof generator === "function")
            return generator();
        switch (generator) {
            case "nanoid":
                return nanoid();
            case "uuid":
                return crypto.randomUUID();
        }
    }, 
    // We want to re-generate the ID on every submit
    [value, generator, submitCount]);
    return (_jsx("input", { type: "hidden", value: actualValue, ...register(name), ...rest }));
};
//# sourceMappingURL=id-field.js.map