import h from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import o from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import * as s from "react";
var u = /* @__PURE__ */ s.createContext({
  triggerFormChange: function() {
  },
  triggerFormFinish: function() {
  },
  registerForm: function() {
  },
  unregisterForm: function() {
  }
}), C = function(g) {
  var c = g.validateMessages, m = g.onFormChange, a = g.onFormFinish, f = g.children, t = s.useContext(u), i = s.useRef({});
  return /* @__PURE__ */ s.createElement(u.Provider, {
    value: o(o({}, t), {}, {
      validateMessages: o(o({}, t.validateMessages), c),
      // =========================================================
      // =                  Global Form Control                  =
      // =========================================================
      triggerFormChange: function(r, e) {
        m && m(r, {
          changedFields: e,
          forms: i.current
        }), t.triggerFormChange(r, e);
      },
      triggerFormFinish: function(r, e) {
        a && a(r, {
          values: e,
          forms: i.current
        }), t.triggerFormFinish(r, e);
      },
      registerForm: function(r, e) {
        r && (i.current = o(o({}, i.current), {}, h({}, r, e))), t.registerForm(r, e);
      },
      unregisterForm: function(r) {
        var e = o({}, i.current);
        delete e[r], i.current = e, t.unregisterForm(r);
      }
    })
  }, f);
};
export {
  C as FormProvider,
  u as default
};
