/**
 * This file is part of the NocoBase (R) project.
 * Copyright (c) 2020-2024 NocoBase Co., Ltd.
 * Authors: NocoBase Team.
 *
 * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
 * For more information, please refer to: https://www.nocobase.com/agreement.
 */

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var key_kind_exports = {};
__export(key_kind_exports, {
  assertBindKeyKind: () => assertBindKeyKind,
  buildPlanKeyKind: () => buildPlanKeyKind
});
module.exports = __toCommonJS(key_kind_exports);
var import_node_use_sets = require("../node-use-sets");
var import_approval = require("../approval");
var import_errors = require("../errors");
var import_placement = require("../placement");
var import_service_utils = require("../service-utils");
function buildPlanKeyKind(node, resolvedKind) {
  const use = String((node == null ? void 0 : node.use) || "").trim();
  const semanticUse = (0, import_approval.normalizeApprovalSemanticUse)(use);
  if (semanticUse === "RootPageModel" || resolvedKind === "page") {
    return "page";
  }
  if (semanticUse === "RootPageTabModel" || resolvedKind === "tab") {
    return "tab";
  }
  if (semanticUse === "ChildPageModel") {
    return "popupPage";
  }
  if (semanticUse === "ChildPageTabModel") {
    return "popupTab";
  }
  if (semanticUse === "BlockGridModel" || resolvedKind === "grid") {
    return "grid";
  }
  if ((0, import_placement.isPopupHostUse)(use)) {
    return "popupHost";
  }
  if (import_node_use_sets.ACTION_BUTTON_USES.has(use)) {
    return "action";
  }
  if (import_node_use_sets.FIELD_WRAPPER_USES.has(use) || import_node_use_sets.STANDALONE_FIELD_NODE_USES.has(use) || (0, import_service_utils.isFieldNodeUse)(use)) {
    return "fieldHost";
  }
  if (import_node_use_sets.COLLECTION_BLOCK_USES.has(use) || import_node_use_sets.STATIC_CONTENT_BLOCK_USES.has(use) || import_node_use_sets.JS_BLOCK_USES.has(use) || use.endsWith("BlockModel")) {
    return "block";
  }
  return resolvedKind || "node";
}
function assertBindKeyKind(actionName, bindKey, node, resolvedKind) {
  if (!bindKey.expectedKind) {
    return;
  }
  const actualKind = buildPlanKeyKind(node, resolvedKind);
  const expectedKind = String(bindKey.expectedKind || "").trim();
  const matched = expectedKind === "node" || expectedKind === actualKind || expectedKind === "block" && actualKind === "block" || expectedKind === "fieldHost" && actualKind === "fieldHost" || expectedKind === "popupHost" && actualKind === "popupHost" || expectedKind === "popupTab" && actualKind === "popupTab" || expectedKind === "action" && actualKind === "action";
  if (matched) {
    return;
  }
  (0, import_errors.throwBadRequest)(
    `flowSurfaces ${actionName} bindKeys key '${bindKey.key}' expected kind '${expectedKind}', got '${actualKind}'`
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  assertBindKeyKind,
  buildPlanKeyKind
});
