import { forwardRef, useRef, useCallback } from "react";
import { FormProviderContext } from "./context.js";
import { jsx } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var FormProviderComponent = function(props, _) {
  var formsRef = useRef({});
  var register = useCallback(function(name, form) {
    if (name) {
      formsRef.current[name] = form;
    }
    return function() {
      delete formsRef.current[name];
    };
  }, []);
  var onFormSubmit = useCallback(function(name, changedValues) {
    props.onFormSubmit && props.onFormSubmit(name, changedValues, {
      forms: formsRef.current
    });
  }, [props.onFormSubmit]);
  var onFormValuesChange = useCallback(function(name, values) {
    props.onFormValuesChange && props.onFormValuesChange(name, values, {
      forms: formsRef.current
    });
  }, [props.onFormValuesChange]);
  return /* @__PURE__ */ jsx(FormProviderContext.Provider, {
    value: {
      onFormValuesChange,
      onFormSubmit,
      register
    },
    children: props.children
  });
};
var FormProvider = forwardRef(FormProviderComponent);
FormProvider.displayName = "FormProvider";
const FormProvider$1 = FormProvider;
export {
  FormProvider$1 as default
};
//# sourceMappingURL=form-provider.js.map
