"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const react = require("react");
const reactRouting = require("@contember/react-routing");
const useEntityRedirectOnPersistSuccess = (target) => {
  const linkFactory = reactRouting.useLinkFactory();
  const currentRequest = reactRouting.useCurrentRequest();
  return react.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]);
};
exports.useEntityRedirectOnPersistSuccess = useEntityRedirectOnPersistSuccess;
//# sourceMappingURL=useEntityRedirectOnPersistSuccess.cjs.map
