var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import { jsx as _jsx } from "react/jsx-runtime";
import React from "react";
import { Controller, useFormContext } from "react-hook-form";
// https://react-hook-form.com/api#Controller
// The controller wrapper helps with thrid party controlled components.
// The Controller can also take a prop of control, which would originally
// come from useForm. As we're using FormContext (with the FormProvider in FormTemplate)
// we can simple destructure any form methods we need here, for example setValue, etc.
export var FormController = React.memo(function (_a) {
    var name = _a.name, render = _a.render;
    var methods = useFormContext();
    // Any errors related to current field name.
    var error = methods.formState.errors[name];
    // If field has been touched
    // const touched = methods.formState.touched[name];
    // If any of the inputs have been modified. Will use at later date if necessary.
    // const dirty = methods.formState.dirtyFields[name];
    return (_jsx(Controller, { name: name, control: methods.control, render: function (innerProps) {
            return render(__assign(__assign({}, innerProps), { // onChange, onBlur, name, ref
                methods: methods, error: error }));
        } }));
});
//# sourceMappingURL=index.js.map