/**
 * 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 placement_exports = {};
__export(placement_exports, {
  FLOW_SURFACE_DETAILS_BLOCK_USES: () => FLOW_SURFACE_DETAILS_BLOCK_USES,
  FLOW_SURFACE_FIELD_WRAPPER_USES: () => FLOW_SURFACE_FIELD_WRAPPER_USES,
  FLOW_SURFACE_FILTER_FORM_BLOCK_USES: () => FLOW_SURFACE_FILTER_FORM_BLOCK_USES,
  FLOW_SURFACE_FORM_BLOCK_USES: () => FLOW_SURFACE_FORM_BLOCK_USES,
  FLOW_SURFACE_GRID_USES: () => FLOW_SURFACE_GRID_USES,
  FLOW_SURFACE_PAGE_MODEL_USES: () => FLOW_SURFACE_PAGE_MODEL_USES,
  FLOW_SURFACE_PAGE_ROUTE_TYPES: () => FLOW_SURFACE_PAGE_ROUTE_TYPES,
  FLOW_SURFACE_POPUP_HOST_USES: () => FLOW_SURFACE_POPUP_HOST_USES,
  canCatalogAddBlock: () => canCatalogAddBlock,
  isActionContainerUse: () => isActionContainerUse,
  isBlockContainerUse: () => isBlockContainerUse,
  isDetailsBlockUse: () => isDetailsBlockUse,
  isFieldContainerUse: () => isFieldContainerUse,
  isFieldWrapperUse: () => isFieldWrapperUse,
  isFilterFormBlockUse: () => isFilterFormBlockUse,
  isFormBlockUse: () => isFormBlockUse,
  isGridUse: () => isGridUse,
  isPageModelUse: () => isPageModelUse,
  isPageRouteType: () => isPageRouteType,
  isPopupHostUse: () => isPopupHostUse,
  isTabsRouteType: () => isTabsRouteType
});
module.exports = __toCommonJS(placement_exports);
var import_approval = require("./approval");
var import_node_use_sets = require("./node-use-sets");
const FLOW_SURFACE_POPUP_HOST_USES = /* @__PURE__ */ new Set([
  "AddNewActionModel",
  "ViewActionModel",
  "EditActionModel",
  "PopupCollectionActionModel",
  "AddChildActionModel",
  "CalendarQuickCreateActionModel",
  "CalendarEventViewActionModel",
  "KanbanQuickCreateActionModel",
  "KanbanCardViewActionModel",
  "ClickableFieldModel",
  "DisplayTextFieldModel",
  "DisplayEnumFieldModel",
  "DisplayDateTimeFieldModel",
  "DisplayNumberFieldModel",
  "DisplayPercentFieldModel",
  "DisplayTimeFieldModel",
  "DisplayAssociationFieldModel",
  "DisplayAssociationField",
  "DisplayTitleFieldModel",
  "DisplayURLFieldModel"
]);
const FLOW_SURFACE_FORM_BLOCK_USES = /* @__PURE__ */ new Set([
  "FormBlockModel",
  "CreateFormModel",
  "EditFormModel",
  "AssignFormModel"
]);
const FLOW_SURFACE_DETAILS_BLOCK_USES = /* @__PURE__ */ new Set(["DetailsBlockModel"]);
const FLOW_SURFACE_FILTER_FORM_BLOCK_USES = /* @__PURE__ */ new Set(["FilterFormBlockModel"]);
const FLOW_SURFACE_GRID_USES = /* @__PURE__ */ new Set([
  "BlockGridModel",
  "FormGridModel",
  "DetailsGridModel",
  "FilterFormGridModel",
  "AssignFormGridModel"
]);
const FLOW_SURFACE_FIELD_WRAPPER_USES = import_node_use_sets.FIELD_WRAPPER_USES;
const FLOW_SURFACE_PAGE_MODEL_USES = /* @__PURE__ */ new Set([
  "RootPageModel",
  "ChildPageModel",
  "RootPageTabModel",
  "ChildPageTabModel"
]);
const FLOW_SURFACE_PAGE_ROUTE_TYPES = /* @__PURE__ */ new Set(["page", "flowPage"]);
function isPopupHostUse(use) {
  return FLOW_SURFACE_POPUP_HOST_USES.has(use || "");
}
function isFormBlockUse(use) {
  return FLOW_SURFACE_FORM_BLOCK_USES.has((0, import_approval.normalizeApprovalSemanticUse)(use) || "");
}
function isDetailsBlockUse(use) {
  return FLOW_SURFACE_DETAILS_BLOCK_USES.has((0, import_approval.normalizeApprovalSemanticUse)(use) || "");
}
function isFilterFormBlockUse(use) {
  return FLOW_SURFACE_FILTER_FORM_BLOCK_USES.has((0, import_approval.normalizeApprovalSemanticUse)(use) || "");
}
function isGridUse(use) {
  return FLOW_SURFACE_GRID_USES.has((0, import_approval.normalizeApprovalSemanticUse)(use) || "");
}
function isFieldWrapperUse(use) {
  return FLOW_SURFACE_FIELD_WRAPPER_USES.has(use || "");
}
function isPageModelUse(use) {
  return FLOW_SURFACE_PAGE_MODEL_USES.has((0, import_approval.normalizeApprovalSemanticUse)(use) || "");
}
function isPageRouteType(routeLike) {
  var _a;
  const type = ((_a = routeLike == null ? void 0 : routeLike.get) == null ? void 0 : _a.call(routeLike, "type")) || (routeLike == null ? void 0 : routeLike.type);
  return FLOW_SURFACE_PAGE_ROUTE_TYPES.has(type || "");
}
function isTabsRouteType(routeLike) {
  var _a;
  const type = ((_a = routeLike == null ? void 0 : routeLike.get) == null ? void 0 : _a.call(routeLike, "type")) || (routeLike == null ? void 0 : routeLike.type);
  return type === "tabs";
}
function canCatalogAddBlock(input) {
  var _a, _b;
  const node = input.node;
  const resolved = input.resolved;
  if (!node && !resolved) {
    return true;
  }
  if ((0, import_approval.isApprovalTaskCardGridUse)(node == null ? void 0 : node.use)) {
    return false;
  }
  if (isGridUse(node == null ? void 0 : node.use) || isPageModelUse(node == null ? void 0 : node.use)) {
    return true;
  }
  if (isPopupHostUse(node == null ? void 0 : node.use) || (0, import_approval.normalizeApprovalSemanticUse)((_b = (_a = node == null ? void 0 : node.subModels) == null ? void 0 : _a.page) == null ? void 0 : _b.use) === "ChildPageModel") {
    return true;
  }
  if (!(node == null ? void 0 : node.use) && isTabsRouteType(resolved == null ? void 0 : resolved.tabRoute) || (node == null ? void 0 : node.use) === "RouteModel" && isTabsRouteType(resolved == null ? void 0 : resolved.route)) {
    return true;
  }
  if (!(node == null ? void 0 : node.use) && isPageRouteType(resolved == null ? void 0 : resolved.pageRoute) || (node == null ? void 0 : node.use) === "RouteModel" && isPageRouteType(resolved == null ? void 0 : resolved.route)) {
    return true;
  }
  return false;
}
function isFieldContainerUse(parentUse, subKey) {
  if (subKey === "columns" && parentUse === "TableBlockModel") {
    return true;
  }
  return subKey === "items" && (isGridUse(parentUse) || isFormBlockUse(parentUse) || isDetailsBlockUse(parentUse) || isFilterFormBlockUse(parentUse));
}
function isBlockContainerUse(parentUse, subKey) {
  return subKey === "items" && (isGridUse(parentUse) && !(0, import_approval.isApprovalTaskCardGridUse)(parentUse) || isPopupHostUse(parentUse));
}
function isActionContainerUse(parentUse) {
  return [
    "TableBlockModel",
    "CalendarBlockModel",
    "KanbanBlockModel",
    "TableActionsColumnModel",
    "ListBlockModel",
    "GridCardBlockModel",
    "ListItemModel",
    "GridCardItemModel",
    "ActionPanelBlockModel"
  ].includes(parentUse || "") || isFormBlockUse(parentUse) || isDetailsBlockUse(parentUse) || isFilterFormBlockUse(parentUse);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FLOW_SURFACE_DETAILS_BLOCK_USES,
  FLOW_SURFACE_FIELD_WRAPPER_USES,
  FLOW_SURFACE_FILTER_FORM_BLOCK_USES,
  FLOW_SURFACE_FORM_BLOCK_USES,
  FLOW_SURFACE_GRID_USES,
  FLOW_SURFACE_PAGE_MODEL_USES,
  FLOW_SURFACE_PAGE_ROUTE_TYPES,
  FLOW_SURFACE_POPUP_HOST_USES,
  canCatalogAddBlock,
  isActionContainerUse,
  isBlockContainerUse,
  isDetailsBlockUse,
  isFieldContainerUse,
  isFieldWrapperUse,
  isFilterFormBlockUse,
  isFormBlockUse,
  isGridUse,
  isPageModelUse,
  isPageRouteType,
  isPopupHostUse,
  isTabsRouteType
});
