/* eslint-disable @typescript-eslint/no-explicit-any */
import React from "react";

import { FormControllerProps } from "./form-controller.types";
import { FormAdapter } from "utils";
import { UseField } from "hooks";

export const FormController = <Form extends FormAdapter<any, any>, Name extends string, Value>({
  name,
  render,
  useField,
  ...validation
}: FormControllerProps<Form, Name, Value> & { useField: UseField<FormAdapter<any, string>, any> }) => {
  const field = useField(name, validation as any);

  return <>{render(field)}</>;
};
