import "../../../../rc-field-form/es/index.mjs";
import * as i from "react";
import d from "../../../../scroll-into-view-if-needed/dist/index.mjs";
import { getFieldId as f, toArray as l } from "../util.mjs";
import g from "../../../../rc-field-form/es/useForm.mjs";
function u(e) {
  return l(e).join("_");
}
function I(e) {
  const [r] = g(), s = i.useRef({}), a = i.useMemo(() => e ?? Object.assign(Object.assign({}, r), {
    __INTERNAL__: {
      itemRef: (n) => (t) => {
        const o = u(n);
        t ? s.current[o] = t : delete s.current[o];
      }
    },
    scrollToField: function(n) {
      let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
      const o = l(n), c = f(o, a.__INTERNAL__.name), m = c ? document.getElementById(c) : null;
      m && d(m, Object.assign({
        scrollMode: "if-needed",
        block: "nearest"
      }, t));
    },
    getFieldInstance: (n) => {
      const t = u(n);
      return s.current[t];
    }
  }), [e, r]);
  return [a];
}
export {
  I as default
};
