"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const reactBinding = require("@contember/react-binding");
const react = require("react");
const urlMapper = require("../urlMapper.cjs");
const ROUTING_BINDING_PARAMETER_PREFIX = "entity.";
const createBindingLinkParametersResolver = (entity) => {
  return (param) => {
    if (param.startsWith(ROUTING_BINDING_PARAMETER_PREFIX)) {
      if (!entity) {
        throw new reactBinding.BindingError(`Cannot use data binding routing parameters in non-databinding context`);
      }
      return entity.getField(param.slice(ROUTING_BINDING_PARAMETER_PREFIX.length)).value ?? void 0;
    }
    throw new urlMapper.PageNotFound(`Routing parameter ${param} not found`);
  };
};
const useBindingLinkParametersResolver = () => {
  const hasEntity = reactBinding.useHasEntity();
  const entity = hasEntity ? reactBinding.useEntity() : void 0;
  return react.useMemo(
    () => createBindingLinkParametersResolver(entity),
    [entity]
  );
};
exports.ROUTING_BINDING_PARAMETER_PREFIX = ROUTING_BINDING_PARAMETER_PREFIX;
exports.createBindingLinkParametersResolver = createBindingLinkParametersResolver;
exports.useBindingLinkParametersResolver = useBindingLinkParametersResolver;
//# sourceMappingURL=useBindingLinkParametersResolver.cjs.map
