import { stringifyEntityRef } from '@backstage/catalog-model';
import { usePermission } from '@backstage/plugin-permission-react';
import { useAsyncEntity } from './useEntity.esm.js';

function useEntityPermission(permission) {
  const {
    entity,
    loading: loadingEntity,
    error: entityError
  } = useAsyncEntity();
  const {
    allowed,
    loading: loadingPermission,
    error: permissionError
  } = usePermission({
    permission,
    resourceRef: entity ? stringifyEntityRef(entity) : void 0
  });
  if (loadingEntity || loadingPermission) {
    return { loading: true, allowed: false };
  }
  if (entityError) {
    return { loading: false, allowed: false, error: entityError };
  }
  return { loading: false, allowed, error: permissionError };
}

export { useEntityPermission };
//# sourceMappingURL=useEntityPermission.esm.js.map
