import { useState as p, useRef as F, useCallback as n } from "react";
import d from "../../../../../../../fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.mjs";
import { getStatus as f } from "../../get-status/get-status.mjs";
import { clearListState as O } from "../../lists/clear-list-state.mjs";
import { getPath as a } from "../../paths/get-path.mjs";
function G({
  initialDirty: y,
  initialTouched: V,
  mode: m,
  $values: s
}) {
  const [b, g] = p(V), [R, D] = p(y), u = F(V), o = F(y), S = n((t) => {
    const e = typeof t == "function" ? t(u.current) : t;
    u.current = e, m === "controlled" && g(e);
  }, []), i = n(
    (t, e = !1) => {
      const r = typeof t == "function" ? t(o.current) : t;
      o.current = r, (m === "controlled" || e) && D(r);
    },
    []
  ), T = n(() => S({}), []), k = n((t) => {
    const e = t ? { ...s.refValues.current, ...t } : s.refValues.current;
    s.setValuesSnapshot(e), i({});
  }, []), C = n((t, e) => {
    S((r) => f(r, t) === e ? r : { ...r, [t]: e });
  }, []), h = n((t, e, r) => {
    i((c) => f(c, t) === e ? c : { ...c, [t]: e }, r);
  }, []), j = n((t, e) => {
    const r = f(o.current, t), c = !d(a(t, s.getValuesSnapshot()), e), l = O(t, o.current);
    l[t] = c, i(l, r !== c);
  }, []), q = n(
    (t) => f(u.current, t),
    []
  ), w = n(
    (t) => i((e) => {
      if (typeof t != "string")
        return e;
      const r = O(t, e);
      return delete r[t], d(r, e) ? e : r;
    }),
    []
  ), x = n((t) => {
    if (t) {
      const r = a(t, o.current);
      if (typeof r == "boolean")
        return r;
      const c = a(t, s.refValues.current), l = a(t, s.valuesSnapshot.current);
      return !d(c, l);
    }
    return Object.keys(o.current).length > 0 ? f(o.current) : !d(s.refValues.current, s.valuesSnapshot.current);
  }, []), E = n(() => o.current, []), I = n(() => u.current, []);
  return {
    touchedState: b,
    dirtyState: R,
    touchedRef: u,
    dirtyRef: o,
    setTouched: S,
    setDirty: i,
    resetDirty: k,
    resetTouched: T,
    isTouched: q,
    setFieldTouched: C,
    setFieldDirty: h,
    setTouchedState: g,
    setDirtyState: D,
    clearFieldDirty: w,
    isDirty: x,
    getDirty: E,
    getTouched: I,
    setCalculatedFieldDirty: j
  };
}
export {
  G as useFormStatus
};
//# sourceMappingURL=use-form-status.mjs.map
