import { useBlocker } from "react-router-dom";
import { useSatExam } from "../stores/useSatExam";

export const useExamNavigationGuard = () => {
  const phase = useSatExam((s) => s.phase);

  const blocker = useBlocker(
    ({ currentLocation, nextLocation }) =>
      (phase === "MODULE" || phase === "BREAK") &&
      currentLocation.pathname !== nextLocation.pathname,
  );

  return blocker;
};
