"use strict";
(self.webpackChunk_N_E = self.webpackChunk_N_E || []).push([
  [87536],
  {
    87536: function (e, t, r) {
      r.d(t, {
        Dq: function () {
          return useFieldArray;
        },
        Gc: function () {
          return useFormContext;
        },
        KN: function () {
          return appendErrors;
        },
        Qr: function () {
          return Controller;
        },
        RV: function () {
          return FormProvider;
        },
        U2: function () {
          return get;
        },
        cI: function () {
          return useForm;
        },
        qo: function () {
          return useWatch;
        },
        t8: function () {
          return set;
        },
      });
      var s = r(67294),
        isCheckBoxInput = (e) => "checkbox" === e.type,
        isDateObject = (e) => e instanceof Date,
        isNullOrUndefined = (e) => null == e;
      let isObjectType = (e) => "object" == typeof e;
      var isObject = (e) =>
          !isNullOrUndefined(e) &&
          !Array.isArray(e) &&
          isObjectType(e) &&
          !isDateObject(e),
        getEventValue = (e) =>
          isObject(e) && e.target
            ? isCheckBoxInput(e.target)
              ? e.target.checked
              : e.target.value
            : e,
        getNodeParentName = (e) => e.substring(0, e.search(/\.\d+(\.|$)/)) || e,
        isNameInFieldArray = (e, t) => e.has(getNodeParentName(t)),
        isPlainObject = (e) => {
          let t = e.constructor && e.constructor.prototype;
          return isObject(t) && t.hasOwnProperty("isPrototypeOf");
        },
        i =
          "undefined" != typeof window &&
          void 0 !== window.HTMLElement &&
          "undefined" != typeof document;
      function cloneObject(e) {
        let t;
        let r = Array.isArray(e);
        if (e instanceof Date) t = new Date(e);
        else if (e instanceof Set) t = new Set(e);
        else if (
          !(
            !(i && (e instanceof Blob || e instanceof FileList)) &&
            (r || isObject(e))
          )
        )
          return e;
        else if (((t = r ? [] : {}), r || isPlainObject(e)))
          for (let r in e) e.hasOwnProperty(r) && (t[r] = cloneObject(e[r]));
        else t = e;
        return t;
      }
      var compact = (e) => (Array.isArray(e) ? e.filter(Boolean) : []),
        isUndefined = (e) => void 0 === e,
        get = (e, t, r) => {
          if (!t || !isObject(e)) return r;
          let s = compact(t.split(/[,[\].]+?/)).reduce(
            (e, t) => (isNullOrUndefined(e) ? e : e[t]),
            e
          );
          return isUndefined(s) || s === e ? (isUndefined(e[t]) ? r : e[t]) : s;
        },
        isBoolean = (e) => "boolean" == typeof e;
      let a = { BLUR: "blur", FOCUS_OUT: "focusout", CHANGE: "change" },
        l = {
          onBlur: "onBlur",
          onChange: "onChange",
          onSubmit: "onSubmit",
          onTouched: "onTouched",
          all: "all",
        },
        n = {
          max: "max",
          min: "min",
          maxLength: "maxLength",
          minLength: "minLength",
          pattern: "pattern",
          required: "required",
          validate: "validate",
        },
        u = s.createContext(null),
        useFormContext = () => s.useContext(u),
        FormProvider = (e) => {
          let { children: t, ...r } = e;
          return s.createElement(u.Provider, { value: r }, t);
        };
      var getProxyFormState = (e, t, r, s = !0) => {
          let i = { defaultValues: t._defaultValues };
          for (let a in e)
            Object.defineProperty(i, a, {
              get: () => (
                t._proxyFormState[a] !== l.all &&
                  (t._proxyFormState[a] = !s || l.all),
                r && (r[a] = !0),
                e[a]
              ),
            });
          return i;
        },
        isEmptyObject = (e) => isObject(e) && !Object.keys(e).length,
        shouldRenderFormState = (e, t, r, s) => {
          r(e);
          let { name: i, ...a } = e;
          return (
            isEmptyObject(a) ||
            Object.keys(a).length >= Object.keys(t).length ||
            Object.keys(a).find((e) => t[e] === (!s || l.all))
          );
        },
        convertToArrayPayload = (e) => (Array.isArray(e) ? e : [e]),
        shouldSubscribeByName = (e, t, r) =>
          !e ||
          !t ||
          e === t ||
          convertToArrayPayload(e).some(
            (e) => e && (r ? e === t : e.startsWith(t) || t.startsWith(e))
          );
      function useSubscribe(e) {
        let t = s.useRef(e);
        (t.current = e),
          s.useEffect(() => {
            let r =
              !e.disabled &&
              t.current.subject &&
              t.current.subject.subscribe({ next: t.current.next });
            return () => {
              r && r.unsubscribe();
            };
          }, [e.disabled]);
      }
      var isString = (e) => "string" == typeof e,
        generateWatchOutput = (e, t, r, s, i) =>
          isString(e)
            ? (s && t.watch.add(e), get(r, e, i))
            : Array.isArray(e)
            ? e.map((e) => (s && t.watch.add(e), get(r, e)))
            : (s && (t.watchAll = !0), r);
      function useWatch(e) {
        let t = useFormContext(),
          {
            control: r = t.control,
            name: i,
            defaultValue: a,
            disabled: l,
            exact: n,
          } = e || {},
          u = s.useRef(i);
        (u.current = i),
          useSubscribe({
            disabled: l,
            subject: r._subjects.values,
            next: (e) => {
              shouldSubscribeByName(u.current, e.name, n) &&
                d(
                  cloneObject(
                    generateWatchOutput(
                      u.current,
                      r._names,
                      e.values || r._formValues,
                      !1,
                      a
                    )
                  )
                );
            },
          });
        let [o, d] = s.useState(r._getWatch(i, a));
        return s.useEffect(() => r._removeUnmounted()), o;
      }
      var isKey = (e) => /^\w*$/.test(e),
        stringToPath = (e) =>
          compact(e.replace(/["|']|\]/g, "").split(/\.|\[/)),
        set = (e, t, r) => {
          let s = -1,
            i = isKey(t) ? [t] : stringToPath(t),
            a = i.length,
            l = a - 1;
          for (; ++s < a; ) {
            let t = i[s],
              a = r;
            if (s !== l) {
              let r = e[t];
              a =
                isObject(r) || Array.isArray(r)
                  ? r
                  : isNaN(+i[s + 1])
                  ? {}
                  : [];
            }
            (e[t] = a), (e = e[t]);
          }
          return e;
        };
      let Controller = (e) =>
        e.render(
          (function (e) {
            let t = useFormContext(),
              {
                name: r,
                disabled: i,
                control: l = t.control,
                shouldUnregister: n,
              } = e,
              u = isNameInFieldArray(l._names.array, r),
              o = useWatch({
                control: l,
                name: r,
                defaultValue: get(
                  l._formValues,
                  r,
                  get(l._defaultValues, r, e.defaultValue)
                ),
                exact: !0,
              }),
              d = (function (e) {
                let t = useFormContext(),
                  {
                    control: r = t.control,
                    disabled: i,
                    name: a,
                    exact: l,
                  } = e || {},
                  [n, u] = s.useState(r._formState),
                  o = s.useRef(!0),
                  d = s.useRef({
                    isDirty: !1,
                    isLoading: !1,
                    dirtyFields: !1,
                    touchedFields: !1,
                    isValidating: !1,
                    isValid: !1,
                    errors: !1,
                  }),
                  c = s.useRef(a);
                return (
                  (c.current = a),
                  useSubscribe({
                    disabled: i,
                    next: (e) =>
                      o.current &&
                      shouldSubscribeByName(c.current, e.name, l) &&
                      shouldRenderFormState(e, d.current, r._updateFormState) &&
                      u({ ...r._formState, ...e }),
                    subject: r._subjects.state,
                  }),
                  s.useEffect(
                    () => (
                      (o.current = !0),
                      d.current.isValid && r._updateValid(!0),
                      () => {
                        o.current = !1;
                      }
                    ),
                    [r]
                  ),
                  getProxyFormState(n, r, d.current, !1)
                );
              })({ control: l, name: r }),
              c = s.useRef(
                l.register(r, {
                  ...e.rules,
                  value: o,
                  ...(isBoolean(e.disabled) ? { disabled: e.disabled } : {}),
                })
              );
            return (
              s.useEffect(() => {
                let e = l._options.shouldUnregister || n,
                  updateMounted = (e, t) => {
                    let r = get(l._fields, e);
                    r && (r._f.mount = t);
                  };
                if ((updateMounted(r, !0), e)) {
                  let e = cloneObject(get(l._options.defaultValues, r));
                  set(l._defaultValues, r, e),
                    isUndefined(get(l._formValues, r)) &&
                      set(l._formValues, r, e);
                }
                return () => {
                  (u ? e && !l._state.action : e)
                    ? l.unregister(r)
                    : updateMounted(r, !1);
                };
              }, [r, l, u, n]),
              s.useEffect(() => {
                get(l._fields, r) &&
                  l._updateDisabledField({
                    disabled: i,
                    fields: l._fields,
                    name: r,
                    value: get(l._fields, r)._f.value,
                  });
              }, [i, r, l]),
              {
                field: {
                  name: r,
                  value: o,
                  ...(isBoolean(i) || d.disabled
                    ? { disabled: d.disabled || i }
                    : {}),
                  onChange: s.useCallback(
                    (e) =>
                      c.current.onChange({
                        target: { value: getEventValue(e), name: r },
                        type: a.CHANGE,
                      }),
                    [r]
                  ),
                  onBlur: s.useCallback(
                    () =>
                      c.current.onBlur({
                        target: { value: get(l._formValues, r), name: r },
                        type: a.BLUR,
                      }),
                    [r, l]
                  ),
                  ref: (e) => {
                    let t = get(l._fields, r);
                    t &&
                      e &&
                      (t._f.ref = {
                        focus: () => e.focus(),
                        select: () => e.select(),
                        setCustomValidity: (t) => e.setCustomValidity(t),
                        reportValidity: () => e.reportValidity(),
                      });
                  },
                },
                formState: d,
                fieldState: Object.defineProperties(
                  {},
                  {
                    invalid: { enumerable: !0, get: () => !!get(d.errors, r) },
                    isDirty: {
                      enumerable: !0,
                      get: () => !!get(d.dirtyFields, r),
                    },
                    isTouched: {
                      enumerable: !0,
                      get: () => !!get(d.touchedFields, r),
                    },
                    error: { enumerable: !0, get: () => get(d.errors, r) },
                  }
                ),
              }
            );
          })(e)
        );
      var appendErrors = (e, t, r, s, i) =>
          t
            ? {
                ...r[e],
                types: {
                  ...(r[e] && r[e].types ? r[e].types : {}),
                  [s]: i || !0,
                },
              }
            : {},
        generateId = () => {
          let e =
            "undefined" == typeof performance
              ? Date.now()
              : 1e3 * performance.now();
          return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
            /[xy]/g,
            (t) => {
              let r = (16 * Math.random() + e) % 16 | 0;
              return ("x" == t ? r : (3 & r) | 8).toString(16);
            }
          );
        },
        getFocusFieldName = (e, t, r = {}) =>
          r.shouldFocus || isUndefined(r.shouldFocus)
            ? r.focusName ||
              `${e}.${isUndefined(r.focusIndex) ? t : r.focusIndex}.`
            : "",
        getValidationModes = (e) => ({
          isOnSubmit: !e || e === l.onSubmit,
          isOnBlur: e === l.onBlur,
          isOnChange: e === l.onChange,
          isOnAll: e === l.all,
          isOnTouch: e === l.onTouched,
        }),
        isWatched = (e, t, r) =>
          !r &&
          (t.watchAll ||
            t.watch.has(e) ||
            [...t.watch].some(
              (t) => e.startsWith(t) && /^\.\w+/.test(e.slice(t.length))
            ));
      let iterateFieldsByAction = (e, t, r, s) => {
        for (let i of r || Object.keys(e)) {
          let r = get(e, i);
          if (r) {
            let { _f: e, ...a } = r;
            if (e) {
              if (
                (e.refs && e.refs[0] && t(e.refs[0], i) && !s) ||
                (e.ref && t(e.ref, e.name) && !s)
              )
                break;
              iterateFieldsByAction(a, t);
            } else isObject(a) && iterateFieldsByAction(a, t);
          }
        }
      };
      var updateFieldArrayRootError = (e, t, r) => {
          let s = compact(get(e, r));
          return set(s, "root", t[r]), set(e, r, s), e;
        },
        isFileInput = (e) => "file" === e.type,
        isFunction = (e) => "function" == typeof e,
        isHTMLElement = (e) => {
          if (!i) return !1;
          let t = e ? e.ownerDocument : 0;
          return (
            e instanceof
            (t && t.defaultView ? t.defaultView.HTMLElement : HTMLElement)
          );
        },
        isMessage = (e) => isString(e),
        isRadioInput = (e) => "radio" === e.type,
        isRegex = (e) => e instanceof RegExp;
      let o = { value: !1, isValid: !1 },
        d = { value: !0, isValid: !0 };
      var getCheckboxValue = (e) => {
        if (Array.isArray(e)) {
          if (e.length > 1) {
            let t = e
              .filter((e) => e && e.checked && !e.disabled)
              .map((e) => e.value);
            return { value: t, isValid: !!t.length };
          }
          return e[0].checked && !e[0].disabled
            ? e[0].attributes && !isUndefined(e[0].attributes.value)
              ? isUndefined(e[0].value) || "" === e[0].value
                ? d
                : { value: e[0].value, isValid: !0 }
              : d
            : o;
        }
        return o;
      };
      let c = { isValid: !1, value: null };
      var getRadioValue = (e) =>
        Array.isArray(e)
          ? e.reduce(
              (e, t) =>
                t && t.checked && !t.disabled
                  ? { isValid: !0, value: t.value }
                  : e,
              c
            )
          : c;
      function getValidateError(e, t, r = "validate") {
        if (
          isMessage(e) ||
          (Array.isArray(e) && e.every(isMessage)) ||
          (isBoolean(e) && !e)
        )
          return { type: r, message: isMessage(e) ? e : "", ref: t };
      }
      var getValueAndMessage = (e) =>
          isObject(e) && !isRegex(e) ? e : { value: e, message: "" },
        validateField = async (e, t, r, s, i) => {
          let {
              ref: a,
              refs: l,
              required: u,
              maxLength: o,
              minLength: d,
              min: c,
              max: f,
              pattern: g,
              validate: y,
              name: m,
              valueAsNumber: p,
              mount: b,
              disabled: h,
            } = e._f,
            _ = get(t, m);
          if (!b || h) return {};
          let v = l ? l[0] : a,
            setCustomValidity = (e) => {
              s &&
                v.reportValidity &&
                (v.setCustomValidity(isBoolean(e) ? "" : e || ""),
                v.reportValidity());
            },
            A = {},
            V = isRadioInput(a),
            F = isCheckBoxInput(a),
            x =
              ((p || isFileInput(a)) &&
                isUndefined(a.value) &&
                isUndefined(_)) ||
              (isHTMLElement(a) && "" === a.value) ||
              "" === _ ||
              (Array.isArray(_) && !_.length),
            S = appendErrors.bind(null, m, r, A),
            getMinMaxMessage = (e, t, r, s = n.maxLength, i = n.minLength) => {
              let l = e ? t : r;
              A[m] = {
                type: e ? s : i,
                message: l,
                ref: a,
                ...S(e ? s : i, l),
              };
            };
          if (
            i
              ? !Array.isArray(_) || !_.length
              : u &&
                ((!(V || F) && (x || isNullOrUndefined(_))) ||
                  (isBoolean(_) && !_) ||
                  (F && !getCheckboxValue(l).isValid) ||
                  (V && !getRadioValue(l).isValid))
          ) {
            let { value: e, message: t } = isMessage(u)
              ? { value: !!u, message: u }
              : getValueAndMessage(u);
            if (
              e &&
              ((A[m] = {
                type: n.required,
                message: t,
                ref: v,
                ...S(n.required, t),
              }),
              !r)
            )
              return setCustomValidity(t), A;
          }
          if (!x && (!isNullOrUndefined(c) || !isNullOrUndefined(f))) {
            let e, t;
            let s = getValueAndMessage(f),
              i = getValueAndMessage(c);
            if (isNullOrUndefined(_) || isNaN(_)) {
              let r = a.valueAsDate || new Date(_),
                convertTimeToDate = (e) =>
                  new Date(new Date().toDateString() + " " + e),
                l = "time" == a.type,
                n = "week" == a.type;
              isString(s.value) &&
                _ &&
                (e = l
                  ? convertTimeToDate(_) > convertTimeToDate(s.value)
                  : n
                  ? _ > s.value
                  : r > new Date(s.value)),
                isString(i.value) &&
                  _ &&
                  (t = l
                    ? convertTimeToDate(_) < convertTimeToDate(i.value)
                    : n
                    ? _ < i.value
                    : r < new Date(i.value));
            } else {
              let r = a.valueAsNumber || (_ ? +_ : _);
              isNullOrUndefined(s.value) || (e = r > s.value),
                isNullOrUndefined(i.value) || (t = r < i.value);
            }
            if (
              (e || t) &&
              (getMinMaxMessage(!!e, s.message, i.message, n.max, n.min), !r)
            )
              return setCustomValidity(A[m].message), A;
          }
          if ((o || d) && !x && (isString(_) || (i && Array.isArray(_)))) {
            let e = getValueAndMessage(o),
              t = getValueAndMessage(d),
              s = !isNullOrUndefined(e.value) && _.length > +e.value,
              i = !isNullOrUndefined(t.value) && _.length < +t.value;
            if ((s || i) && (getMinMaxMessage(s, e.message, t.message), !r))
              return setCustomValidity(A[m].message), A;
          }
          if (g && !x && isString(_)) {
            let { value: e, message: t } = getValueAndMessage(g);
            if (
              isRegex(e) &&
              !_.match(e) &&
              ((A[m] = {
                type: n.pattern,
                message: t,
                ref: a,
                ...S(n.pattern, t),
              }),
              !r)
            )
              return setCustomValidity(t), A;
          }
          if (y) {
            if (isFunction(y)) {
              let e = await y(_, t),
                s = getValidateError(e, v);
              if (s && ((A[m] = { ...s, ...S(n.validate, s.message) }), !r))
                return setCustomValidity(s.message), A;
            } else if (isObject(y)) {
              let e = {};
              for (let s in y) {
                if (!isEmptyObject(e) && !r) break;
                let i = getValidateError(await y[s](_, t), v, s);
                i &&
                  ((e = { ...i, ...S(s, i.message) }),
                  setCustomValidity(i.message),
                  r && (A[m] = e));
              }
              if (!isEmptyObject(e) && ((A[m] = { ref: v, ...e }), !r))
                return A;
            }
          }
          return setCustomValidity(!0), A;
        },
        appendAt = (e, t) => [...e, ...convertToArrayPayload(t)],
        fillEmptyArray = (e) =>
          Array.isArray(e) ? e.map(() => void 0) : void 0;
      function insert(e, t, r) {
        return [...e.slice(0, t), ...convertToArrayPayload(r), ...e.slice(t)];
      }
      var moveArrayAt = (e, t, r) =>
          Array.isArray(e)
            ? (isUndefined(e[r]) && (e[r] = void 0),
              e.splice(r, 0, e.splice(t, 1)[0]),
              e)
            : [],
        prependAt = (e, t) => [
          ...convertToArrayPayload(t),
          ...convertToArrayPayload(e),
        ],
        removeArrayAt = (e, t) =>
          isUndefined(t)
            ? []
            : (function (e, t) {
                let r = 0,
                  s = [...e];
                for (let e of t) s.splice(e - r, 1), r++;
                return compact(s).length ? s : [];
              })(
                e,
                convertToArrayPayload(t).sort((e, t) => e - t)
              ),
        swapArrayAt = (e, t, r) => {
          [e[t], e[r]] = [e[r], e[t]];
        };
      function unset(e, t) {
        let r = Array.isArray(t) ? t : isKey(t) ? [t] : stringToPath(t),
          s =
            1 === r.length
              ? e
              : (function (e, t) {
                  let r = t.slice(0, -1).length,
                    s = 0;
                  for (; s < r; ) e = isUndefined(e) ? s++ : e[t[s++]];
                  return e;
                })(e, r),
          i = r.length - 1,
          a = r[i];
        return (
          s && delete s[a],
          0 !== i &&
            ((isObject(s) && isEmptyObject(s)) ||
              (Array.isArray(s) &&
                (function (e) {
                  for (let t in e)
                    if (e.hasOwnProperty(t) && !isUndefined(e[t])) return !1;
                  return !0;
                })(s))) &&
            unset(e, r.slice(0, -1)),
          e
        );
      }
      var updateAt = (e, t, r) => ((e[t] = r), e);
      function useFieldArray(e) {
        let t = useFormContext(),
          {
            control: r = t.control,
            name: i,
            keyName: a = "id",
            shouldUnregister: n,
          } = e,
          [u, o] = s.useState(r._getFieldArray(i)),
          d = s.useRef(r._getFieldArray(i).map(generateId)),
          c = s.useRef(u),
          f = s.useRef(i),
          g = s.useRef(!1);
        (f.current = i),
          (c.current = u),
          r._names.array.add(i),
          e.rules && r.register(i, e.rules),
          useSubscribe({
            next: ({ values: e, name: t }) => {
              if (t === f.current || !t) {
                let t = get(e, f.current);
                Array.isArray(t) && (o(t), (d.current = t.map(generateId)));
              }
            },
            subject: r._subjects.array,
          });
        let y = s.useCallback(
          (e) => {
            (g.current = !0), r._updateFieldArray(i, e);
          },
          [r, i]
        );
        return (
          s.useEffect(() => {
            if (
              ((r._state.action = !1),
              isWatched(i, r._names) &&
                r._subjects.state.next({ ...r._formState }),
              g.current &&
                (!getValidationModes(r._options.mode).isOnSubmit ||
                  r._formState.isSubmitted))
            ) {
              if (r._options.resolver)
                r._executeSchema([i]).then((e) => {
                  let t = get(e.errors, i),
                    s = get(r._formState.errors, i);
                  (s
                    ? (!t && s.type) ||
                      (t && (s.type !== t.type || s.message !== t.message))
                    : t && t.type) &&
                    (t
                      ? set(r._formState.errors, i, t)
                      : unset(r._formState.errors, i),
                    r._subjects.state.next({ errors: r._formState.errors }));
                });
              else {
                let e = get(r._fields, i);
                e &&
                  e._f &&
                  !(
                    getValidationModes(r._options.reValidateMode).isOnSubmit &&
                    getValidationModes(r._options.mode).isOnSubmit
                  ) &&
                  validateField(
                    e,
                    r._formValues,
                    r._options.criteriaMode === l.all,
                    r._options.shouldUseNativeValidation,
                    !0
                  ).then(
                    (e) =>
                      !isEmptyObject(e) &&
                      r._subjects.state.next({
                        errors: updateFieldArrayRootError(
                          r._formState.errors,
                          e,
                          i
                        ),
                      })
                  );
              }
            }
            r._subjects.values.next({ name: i, values: { ...r._formValues } }),
              r._names.focus &&
                iterateFieldsByAction(r._fields, (e, t) => {
                  if (r._names.focus && t.startsWith(r._names.focus) && e.focus)
                    return e.focus(), 1;
                }),
              (r._names.focus = ""),
              r._updateValid(),
              (g.current = !1);
          }, [u, i, r]),
          s.useEffect(
            () => (
              get(r._formValues, i) || r._updateFieldArray(i),
              () => {
                (r._options.shouldUnregister || n) && r.unregister(i);
              }
            ),
            [i, r, a, n]
          ),
          {
            swap: s.useCallback(
              (e, t) => {
                let s = r._getFieldArray(i);
                swapArrayAt(s, e, t),
                  swapArrayAt(d.current, e, t),
                  y(s),
                  o(s),
                  r._updateFieldArray(
                    i,
                    s,
                    swapArrayAt,
                    { argA: e, argB: t },
                    !1
                  );
              },
              [y, i, r]
            ),
            move: s.useCallback(
              (e, t) => {
                let s = r._getFieldArray(i);
                moveArrayAt(s, e, t),
                  moveArrayAt(d.current, e, t),
                  y(s),
                  o(s),
                  r._updateFieldArray(
                    i,
                    s,
                    moveArrayAt,
                    { argA: e, argB: t },
                    !1
                  );
              },
              [y, i, r]
            ),
            prepend: s.useCallback(
              (e, t) => {
                let s = convertToArrayPayload(cloneObject(e)),
                  a = prependAt(r._getFieldArray(i), s);
                (r._names.focus = getFocusFieldName(i, 0, t)),
                  (d.current = prependAt(d.current, s.map(generateId))),
                  y(a),
                  o(a),
                  r._updateFieldArray(i, a, prependAt, {
                    argA: fillEmptyArray(e),
                  });
              },
              [y, i, r]
            ),
            append: s.useCallback(
              (e, t) => {
                let s = convertToArrayPayload(cloneObject(e)),
                  a = appendAt(r._getFieldArray(i), s);
                (r._names.focus = getFocusFieldName(i, a.length - 1, t)),
                  (d.current = appendAt(d.current, s.map(generateId))),
                  y(a),
                  o(a),
                  r._updateFieldArray(i, a, appendAt, {
                    argA: fillEmptyArray(e),
                  });
              },
              [y, i, r]
            ),
            remove: s.useCallback(
              (e) => {
                let t = removeArrayAt(r._getFieldArray(i), e);
                (d.current = removeArrayAt(d.current, e)),
                  y(t),
                  o(t),
                  r._updateFieldArray(i, t, removeArrayAt, { argA: e });
              },
              [y, i, r]
            ),
            insert: s.useCallback(
              (e, t, s) => {
                let a = convertToArrayPayload(cloneObject(t)),
                  l = insert(r._getFieldArray(i), e, a);
                (r._names.focus = getFocusFieldName(i, e, s)),
                  (d.current = insert(d.current, e, a.map(generateId))),
                  y(l),
                  o(l),
                  r._updateFieldArray(i, l, insert, {
                    argA: e,
                    argB: fillEmptyArray(t),
                  });
              },
              [y, i, r]
            ),
            update: s.useCallback(
              (e, t) => {
                let s = cloneObject(t),
                  a = updateAt(r._getFieldArray(i), e, s);
                (d.current = [...a].map((t, r) =>
                  t && r !== e ? d.current[r] : generateId()
                )),
                  y(a),
                  o([...a]),
                  r._updateFieldArray(
                    i,
                    a,
                    updateAt,
                    { argA: e, argB: s },
                    !0,
                    !1
                  );
              },
              [y, i, r]
            ),
            replace: s.useCallback(
              (e) => {
                let t = convertToArrayPayload(cloneObject(e));
                (d.current = t.map(generateId)),
                  y([...t]),
                  o([...t]),
                  r._updateFieldArray(i, [...t], (e) => e, {}, !0, !1);
              },
              [y, i, r]
            ),
            fields: s.useMemo(
              () =>
                u.map((e, t) => ({ ...e, [a]: d.current[t] || generateId() })),
              [u, a]
            ),
          }
        );
      }
      var createSubject = () => {
          let e = [];
          return {
            get observers() {
              return e;
            },
            next: (t) => {
              for (let r of e) r.next && r.next(t);
            },
            subscribe: (t) => (
              e.push(t),
              {
                unsubscribe: () => {
                  e = e.filter((e) => e !== t);
                },
              }
            ),
            unsubscribe: () => {
              e = [];
            },
          };
        },
        isPrimitive = (e) => isNullOrUndefined(e) || !isObjectType(e);
      function deepEqual(e, t) {
        if (isPrimitive(e) || isPrimitive(t)) return e === t;
        if (isDateObject(e) && isDateObject(t))
          return e.getTime() === t.getTime();
        let r = Object.keys(e),
          s = Object.keys(t);
        if (r.length !== s.length) return !1;
        for (let i of r) {
          let r = e[i];
          if (!s.includes(i)) return !1;
          if ("ref" !== i) {
            let e = t[i];
            if (
              (isDateObject(r) && isDateObject(e)) ||
              (isObject(r) && isObject(e)) ||
              (Array.isArray(r) && Array.isArray(e))
                ? !deepEqual(r, e)
                : r !== e
            )
              return !1;
          }
        }
        return !0;
      }
      var isMultipleSelect = (e) => "select-multiple" === e.type,
        isRadioOrCheckbox = (e) => isRadioInput(e) || isCheckBoxInput(e),
        live = (e) => isHTMLElement(e) && e.isConnected,
        objectHasFunction = (e) => {
          for (let t in e) if (isFunction(e[t])) return !0;
          return !1;
        };
      function markFieldsDirty(e, t = {}) {
        let r = Array.isArray(e);
        if (isObject(e) || r)
          for (let r in e)
            Array.isArray(e[r]) || (isObject(e[r]) && !objectHasFunction(e[r]))
              ? ((t[r] = Array.isArray(e[r]) ? [] : {}),
                markFieldsDirty(e[r], t[r]))
              : isNullOrUndefined(e[r]) || (t[r] = !0);
        return t;
      }
      var getDirtyFields = (e, t) =>
          (function getDirtyFieldsFromDefaultValues(e, t, r) {
            let s = Array.isArray(e);
            if (isObject(e) || s)
              for (let s in e)
                Array.isArray(e[s]) ||
                (isObject(e[s]) && !objectHasFunction(e[s]))
                  ? isUndefined(t) || isPrimitive(r[s])
                    ? (r[s] = Array.isArray(e[s])
                        ? markFieldsDirty(e[s], [])
                        : { ...markFieldsDirty(e[s]) })
                    : getDirtyFieldsFromDefaultValues(
                        e[s],
                        isNullOrUndefined(t) ? {} : t[s],
                        r[s]
                      )
                  : (r[s] = !deepEqual(e[s], t[s]));
            return r;
          })(e, t, markFieldsDirty(t)),
        getFieldValueAs = (
          e,
          { valueAsNumber: t, valueAsDate: r, setValueAs: s }
        ) =>
          isUndefined(e)
            ? e
            : t
            ? "" === e
              ? NaN
              : e
              ? +e
              : e
            : r && isString(e)
            ? new Date(e)
            : s
            ? s(e)
            : e;
      function getFieldValue(e) {
        let t = e.ref;
        return (e.refs ? e.refs.every((e) => e.disabled) : t.disabled)
          ? void 0
          : isFileInput(t)
          ? t.files
          : isRadioInput(t)
          ? getRadioValue(e.refs).value
          : isMultipleSelect(t)
          ? [...t.selectedOptions].map(({ value: e }) => e)
          : isCheckBoxInput(t)
          ? getCheckboxValue(e.refs).value
          : getFieldValueAs(isUndefined(t.value) ? e.ref.value : t.value, e);
      }
      var getResolverOptions = (e, t, r, s) => {
          let i = {};
          for (let r of e) {
            let e = get(t, r);
            e && set(i, r, e._f);
          }
          return {
            criteriaMode: r,
            names: [...e],
            fields: i,
            shouldUseNativeValidation: s,
          };
        },
        getRuleValue = (e) =>
          isUndefined(e)
            ? e
            : isRegex(e)
            ? e.source
            : isObject(e)
            ? isRegex(e.value)
              ? e.value.source
              : e.value
            : e,
        hasValidation = (e) =>
          e.mount &&
          (e.required ||
            e.min ||
            e.max ||
            e.maxLength ||
            e.minLength ||
            e.pattern ||
            e.validate);
      function schemaErrorLookup(e, t, r) {
        let s = get(e, r);
        if (s || isKey(r)) return { error: s, name: r };
        let i = r.split(".");
        for (; i.length; ) {
          let s = i.join("."),
            a = get(t, s),
            l = get(e, s);
          if (a && !Array.isArray(a) && r !== s) break;
          if (l && l.type) return { name: s, error: l };
          i.pop();
        }
        return { name: r };
      }
      var skipValidation = (e, t, r, s, i) =>
          !i.isOnAll &&
          (!r && i.isOnTouch
            ? !(t || e)
            : (r ? s.isOnBlur : i.isOnBlur)
            ? !e
            : (r ? !s.isOnChange : !i.isOnChange) || e),
        unsetEmptyArray = (e, t) => !compact(get(e, t)).length && unset(e, t);
      let f = {
        mode: l.onSubmit,
        reValidateMode: l.onChange,
        shouldFocusError: !0,
      };
      function useForm(e = {}) {
        let t = s.useRef(),
          r = s.useRef(),
          [n, u] = s.useState({
            isDirty: !1,
            isValidating: !1,
            isLoading: isFunction(e.defaultValues),
            isSubmitted: !1,
            isSubmitting: !1,
            isSubmitSuccessful: !1,
            isValid: !1,
            submitCount: 0,
            dirtyFields: {},
            touchedFields: {},
            errors: e.errors || {},
            disabled: e.disabled || !1,
            defaultValues: isFunction(e.defaultValues)
              ? void 0
              : e.defaultValues,
          });
        t.current ||
          (t.current = {
            ...(function (e = {}, t) {
              let r,
                s = { ...f, ...e },
                n = {
                  submitCount: 0,
                  isDirty: !1,
                  isLoading: isFunction(s.defaultValues),
                  isValidating: !1,
                  isSubmitted: !1,
                  isSubmitting: !1,
                  isSubmitSuccessful: !1,
                  isValid: !1,
                  touchedFields: {},
                  dirtyFields: {},
                  errors: s.errors || {},
                  disabled: s.disabled || !1,
                },
                u = {},
                o =
                  ((isObject(s.values) || isObject(s.defaultValues)) &&
                    cloneObject(s.values || s.defaultValues)) ||
                  {},
                d = s.shouldUnregister ? {} : cloneObject(o),
                c = { action: !1, mount: !1, watch: !1 },
                g = {
                  mount: new Set(),
                  unMount: new Set(),
                  array: new Set(),
                  watch: new Set(),
                },
                y = 0,
                m = {
                  isDirty: !1,
                  dirtyFields: !1,
                  touchedFields: !1,
                  isValidating: !1,
                  isValid: !1,
                  errors: !1,
                },
                p = {
                  values: createSubject(),
                  array: createSubject(),
                  state: createSubject(),
                },
                b = getValidationModes(s.mode),
                h = getValidationModes(s.reValidateMode),
                _ = s.criteriaMode === l.all,
                debounce = (e) => (t) => {
                  clearTimeout(y), (y = setTimeout(e, t));
                },
                _updateValid = async (e) => {
                  if (m.isValid || e) {
                    let e = s.resolver
                      ? isEmptyObject((await _executeSchema()).errors)
                      : await executeBuiltInValidation(u, !0);
                    e !== n.isValid && p.state.next({ isValid: e });
                  }
                },
                _updateIsValidating = (e) =>
                  m.isValidating && p.state.next({ isValidating: e }),
                updateErrors = (e, t) => {
                  set(n.errors, e, t), p.state.next({ errors: n.errors });
                },
                updateValidAndValue = (e, t, r, s) => {
                  let i = get(u, e);
                  if (i) {
                    let a = get(d, e, isUndefined(r) ? get(o, e) : r);
                    isUndefined(a) || (s && s.defaultChecked) || t
                      ? set(d, e, t ? a : getFieldValue(i._f))
                      : setFieldValue(e, a),
                      c.mount && _updateValid();
                  }
                },
                updateTouchAndDirty = (e, t, r, s, i) => {
                  let a = !1,
                    l = !1,
                    d = { name: e },
                    c = !!(get(u, e) && get(u, e)._f.disabled);
                  if (!r || s) {
                    m.isDirty &&
                      ((l = n.isDirty),
                      (n.isDirty = d.isDirty = _getDirty()),
                      (a = l !== d.isDirty));
                    let r = c || deepEqual(get(o, e), t);
                    (l = !!(!c && get(n.dirtyFields, e))),
                      r || c
                        ? unset(n.dirtyFields, e)
                        : set(n.dirtyFields, e, !0),
                      (d.dirtyFields = n.dirtyFields),
                      (a = a || (m.dirtyFields && !r !== l));
                  }
                  if (r) {
                    let t = get(n.touchedFields, e);
                    t ||
                      (set(n.touchedFields, e, r),
                      (d.touchedFields = n.touchedFields),
                      (a = a || (m.touchedFields && t !== r)));
                  }
                  return a && i && p.state.next(d), a ? d : {};
                },
                shouldRenderByError = (t, s, i, a) => {
                  let l = get(n.errors, t),
                    u = m.isValid && isBoolean(s) && n.isValid !== s;
                  if (
                    (e.delayError && i
                      ? (r = debounce(() => updateErrors(t, i)))(e.delayError)
                      : (clearTimeout(y),
                        (r = null),
                        i ? set(n.errors, t, i) : unset(n.errors, t)),
                    (i ? !deepEqual(l, i) : l) || !isEmptyObject(a) || u)
                  ) {
                    let e = {
                      ...a,
                      ...(u && isBoolean(s) ? { isValid: s } : {}),
                      errors: n.errors,
                      name: t,
                    };
                    (n = { ...n, ...e }), p.state.next(e);
                  }
                  _updateIsValidating(!1);
                },
                _executeSchema = async (e) =>
                  s.resolver(
                    d,
                    s.context,
                    getResolverOptions(
                      e || g.mount,
                      u,
                      s.criteriaMode,
                      s.shouldUseNativeValidation
                    )
                  ),
                executeSchemaAndUpdateState = async (e) => {
                  let { errors: t } = await _executeSchema(e);
                  if (e)
                    for (let r of e) {
                      let e = get(t, r);
                      e ? set(n.errors, r, e) : unset(n.errors, r);
                    }
                  else n.errors = t;
                  return t;
                },
                executeBuiltInValidation = async (e, t, r = { valid: !0 }) => {
                  for (let i in e) {
                    let a = e[i];
                    if (a) {
                      let { _f: e, ...i } = a;
                      if (e) {
                        let i = g.array.has(e.name),
                          l = await validateField(
                            a,
                            d,
                            _,
                            s.shouldUseNativeValidation && !t,
                            i
                          );
                        if (l[e.name] && ((r.valid = !1), t)) break;
                        t ||
                          (get(l, e.name)
                            ? i
                              ? updateFieldArrayRootError(n.errors, l, e.name)
                              : set(n.errors, e.name, l[e.name])
                            : unset(n.errors, e.name));
                      }
                      i && (await executeBuiltInValidation(i, t, r));
                    }
                  }
                  return r.valid;
                },
                _getDirty = (e, t) => (
                  e && t && set(d, e, t), !deepEqual(getValues(), o)
                ),
                _getWatch = (e, t, r) =>
                  generateWatchOutput(
                    e,
                    g,
                    {
                      ...(c.mount
                        ? d
                        : isUndefined(t)
                        ? o
                        : isString(e)
                        ? { [e]: t }
                        : t),
                    },
                    r,
                    t
                  ),
                setFieldValue = (e, t, r = {}) => {
                  let s = get(u, e),
                    i = t;
                  if (s) {
                    let r = s._f;
                    r &&
                      (r.disabled || set(d, e, getFieldValueAs(t, r)),
                      (i =
                        isHTMLElement(r.ref) && isNullOrUndefined(t) ? "" : t),
                      isMultipleSelect(r.ref)
                        ? [...r.ref.options].forEach(
                            (e) => (e.selected = i.includes(e.value))
                          )
                        : r.refs
                        ? isCheckBoxInput(r.ref)
                          ? r.refs.length > 1
                            ? r.refs.forEach(
                                (e) =>
                                  (!e.defaultChecked || !e.disabled) &&
                                  (e.checked = Array.isArray(i)
                                    ? !!i.find((t) => t === e.value)
                                    : i === e.value)
                              )
                            : r.refs[0] && (r.refs[0].checked = !!i)
                          : r.refs.forEach((e) => (e.checked = e.value === i))
                        : isFileInput(r.ref)
                        ? (r.ref.value = "")
                        : ((r.ref.value = i),
                          r.ref.type ||
                            p.values.next({ name: e, values: { ...d } })));
                  }
                  (r.shouldDirty || r.shouldTouch) &&
                    updateTouchAndDirty(e, i, r.shouldTouch, r.shouldDirty, !0),
                    r.shouldValidate && trigger(e);
                },
                setValues = (e, t, r) => {
                  for (let s in t) {
                    let i = t[s],
                      a = `${e}.${s}`,
                      l = get(u, a);
                    (!g.array.has(e) && isPrimitive(i) && (!l || l._f)) ||
                    isDateObject(i)
                      ? setFieldValue(a, i, r)
                      : setValues(a, i, r);
                  }
                },
                setValue = (e, r, s = {}) => {
                  let i = get(u, e),
                    a = g.array.has(e),
                    l = cloneObject(r);
                  set(d, e, l),
                    a
                      ? (p.array.next({ name: e, values: { ...d } }),
                        (m.isDirty || m.dirtyFields) &&
                          s.shouldDirty &&
                          p.state.next({
                            name: e,
                            dirtyFields: getDirtyFields(o, d),
                            isDirty: _getDirty(e, l),
                          }))
                      : !i || i._f || isNullOrUndefined(l)
                      ? setFieldValue(e, l, s)
                      : setValues(e, l, s),
                    isWatched(e, g) && p.state.next({ ...n }),
                    p.values.next({ name: e, values: { ...d } }),
                    c.mount || t();
                },
                onChange = async (e) => {
                  let t = e.target,
                    i = t.name,
                    l = !0,
                    o = get(u, i),
                    _updateIsFieldValueUpdated = (e) => {
                      l = Number.isNaN(e) || e === get(d, i, e);
                    };
                  if (o) {
                    let c, f;
                    let y = t.type ? getFieldValue(o._f) : getEventValue(e),
                      v = e.type === a.BLUR || e.type === a.FOCUS_OUT,
                      A =
                        (!hasValidation(o._f) &&
                          !s.resolver &&
                          !get(n.errors, i) &&
                          !o._f.deps) ||
                        skipValidation(
                          v,
                          get(n.touchedFields, i),
                          n.isSubmitted,
                          h,
                          b
                        ),
                      V = isWatched(i, g, v);
                    set(d, i, y),
                      v
                        ? (o._f.onBlur && o._f.onBlur(e), r && r(0))
                        : o._f.onChange && o._f.onChange(e);
                    let F = updateTouchAndDirty(i, y, v, !1),
                      x = !isEmptyObject(F) || V;
                    if (
                      (v ||
                        p.values.next({
                          name: i,
                          type: e.type,
                          values: { ...d },
                        }),
                      A)
                    )
                      return (
                        m.isValid && _updateValid(),
                        x && p.state.next({ name: i, ...(V ? {} : F) })
                      );
                    if (
                      (!v && V && p.state.next({ ...n }),
                      _updateIsValidating(!0),
                      s.resolver)
                    ) {
                      let { errors: e } = await _executeSchema([i]);
                      if ((_updateIsFieldValueUpdated(y), l)) {
                        let t = schemaErrorLookup(n.errors, u, i),
                          r = schemaErrorLookup(e, u, t.name || i);
                        (c = r.error), (i = r.name), (f = isEmptyObject(e));
                      }
                    } else
                      (c = (
                        await validateField(
                          o,
                          d,
                          _,
                          s.shouldUseNativeValidation
                        )
                      )[i]),
                        _updateIsFieldValueUpdated(y),
                        l &&
                          (c
                            ? (f = !1)
                            : m.isValid &&
                              (f = await executeBuiltInValidation(u, !0)));
                    l &&
                      (o._f.deps && trigger(o._f.deps),
                      shouldRenderByError(i, f, c, F));
                  }
                },
                _focusInput = (e, t) => {
                  if (get(n.errors, t) && e.focus) return e.focus(), 1;
                },
                trigger = async (e, t = {}) => {
                  let r, i;
                  let a = convertToArrayPayload(e);
                  if ((_updateIsValidating(!0), s.resolver)) {
                    let t = await executeSchemaAndUpdateState(
                      isUndefined(e) ? e : a
                    );
                    (r = isEmptyObject(t)),
                      (i = e ? !a.some((e) => get(t, e)) : r);
                  } else
                    e
                      ? ((i = (
                          await Promise.all(
                            a.map(async (e) => {
                              let t = get(u, e);
                              return await executeBuiltInValidation(
                                t && t._f ? { [e]: t } : t
                              );
                            })
                          )
                        ).every(Boolean)) ||
                          n.isValid) &&
                        _updateValid()
                      : (i = r = await executeBuiltInValidation(u));
                  return (
                    p.state.next({
                      ...(!isString(e) || (m.isValid && r !== n.isValid)
                        ? {}
                        : { name: e }),
                      ...(s.resolver || !e ? { isValid: r } : {}),
                      errors: n.errors,
                      isValidating: !1,
                    }),
                    t.shouldFocus &&
                      !i &&
                      iterateFieldsByAction(u, _focusInput, e ? a : g.mount),
                    i
                  );
                },
                getValues = (e) => {
                  let t = { ...o, ...(c.mount ? d : {}) };
                  return isUndefined(e)
                    ? t
                    : isString(e)
                    ? get(t, e)
                    : e.map((e) => get(t, e));
                },
                getFieldState = (e, t) => ({
                  invalid: !!get((t || n).errors, e),
                  isDirty: !!get((t || n).dirtyFields, e),
                  isTouched: !!get((t || n).touchedFields, e),
                  error: get((t || n).errors, e),
                }),
                setError = (e, t, r) => {
                  let s = (get(u, e, { _f: {} })._f || {}).ref;
                  set(n.errors, e, { ...t, ref: s }),
                    p.state.next({ name: e, errors: n.errors, isValid: !1 }),
                    r && r.shouldFocus && s && s.focus && s.focus();
                },
                unregister = (e, t = {}) => {
                  for (let r of e ? convertToArrayPayload(e) : g.mount)
                    g.mount.delete(r),
                      g.array.delete(r),
                      t.keepValue || (unset(u, r), unset(d, r)),
                      t.keepError || unset(n.errors, r),
                      t.keepDirty || unset(n.dirtyFields, r),
                      t.keepTouched || unset(n.touchedFields, r),
                      s.shouldUnregister || t.keepDefaultValue || unset(o, r);
                  p.values.next({ values: { ...d } }),
                    p.state.next({
                      ...n,
                      ...(t.keepDirty ? { isDirty: _getDirty() } : {}),
                    }),
                    t.keepIsValid || _updateValid();
                },
                _updateDisabledField = ({
                  disabled: e,
                  name: t,
                  field: r,
                  fields: s,
                  value: i,
                }) => {
                  if (isBoolean(e)) {
                    let a = e
                      ? void 0
                      : isUndefined(i)
                      ? getFieldValue(r ? r._f : get(s, t)._f)
                      : i;
                    set(d, t, a), updateTouchAndDirty(t, a, !1, !1, !0);
                  }
                },
                register = (e, t = {}) => {
                  let r = get(u, e),
                    i = isBoolean(t.disabled);
                  return (
                    set(u, e, {
                      ...(r || {}),
                      _f: {
                        ...(r && r._f ? r._f : { ref: { name: e } }),
                        name: e,
                        mount: !0,
                        ...t,
                      },
                    }),
                    g.mount.add(e),
                    r
                      ? _updateDisabledField({
                          field: r,
                          disabled: t.disabled,
                          name: e,
                          value: t.value,
                        })
                      : updateValidAndValue(e, !0, t.value),
                    {
                      ...(i ? { disabled: t.disabled } : {}),
                      ...(s.progressive
                        ? {
                            required: !!t.required,
                            min: getRuleValue(t.min),
                            max: getRuleValue(t.max),
                            minLength: getRuleValue(t.minLength),
                            maxLength: getRuleValue(t.maxLength),
                            pattern: getRuleValue(t.pattern),
                          }
                        : {}),
                      name: e,
                      onChange,
                      onBlur: onChange,
                      ref: (i) => {
                        if (i) {
                          register(e, t), (r = get(u, e));
                          let s =
                              (isUndefined(i.value) &&
                                i.querySelectorAll &&
                                i.querySelectorAll(
                                  "input,select,textarea"
                                )[0]) ||
                              i,
                            a = isRadioOrCheckbox(s),
                            l = r._f.refs || [];
                          (a ? l.find((e) => e === s) : s === r._f.ref) ||
                            (set(u, e, {
                              _f: {
                                ...r._f,
                                ...(a
                                  ? {
                                      refs: [
                                        ...l.filter(live),
                                        s,
                                        ...(Array.isArray(get(o, e))
                                          ? [{}]
                                          : []),
                                      ],
                                      ref: { type: s.type, name: e },
                                    }
                                  : { ref: s }),
                              },
                            }),
                            updateValidAndValue(e, !1, void 0, s));
                        } else
                          (r = get(u, e, {}))._f && (r._f.mount = !1),
                            (s.shouldUnregister || t.shouldUnregister) &&
                              !(isNameInFieldArray(g.array, e) && c.action) &&
                              g.unMount.add(e);
                      },
                    }
                  );
                },
                _focusError = () =>
                  s.shouldFocusError &&
                  iterateFieldsByAction(u, _focusInput, g.mount),
                handleSubmit = (e, t) => async (r) => {
                  let i;
                  r &&
                    (r.preventDefault && r.preventDefault(),
                    r.persist && r.persist());
                  let a = cloneObject(d);
                  if ((p.state.next({ isSubmitting: !0 }), s.resolver)) {
                    let { errors: e, values: t } = await _executeSchema();
                    (n.errors = e), (a = t);
                  } else await executeBuiltInValidation(u);
                  if ((unset(n.errors, "root"), isEmptyObject(n.errors))) {
                    p.state.next({ errors: {} });
                    try {
                      await e(a, r);
                    } catch (e) {
                      i = e;
                    }
                  } else
                    t && (await t({ ...n.errors }, r)),
                      _focusError(),
                      setTimeout(_focusError);
                  if (
                    (p.state.next({
                      isSubmitted: !0,
                      isSubmitting: !1,
                      isSubmitSuccessful: isEmptyObject(n.errors) && !i,
                      submitCount: n.submitCount + 1,
                      errors: n.errors,
                    }),
                    i)
                  )
                    throw i;
                },
                _reset = (r, s = {}) => {
                  let a = r ? cloneObject(r) : o,
                    l = cloneObject(a),
                    f = r && !isEmptyObject(r) ? l : o;
                  if ((s.keepDefaultValues || (o = a), !s.keepValues)) {
                    if (s.keepDirtyValues)
                      for (let e of g.mount)
                        get(n.dirtyFields, e)
                          ? set(f, e, get(d, e))
                          : setValue(e, get(f, e));
                    else {
                      if (i && isUndefined(r))
                        for (let e of g.mount) {
                          let t = get(u, e);
                          if (t && t._f) {
                            let e = Array.isArray(t._f.refs)
                              ? t._f.refs[0]
                              : t._f.ref;
                            if (isHTMLElement(e)) {
                              let t = e.closest("form");
                              if (t) {
                                t.reset();
                                break;
                              }
                            }
                          }
                        }
                      u = {};
                    }
                    (d = e.shouldUnregister
                      ? s.keepDefaultValues
                        ? cloneObject(o)
                        : {}
                      : cloneObject(f)),
                      p.array.next({ values: { ...f } }),
                      p.values.next({ values: { ...f } });
                  }
                  (g = {
                    mount: new Set(),
                    unMount: new Set(),
                    array: new Set(),
                    watch: new Set(),
                    watchAll: !1,
                    focus: "",
                  }),
                    c.mount || t(),
                    (c.mount =
                      !m.isValid || !!s.keepIsValid || !!s.keepDirtyValues),
                    (c.watch = !!e.shouldUnregister),
                    p.state.next({
                      submitCount: s.keepSubmitCount ? n.submitCount : 0,
                      isDirty: s.keepDirty
                        ? n.isDirty
                        : !!(s.keepDefaultValues && !deepEqual(r, o)),
                      isSubmitted: !!s.keepIsSubmitted && n.isSubmitted,
                      dirtyFields: s.keepDirtyValues
                        ? s.keepDefaultValues && d
                          ? getDirtyFields(o, d)
                          : n.dirtyFields
                        : s.keepDefaultValues && r
                        ? getDirtyFields(o, r)
                        : {},
                      touchedFields: s.keepTouched ? n.touchedFields : {},
                      errors: s.keepErrors ? n.errors : {},
                      isSubmitSuccessful:
                        !!s.keepIsSubmitSuccessful && n.isSubmitSuccessful,
                      isSubmitting: !1,
                    });
                },
                reset = (e, t) => _reset(isFunction(e) ? e(d) : e, t);
              return {
                control: {
                  register,
                  unregister,
                  getFieldState,
                  handleSubmit,
                  setError,
                  _executeSchema,
                  _getWatch,
                  _getDirty,
                  _updateValid,
                  _removeUnmounted: () => {
                    for (let e of g.unMount) {
                      let t = get(u, e);
                      t &&
                        (t._f.refs
                          ? t._f.refs.every((e) => !live(e))
                          : !live(t._f.ref)) &&
                        unregister(e);
                    }
                    g.unMount = new Set();
                  },
                  _updateFieldArray: (e, t = [], r, s, i = !0, a = !0) => {
                    if (s && r) {
                      if (((c.action = !0), a && Array.isArray(get(u, e)))) {
                        let t = r(get(u, e), s.argA, s.argB);
                        i && set(u, e, t);
                      }
                      if (a && Array.isArray(get(n.errors, e))) {
                        let t = r(get(n.errors, e), s.argA, s.argB);
                        i && set(n.errors, e, t), unsetEmptyArray(n.errors, e);
                      }
                      if (
                        m.touchedFields &&
                        a &&
                        Array.isArray(get(n.touchedFields, e))
                      ) {
                        let t = r(get(n.touchedFields, e), s.argA, s.argB);
                        i && set(n.touchedFields, e, t);
                      }
                      m.dirtyFields && (n.dirtyFields = getDirtyFields(o, d)),
                        p.state.next({
                          name: e,
                          isDirty: _getDirty(e, t),
                          dirtyFields: n.dirtyFields,
                          errors: n.errors,
                          isValid: n.isValid,
                        });
                    } else set(d, e, t);
                  },
                  _updateDisabledField,
                  _getFieldArray: (t) =>
                    compact(
                      get(
                        c.mount ? d : o,
                        t,
                        e.shouldUnregister ? get(o, t, []) : []
                      )
                    ),
                  _reset,
                  _resetDefaultValues: () =>
                    isFunction(s.defaultValues) &&
                    s.defaultValues().then((e) => {
                      reset(e, s.resetOptions), p.state.next({ isLoading: !1 });
                    }),
                  _updateFormState: (e) => {
                    n = { ...n, ...e };
                  },
                  _disableForm: (e) => {
                    isBoolean(e) &&
                      (p.state.next({ disabled: e }),
                      iterateFieldsByAction(
                        u,
                        (t, r) => {
                          let s = e,
                            i = get(u, r);
                          i &&
                            isBoolean(i._f.disabled) &&
                            (s || (s = i._f.disabled)),
                            (t.disabled = s);
                        },
                        0,
                        !1
                      ));
                  },
                  _subjects: p,
                  _proxyFormState: m,
                  _setErrors: (e) => {
                    (n.errors = e),
                      p.state.next({ errors: n.errors, isValid: !1 });
                  },
                  get _fields() {
                    return u;
                  },
                  get _formValues() {
                    return d;
                  },
                  get _state() {
                    return c;
                  },
                  set _state(value) {
                    c = value;
                  },
                  get _defaultValues() {
                    return o;
                  },
                  get _names() {
                    return g;
                  },
                  set _names(value) {
                    g = value;
                  },
                  get _formState() {
                    return n;
                  },
                  set _formState(value) {
                    n = value;
                  },
                  get _options() {
                    return s;
                  },
                  set _options(value) {
                    s = { ...s, ...value };
                  },
                },
                trigger,
                register,
                handleSubmit,
                watch: (e, t) =>
                  isFunction(e)
                    ? p.values.subscribe({
                        next: (r) => e(_getWatch(void 0, t), r),
                      })
                    : _getWatch(e, t, !0),
                setValue,
                getValues,
                reset,
                resetField: (e, t = {}) => {
                  get(u, e) &&
                    (isUndefined(t.defaultValue)
                      ? setValue(e, cloneObject(get(o, e)))
                      : (setValue(e, t.defaultValue),
                        set(o, e, cloneObject(t.defaultValue))),
                    t.keepTouched || unset(n.touchedFields, e),
                    t.keepDirty ||
                      (unset(n.dirtyFields, e),
                      (n.isDirty = t.defaultValue
                        ? _getDirty(e, cloneObject(get(o, e)))
                        : _getDirty())),
                    !t.keepError &&
                      (unset(n.errors, e), m.isValid && _updateValid()),
                    p.state.next({ ...n }));
                },
                clearErrors: (e) => {
                  e &&
                    convertToArrayPayload(e).forEach((e) => unset(n.errors, e)),
                    p.state.next({ errors: e ? n.errors : {} });
                },
                unregister,
                setError,
                setFocus: (e, t = {}) => {
                  let r = get(u, e),
                    s = r && r._f;
                  if (s) {
                    let e = s.refs ? s.refs[0] : s.ref;
                    e.focus && (e.focus(), t.shouldSelect && e.select());
                  }
                },
                getFieldState,
              };
            })(e, () => u((e) => ({ ...e }))),
            formState: n,
          });
        let o = t.current.control;
        return (
          (o._options = e),
          useSubscribe({
            subject: o._subjects.state,
            next: (e) => {
              shouldRenderFormState(
                e,
                o._proxyFormState,
                o._updateFormState,
                !0
              ) && u({ ...o._formState });
            },
          }),
          s.useEffect(() => o._disableForm(e.disabled), [o, e.disabled]),
          s.useEffect(() => {
            if (o._proxyFormState.isDirty) {
              let e = o._getDirty();
              e !== n.isDirty && o._subjects.state.next({ isDirty: e });
            }
          }, [o, n.isDirty]),
          s.useEffect(() => {
            e.values && !deepEqual(e.values, r.current)
              ? (o._reset(e.values, o._options.resetOptions),
                (r.current = e.values),
                u((e) => ({ ...e })))
              : o._resetDefaultValues();
          }, [e.values, o]),
          s.useEffect(() => {
            e.errors && o._setErrors(e.errors);
          }, [e.errors, o]),
          s.useEffect(() => {
            o._state.mount || (o._updateValid(), (o._state.mount = !0)),
              o._state.watch &&
                ((o._state.watch = !1),
                o._subjects.state.next({ ...o._formState })),
              o._removeUnmounted();
          }),
          s.useEffect(() => {
            e.shouldUnregister &&
              o._subjects.values.next({ values: o._getWatch() });
          }, [e.shouldUnregister, o]),
          (t.current.formState = getProxyFormState(n, o)),
          t.current
        );
      }
    },
  },
]);
