import { useContext as a, useRef as p, useEffect as S } from "react";
import { StepperContext as l } from "../context/StepperContext.js";
import { StepContext as m } from "../context/StepContext.js";
function w(o) {
  var s;
  const e = a(l), t = a(m), i = p(o);
  i.current = o;
  const c = (t == null ? void 0 : t.index) ?? 0, r = (s = e == null ? void 0 : e.steps[c]) == null ? void 0 : s.initialData.id, n = e == null ? void 0 : e.getStepRef, u = e !== null && t !== null && r !== void 0;
  if (S(() => {
    if (!u || !n || !r) return;
    const f = n(r);
    return f.current = {
      onBeforeLeave: (d) => i.current(d)
    }, () => {
      f.current = null;
    };
  }, [n, u, r]), !e) throw new Error("useStepperBeforeNavigate must be used inside a <StepperProvider>.");
  if (!t) throw new Error("useStepperBeforeNavigate must be used inside a child rendered by <StepperLayout>.");
}
export {
  w as default
};
//# sourceMappingURL=useStepperBeforeNavigate.js.map
