/**
 * 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 surface_exports = {};
__export(surface_exports, {
  normalizeActionType: () => normalizeActionType,
  normalizeText: () => normalizeText,
  resolveActionModelUse: () => resolveActionModelUse,
  resolveConfigureBlockType: () => resolveConfigureBlockType,
  resolveConfigureModelUse: () => resolveConfigureModelUse,
  resolveFieldModelUse: () => resolveFieldModelUse,
  resolveModelSurfaceStyle: () => resolveModelSurfaceStyle,
  resolvePublicBlockType: () => resolvePublicBlockType,
  resolveSurfaceStyle: () => resolveSurfaceStyle
});
module.exports = __toCommonJS(surface_exports);
var import_constants = require("./constants");
function resolveFieldModelUse(type, renderer, blockType) {
  if (type === "jsColumn") {
    return "JSColumnModel";
  }
  if (type === "jsItem") {
    return "JSItemModel";
  }
  if (renderer === "js") {
    return ["createForm", "editForm"].includes(blockType) ? "JSEditableFieldModel" : "JSFieldModel";
  }
  return "";
}
function resolveActionModelUse(actionType, blockType, slot) {
  if (actionType === "jsItem") {
    return "JSItemActionModel";
  }
  if (actionType !== "js") {
    return "";
  }
  if (slot === "recordActions") {
    return "JSRecordActionModel";
  }
  if (["createForm", "editForm"].includes(blockType)) {
    return "JSFormActionModel";
  }
  if (blockType === "filterForm") {
    return "FilterFormJSActionModel";
  }
  if (["table", "list", "gridCard", "calendar", "kanban"].includes(blockType)) {
    return "JSCollectionActionModel";
  }
  return "JSActionModel";
}
function resolveConfigureModelUse(currentNode) {
  var _a, _b;
  const currentUse = normalizeText(currentNode == null ? void 0 : currentNode.use);
  if (import_constants.KNOWN_MODEL_USES.has(currentUse)) {
    return currentUse;
  }
  const fieldUse = normalizeText((_b = (_a = currentNode == null ? void 0 : currentNode.subModels) == null ? void 0 : _a.field) == null ? void 0 : _b.use);
  if (import_constants.KNOWN_MODEL_USES.has(fieldUse)) {
    return fieldUse;
  }
  return "";
}
function resolveConfigureBlockType(context) {
  var _a;
  const hostBlockType = normalizeText(context.hostBlockType);
  if (hostBlockType) {
    return resolvePublicBlockType(hostBlockType);
  }
  const currentUse = normalizeText((_a = context.currentNode) == null ? void 0 : _a.use);
  return resolvePublicBlockType(currentUse);
}
function resolvePublicBlockType(value) {
  const normalized = normalizeText(value);
  return import_constants.PUBLIC_BLOCK_TYPE_BY_MODEL_USE[normalized] || normalized;
}
function resolveSurfaceStyle(input) {
  if (input.surfaceStyle) {
    return input.surfaceStyle;
  }
  const surface = normalizeText(input.surface);
  if (surface && import_constants.SURFACE_STYLE_BY_ID[surface]) {
    return import_constants.SURFACE_STYLE_BY_ID[surface];
  }
  return resolveModelSurfaceStyle(input.modelUse);
}
function resolveModelSurfaceStyle(modelUse) {
  const normalized = normalizeText(modelUse);
  if (import_constants.RENDER_MODEL_USES.has(normalized)) {
    return "render";
  }
  if (import_constants.ACTION_MODEL_USES.has(normalized)) {
    return "action";
  }
  if (import_constants.VALUE_MODEL_USES.has(normalized)) {
    return "value";
  }
  return void 0;
}
function normalizeActionType(value) {
  const normalized = normalizeText(value);
  return import_constants.ACTION_TYPE_ALIASES.get(normalized.toLowerCase()) || normalized;
}
function normalizeText(value) {
  return typeof value === "string" ? value.trim() : "";
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  normalizeActionType,
  normalizeText,
  resolveActionModelUse,
  resolveConfigureBlockType,
  resolveConfigureModelUse,
  resolveFieldModelUse,
  resolveModelSurfaceStyle,
  resolvePublicBlockType,
  resolveSurfaceStyle
});
