import { useState as m, useRef as d, useCallback as n } from "react";
import { filterErrors as f } from "./filter-errors/filter-errors.mjs";
function R(l) {
  const [o, i] = m(f(l)), c = d(o), s = n((r) => {
    i((e) => {
      const t = f(typeof r == "function" ? r(e) : r);
      return c.current = t, t;
    });
  }, []), E = n(() => s({}), []), u = n(
    (r) => {
      c.current[r] !== void 0 && s((e) => {
        const t = { ...e };
        return delete t[r], t;
      });
    },
    [o]
  ), a = n(
    (r, e) => {
      e == null || e === !1 ? u(r) : c.current[r] !== e && s((t) => ({ ...t, [r]: e }));
    },
    [o]
  );
  return {
    errorsState: o,
    setErrors: s,
    clearErrors: E,
    setFieldError: a,
    clearFieldError: u
  };
}
export {
  R as useFormErrors
};
//# sourceMappingURL=use-form-errors.mjs.map
