import {
  Form
} from "./chunk-2OMSNCRH.js";
import {
  __async
} from "./chunk-CRTRMMJ7.js";

// src/context/dynamic-form-context.tsx
import { createContext, useContext } from "react";
import { jsx } from "react/jsx-runtime";
var DynamicFormContext = createContext(null);
function DynamicFormProvider({
  children,
  fields,
  formik
}) {
  const contextValue = {
    formik,
    fields,
    getFieldValue: (name) => formik.values[name],
    getFieldError: (name) => {
      const error = formik.errors[name];
      const touched = formik.touched[name];
      return touched && error ? String(error) : void 0;
    },
    getFieldTouched: (name) => Boolean(formik.touched[name]),
    setFieldValue: (field, value) => __async(null, null, function* () {
      yield formik.setFieldValue(field, value);
    }),
    handleChange: formik.handleChange,
    handleBlur: formik.handleBlur
  };
  return /* @__PURE__ */ jsx(DynamicFormContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(Form.Root, { onSubmit: formik.handleSubmit, children }) });
}
function useDynamicForm() {
  const context = useContext(DynamicFormContext);
  if (!context) {
    throw new Error("useDynamicForm must be used within a DynamicFormProvider");
  }
  return context;
}

export {
  DynamicFormProvider,
  useDynamicForm
};
//# sourceMappingURL=chunk-O2S7S5B4.js.map