import { memo, useMemo, createElement } from "react";
import { useEntity } from "@contember/binding";
import { Link } from "../../../routing/binding/Link.js";
const PageLinkById = memo(function(props) {
  const parentEntity = useEntity();
  const id = parentEntity.id;
  const target = useMemo(() => {
    if (typeof id !== "string") {
      return null;
    }
    if ("to" in props) {
      return {
        pageName: props.to,
        parameters: {
          [props.idParameterName ?? "id"]: id
        }
      };
    }
    return () => props.change(id, parentEntity);
  }, [id, parentEntity, props]);
  if (target !== null) {
    return /* @__PURE__ */ createElement(Link, {
      to: target,
      Component: props.Component
    }, props.children);
  }
  return null;
});
export { PageLinkById };
//# sourceMappingURL=PageLinkById.js.map
