import { useMemo } from "react";
import { useLinkFactory, useCurrentRequest } from "@contember/react-routing";
const useEntityRedirectOnPersistSuccess = (target) => {
  const linkFactory = useLinkFactory();
  const currentRequest = useCurrentRequest();
  return useMemo(() => {
    if (!target) {
      return void 0;
    }
    return (getAccessor, options) => {
      if (options.successType === "nothingToPersist") {
        return;
      }
      const entity = getAccessor();
      const linkTarget = typeof target === "function" ? target(currentRequest, entity.id, entity, options) : target;
      if (!linkTarget) {
        return;
      }
      const link = linkFactory(linkTarget, {}, entity);
      link.navigate();
    };
  }, [currentRequest, linkFactory, target]);
};
export {
  useEntityRedirectOnPersistSuccess
};
//# sourceMappingURL=useEntityRedirectOnPersistSuccess.js.map
