/**
 * 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 action_scope_exports = {};
__export(action_scope_exports, {
  ACTION_CONTAINER_SCOPE_BY_USE: () => ACTION_CONTAINER_SCOPE_BY_USE,
  ACTION_PANEL_ACTION_CONTAINER_USES: () => ACTION_PANEL_ACTION_CONTAINER_USES,
  CALENDAR_BLOCK_ACTION_CONTAINER_USES: () => CALENDAR_BLOCK_ACTION_CONTAINER_USES,
  COLLECTION_BLOCK_ACTION_CONTAINER_USES: () => COLLECTION_BLOCK_ACTION_CONTAINER_USES,
  COMMENT_RECORD_ACTION_CONTAINER_USES: () => COMMENT_RECORD_ACTION_CONTAINER_USES,
  DETAILS_ACTION_CONTAINER_USES: () => DETAILS_ACTION_CONTAINER_USES,
  FILTER_FORM_ACTION_CONTAINER_USES: () => FILTER_FORM_ACTION_CONTAINER_USES,
  FORM_ACTION_CONTAINER_USES: () => FORM_ACTION_CONTAINER_USES,
  KANBAN_BLOCK_ACTION_CONTAINER_USES: () => KANBAN_BLOCK_ACTION_CONTAINER_USES,
  LIST_BLOCK_ACTION_CONTAINER_USES: () => LIST_BLOCK_ACTION_CONTAINER_USES,
  LIST_RECORD_ACTION_CONTAINER_USES: () => LIST_RECORD_ACTION_CONTAINER_USES,
  RECORD_ACTION_CONTAINER_USES: () => RECORD_ACTION_CONTAINER_USES,
  RECORD_HISTORY_BLOCK_ACTION_CONTAINER_USES: () => RECORD_HISTORY_BLOCK_ACTION_CONTAINER_USES,
  TABLE_BLOCK_ACTION_CONTAINER_USES: () => TABLE_BLOCK_ACTION_CONTAINER_USES,
  TABLE_ROW_ACTION_CONTAINER_USES: () => TABLE_ROW_ACTION_CONTAINER_USES,
  assertActionScopeMatchesContainer: () => assertActionScopeMatchesContainer,
  assertKnownActionContainerUse: () => assertKnownActionContainerUse,
  assertRequestedActionScope: () => assertRequestedActionScope,
  getActionContainerScope: () => getActionContainerScope,
  normalizeActionScope: () => normalizeActionScope
});
module.exports = __toCommonJS(action_scope_exports);
var import_approval = require("./approval");
var import_errors = require("./errors");
const ACTION_SCOPE_SET = /* @__PURE__ */ new Set(["block", "record", "form", "filterForm", "actionPanel"]);
const TABLE_BLOCK_ACTION_CONTAINER_USES = ["TableBlockModel"];
const CALENDAR_BLOCK_ACTION_CONTAINER_USES = ["CalendarBlockModel"];
const KANBAN_BLOCK_ACTION_CONTAINER_USES = ["KanbanBlockModel"];
const RECORD_HISTORY_BLOCK_ACTION_CONTAINER_USES = ["RecordHistoryBlockModel"];
const TABLE_ROW_ACTION_CONTAINER_USES = ["TableActionsColumnModel"];
const LIST_BLOCK_ACTION_CONTAINER_USES = ["ListBlockModel", "GridCardBlockModel"];
const LIST_RECORD_ACTION_CONTAINER_USES = ["ListItemModel", "GridCardItemModel"];
const COMMENT_RECORD_ACTION_CONTAINER_USES = ["CommentItemModel"];
const DETAILS_ACTION_CONTAINER_USES = ["DetailsBlockModel"];
const FORM_ACTION_CONTAINER_USES = ["FormBlockModel", "CreateFormModel", "EditFormModel"];
const FILTER_FORM_ACTION_CONTAINER_USES = ["FilterFormBlockModel"];
const ACTION_PANEL_ACTION_CONTAINER_USES = ["ActionPanelBlockModel"];
const COLLECTION_BLOCK_ACTION_CONTAINER_USES = [
  ...TABLE_BLOCK_ACTION_CONTAINER_USES,
  ...CALENDAR_BLOCK_ACTION_CONTAINER_USES,
  ...LIST_BLOCK_ACTION_CONTAINER_USES
];
const RECORD_ACTION_CONTAINER_USES = [
  ...TABLE_ROW_ACTION_CONTAINER_USES,
  ...DETAILS_ACTION_CONTAINER_USES,
  ...LIST_RECORD_ACTION_CONTAINER_USES
];
const ACTION_CONTAINER_SCOPE_BY_USE = Object.fromEntries([
  ...COLLECTION_BLOCK_ACTION_CONTAINER_USES.map((use) => [use, "block"]),
  ...KANBAN_BLOCK_ACTION_CONTAINER_USES.map((use) => [use, "block"]),
  ...RECORD_HISTORY_BLOCK_ACTION_CONTAINER_USES.map((use) => [use, "block"]),
  ...RECORD_ACTION_CONTAINER_USES.map((use) => [use, "record"]),
  ...COMMENT_RECORD_ACTION_CONTAINER_USES.map((use) => [use, "record"]),
  ...FORM_ACTION_CONTAINER_USES.map((use) => [use, "form"]),
  ...FILTER_FORM_ACTION_CONTAINER_USES.map((use) => [use, "filterForm"]),
  ...ACTION_PANEL_ACTION_CONTAINER_USES.map((use) => [use, "actionPanel"]),
  ...import_approval.APPROVAL_ACTION_CONTAINER_USES.map((use) => [use, "form"])
]);
function getActionContainerScope(containerUse) {
  return ACTION_CONTAINER_SCOPE_BY_USE[String(containerUse || "").trim()] || null;
}
function assertKnownActionContainerUse(input) {
  if (!input.containerUse) {
    return;
  }
  if (!getActionContainerScope(input.containerUse)) {
    throw new import_errors.FlowSurfaceBadRequestError(
      `flowSurfaces ${input.context} container '${input.containerUse}' is not a supported public action container`
    );
  }
}
function normalizeActionScope(scope) {
  if (typeof scope === "undefined" || scope === null || scope === "") {
    return void 0;
  }
  const normalized = String(scope).trim();
  if (!normalized) {
    return void 0;
  }
  if (normalized === "row") {
    throw new import_errors.FlowSurfaceBadRequestError(
      `flowSurfaces action scope 'row' is no longer supported; use 'record' and place record actions under 'recordActions' or a record action container`
    );
  }
  if (!ACTION_SCOPE_SET.has(normalized)) {
    throw new import_errors.FlowSurfaceBadRequestError(`flowSurfaces action scope '${normalized}' is not supported`);
  }
  return normalized;
}
function assertActionScopeMatchesContainer(input) {
  assertKnownActionContainerUse({
    containerUse: input.containerUse,
    context: input.context
  });
  const expectedScope = getActionContainerScope(input.containerUse);
  if (expectedScope && input.actionScope !== expectedScope) {
    throw new import_errors.FlowSurfaceBadRequestError(
      `flowSurfaces ${input.context} scope '${input.actionScope}' is not allowed under '${input.containerUse}', expected '${expectedScope}'`
    );
  }
}
function assertRequestedActionScope(input) {
  assertActionScopeMatchesContainer({
    actionScope: input.resolvedScope,
    containerUse: input.containerUse,
    context: input.context
  });
  if (input.requestedScope && input.requestedScope !== input.resolvedScope) {
    throw new import_errors.FlowSurfaceBadRequestError(
      `flowSurfaces ${input.context} scope '${input.requestedScope}' does not match resolved action scope '${input.resolvedScope}'`
    );
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ACTION_CONTAINER_SCOPE_BY_USE,
  ACTION_PANEL_ACTION_CONTAINER_USES,
  CALENDAR_BLOCK_ACTION_CONTAINER_USES,
  COLLECTION_BLOCK_ACTION_CONTAINER_USES,
  COMMENT_RECORD_ACTION_CONTAINER_USES,
  DETAILS_ACTION_CONTAINER_USES,
  FILTER_FORM_ACTION_CONTAINER_USES,
  FORM_ACTION_CONTAINER_USES,
  KANBAN_BLOCK_ACTION_CONTAINER_USES,
  LIST_BLOCK_ACTION_CONTAINER_USES,
  LIST_RECORD_ACTION_CONTAINER_USES,
  RECORD_ACTION_CONTAINER_USES,
  RECORD_HISTORY_BLOCK_ACTION_CONTAINER_USES,
  TABLE_BLOCK_ACTION_CONTAINER_USES,
  TABLE_ROW_ACTION_CONTAINER_USES,
  assertActionScopeMatchesContainer,
  assertKnownActionContainerUse,
  assertRequestedActionScope,
  getActionContainerScope,
  normalizeActionScope
});
