import { jsx as l, jsxs as j } from "react/jsx-runtime";
import { g as v, s as f, c as x, d as y, F as g } from "../index.esm-BQxOvVZs.js";
import { Modal as F } from "../composables/Modal.js";
import { FormModal as M } from "../feature/govco/FormModal.js";
var p = function(e, r, t) {
  if (e && "reportValidity" in e) {
    var n = v(t, r);
    e.setCustomValidity(n && n.message || ""), e.reportValidity();
  }
}, V = function(e, r) {
  var t = function(a) {
    var o = r.fields[a];
    o && o.ref && "reportValidity" in o.ref ? p(o.ref, a, e) : o.refs && o.refs.forEach(function(i) {
      return p(i, a, e);
    });
  };
  for (var n in r.fields)
    t(n);
}, P = function(e, r) {
  r.shouldUseNativeValidation && V(e, r);
  var t = {};
  for (var n in e) {
    var a = v(r.fields, n), o = Object.assign(e[n] || {}, { ref: a && a.ref });
    if (N(r.names || Object.keys(e), n)) {
      var i = Object.assign({}, E(v(t, n)));
      f(i, "root", o), f(t, n, i);
    } else
      f(t, n, o);
  }
  return t;
}, E = function(e) {
  return Array.isArray(e) ? e.filter(Boolean) : [];
}, N = function(e, r) {
  return e.some(function(t) {
    return t.startsWith(r + ".");
  });
};
function b(e, r, t) {
  return r === void 0 && (r = {}), t === void 0 && (t = {}), function(n, a, o) {
    try {
      return Promise.resolve(function(i, d) {
        try {
          var s = (r.context && process.env.NODE_ENV === "development" && console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead"), Promise.resolve(e[t.mode === "sync" ? "validateSync" : "validate"](n, Object.assign({ abortEarly: !1 }, r, { context: a }))).then(function(c) {
            return o.shouldUseNativeValidation && V({}, o), { values: t.raw ? n : c, errors: {} };
          }));
        } catch (c) {
          return d(c);
        }
        return s && s.then ? s.then(void 0, d) : s;
      }(0, function(i) {
        if (!i.inner)
          throw i;
        return { values: {}, errors: P((d = i, s = !o.shouldUseNativeValidation && o.criteriaMode === "all", (d.inner || []).reduce(function(c, u) {
          if (c[u.path] || (c[u.path] = { message: u.message, type: u.type }), s) {
            var m = c[u.path].types, h = m && m[u.type];
            c[u.path] = x(u.path, s, c, u.type, h ? [].concat(h, u.message) : u.message);
          }
          return c;
        }, {})), o) };
        var d, s;
      }));
    } catch (i) {
      return Promise.reject(i);
    }
  };
}
function C({ children: e, submit: r, onError: t, defaultValue: n, values: a, schema: o, className: i }) {
  const d = y({
    defaultValues: n ?? {},
    values: a,
    mode: "onTouched",
    reValidateMode: "onChange",
    resolver: o ? b(o) : void 0
  });
  return /* @__PURE__ */ l("form", { onSubmit: r ? d.handleSubmit((s) => r(s), t) : void 0, className: i, children: /* @__PURE__ */ j(g, { ...d, children: [
    e,
    /* @__PURE__ */ l(F, { children: /* @__PURE__ */ l(M, {}) })
  ] }) });
}
function U({ children: e, submit: r, onError: t, defaultValue: n, values: a, schema: o, className: i }) {
  const d = y({
    defaultValues: n ?? {},
    values: a,
    mode: "onTouched",
    reValidateMode: "onChange",
    resolver: o ? b(o) : void 0
  });
  return /* @__PURE__ */ l("form", { onSubmit: r ? d.handleSubmit((s) => r(s), t) : void 0, className: i, children: /* @__PURE__ */ l(g, { ...d, children: e }) });
}
export {
  C as AppFormProvider,
  U as BasicFormProvider
};
