/**
 * 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 flow_surfaces_examples_exports = {};
__export(flow_surfaces_examples_exports, {
  flowSurfaceExamples: () => flowSurfaceExamples
});
module.exports = __toCommonJS(flow_surfaces_examples_exports);
const makePublicBlockDefaultFilter = (items = [
  {
    path: "username",
    operator: "$includes",
    value: ""
  },
  {
    path: "email",
    operator: "$includes",
    value: ""
  },
  {
    path: "status",
    operator: "$eq",
    value: ""
  },
  {
    path: "phone",
    operator: "$includes",
    value: ""
  }
]) => ({
  logic: "$and",
  items
});
const makeAIEmployeeActionSettings = (target = "self") => ({
  username: "dex",
  auto: false,
  workContext: [{ target }],
  tasks: [
    {
      title: "Analyze current context",
      prompt: "Analyze the current record and suggest next steps.",
      message: {
        system: "Use the current UI context.",
        workContext: [{ target }]
      },
      autoSend: false,
      skillSettings: null,
      model: null,
      webSearch: false
    }
  ],
  style: { size: 40, mask: false }
});
const flowSurfaceExamples = {
  catalog: {
    target: {
      uid: "table-block-uid"
    }
  },
  context: {
    target: {
      uid: "details-block-uid"
    },
    path: "record",
    maxDepth: 3
  },
  getReactionMeta: {
    target: {
      uid: "employees-form-uid"
    }
  },
  describeSurface: {
    locator: {
      pageSchemaUid: "employees-page-schema"
    },
    bindKeys: [
      {
        key: "employeesTable",
        locator: {
          uid: "employees-table-uid"
        },
        expectedKind: "block"
      }
    ]
  },
  exportBlueprint: {
    target: {
      pageSchemaUid: "employees-page-schema"
    },
    options: {
      unsupported: "error"
    }
  },
  applyBlueprint: {
    version: "1",
    mode: "create",
    navigation: {
      group: {
        title: "Workspace"
      },
      item: {
        title: "Employees"
      }
    },
    page: {
      title: "Employees",
      documentTitle: "Employees workspace",
      enableHeader: true,
      displayTitle: true
    },
    tabs: [
      {
        key: "main",
        title: "Overview",
        blocks: [
          {
            key: "employeeForm",
            type: "createForm",
            collection: "employees",
            fields: [
              { key: "nicknameField", field: "nickname" },
              { key: "statusField", field: "status" },
              "amount",
              "taxRate",
              "subtotal",
              "total"
            ],
            fieldsLayout: {
              rows: [
                ["nicknameField"],
                [
                  { key: "statusField", span: 12 },
                  { key: "amount", span: 12 }
                ],
                ["taxRate"],
                ["subtotal"],
                ["total"]
              ]
            },
            actions: [
              "submit",
              {
                key: "formAssistantAction",
                type: "aiEmployee",
                settings: makeAIEmployeeActionSettings()
              }
            ]
          },
          {
            key: "employeesTable",
            type: "table",
            collection: "employees",
            defaultFilter: makePublicBlockDefaultFilter([
              {
                path: "nickname",
                operator: "$includes",
                value: ""
              },
              {
                path: "email",
                operator: "$includes",
                value: ""
              },
              {
                path: "status",
                operator: "$eq",
                value: ""
              },
              {
                path: "phone",
                operator: "$includes",
                value: ""
              }
            ]),
            fields: ["nickname", "status", "total"],
            actions: [
              {
                key: "filterAction",
                type: "filter",
                settings: {
                  defaultFilter: makePublicBlockDefaultFilter([
                    {
                      path: "nickname",
                      operator: "$includes",
                      value: ""
                    },
                    {
                      path: "email",
                      operator: "$includes",
                      value: ""
                    },
                    {
                      path: "status",
                      operator: "$eq",
                      value: "active"
                    },
                    {
                      path: "phone",
                      operator: "$includes",
                      value: ""
                    }
                  ])
                }
              },
              {
                key: "refreshAction",
                type: "refresh"
              },
              {
                key: "tableInsightAction",
                type: "aiEmployee",
                settings: makeAIEmployeeActionSettings("employeeForm")
              }
            ],
            recordActions: [
              {
                key: "recordInsightAction",
                type: "aiEmployee",
                settings: makeAIEmployeeActionSettings()
              }
            ]
          }
        ],
        layout: {
          rows: [["main.employeeForm"], ["main.employeesTable"]]
        }
      }
    ],
    reaction: {
      items: [
        {
          type: "setFieldValueRules",
          target: "main.employeeForm",
          rules: [
            {
              key: "defaultStatus",
              targetPath: "status",
              mode: "default",
              value: {
                source: "literal",
                value: "draft"
              }
            }
          ]
        },
        {
          type: "setBlockLinkageRules",
          target: "main.employeesTable",
          rules: [
            {
              key: "hideTable",
              when: {
                logic: "$and",
                items: [
                  {
                    path: "params.query.hideTable",
                    operator: "$isTruly"
                  }
                ]
              },
              then: [{ type: "setBlockState", state: "hidden" }]
            }
          ]
        },
        {
          type: "setFieldLinkageRules",
          target: "main.employeeForm",
          rules: [
            {
              key: "recomputeTotals",
              when: {
                logic: "$and",
                items: [
                  {
                    path: "formValues.amount",
                    operator: "$notEmpty"
                  }
                ]
              },
              then: [
                {
                  type: "assignField",
                  items: [
                    {
                      targetPath: "subtotal",
                      value: {
                        source: "runjs",
                        version: "v2",
                        code: "const amount = Number(ctx.formValues?.amount || 0); return amount;"
                      }
                    },
                    {
                      targetPath: "total",
                      value: {
                        source: "runjs",
                        version: "v2",
                        code: "const amount = Number(ctx.formValues?.amount || 0); const taxRate = Number(ctx.formValues?.taxRate || 0); return amount + amount * taxRate;"
                      }
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          type: "setActionLinkageRules",
          target: "main.employeesTable.refreshAction",
          rules: [
            {
              key: "disableRefresh",
              when: {
                logic: "$and",
                items: [
                  {
                    path: "params.query.readonly",
                    operator: "$isTruly"
                  }
                ]
              },
              then: [{ type: "setActionState", state: "disabled" }]
            }
          ]
        }
      ]
    }
  },
  applyBlueprintReplace: {
    version: "1",
    mode: "replace",
    target: {
      pageSchemaUid: "employees-page-schema"
    },
    page: {
      title: "Employees workspace",
      documentTitle: "Employees replace flow",
      displayTitle: false,
      enableTabs: true
    },
    tabs: [
      {
        title: "Overview",
        blocks: [
          {
            key: "employeesTable",
            type: "table",
            collection: "employees",
            fields: ["nickname", "status", "total"]
          }
        ]
      }
    ]
  },
  applyBlueprintCalendar: {
    version: "1",
    mode: "create",
    navigation: {
      item: {
        title: "Calendar"
      }
    },
    page: {
      title: "Calendar",
      documentTitle: "Team calendar"
    },
    tabs: [
      {
        key: "schedule",
        title: "Schedule",
        blocks: [
          {
            key: "eventsCalendar",
            type: "calendar",
            collection: "calendar_events",
            defaultFilter: makePublicBlockDefaultFilter([
              {
                path: "title",
                operator: "$includes",
                value: ""
              },
              {
                path: "status",
                operator: "$eq",
                value: "planned"
              },
              {
                path: "category",
                operator: "$eq",
                value: ""
              },
              {
                path: "scope",
                operator: "$includes",
                value: ""
              }
            ]),
            settings: {
              title: "Team events",
              titleField: "title",
              colorField: "status",
              startField: "startsAt",
              endField: "endsAt",
              defaultView: "week"
            },
            actions: ["filter", "addNew", "refresh", "today", "turnPages", "title", "selectView"]
          }
        ]
      }
    ]
  },
  applyApprovalBlueprintInitiator: {
    version: "1",
    surface: "initiator",
    workflowId: 101,
    blocks: [
      {
        key: "initiatorForm",
        type: "approvalInitiator",
        resource: {
          dataSourceKey: "main",
          collectionName: "employees"
        },
        fields: ["nickname", "status"],
        actions: ["approvalSaveDraft", "approvalWithdraw"]
      }
    ],
    layout: {
      rows: [["initiatorForm"]]
    }
  },
  applyApprovalBlueprintApprover: {
    version: "1",
    surface: "approver",
    nodeId: 201,
    blocks: [
      {
        key: "processForm",
        type: "approvalApprover",
        resource: {
          dataSourceKey: "main",
          collectionName: "employees"
        },
        fields: ["nickname"],
        actions: [
          "approvalApprove",
          "approvalReject",
          {
            type: "approvalReturn",
            settings: {
              approvalReturn: {
                type: "count",
                count: 1
              }
            }
          }
        ]
      },
      {
        key: "approvalInfo",
        type: "approvalInformation",
        resource: {
          dataSourceKey: "main",
          collectionName: "employees"
        },
        fields: ["status"]
      }
    ],
    layout: {
      rows: [["processForm"], ["approvalInfo"]]
    }
  },
  applyApprovalBlueprintTaskCard: {
    version: "1",
    surface: "taskCard",
    nodeId: 201,
    fields: [
      {
        key: "nickname",
        fieldPath: "nickname"
      },
      {
        key: "status",
        fieldPath: "status"
      }
    ],
    layout: {
      rows: [["nickname", "status"]]
    }
  },
  setFieldValueRules: {
    target: {
      uid: "employees-form-uid"
    },
    rules: [
      {
        key: "defaultStatus",
        targetPath: "status",
        mode: "default",
        value: {
          source: "literal",
          value: "draft"
        }
      }
    ],
    expectedFingerprint: "field-value-fp-1"
  },
  setBlockLinkageRules: {
    target: {
      uid: "employees-table-uid"
    },
    rules: [
      {
        key: "hideTable",
        when: {
          logic: "$and",
          items: [
            {
              path: "params.query.hideTable",
              operator: "$isTruly"
            }
          ]
        },
        then: [{ type: "setBlockState", state: "hidden" }]
      }
    ],
    expectedFingerprint: "block-linkage-fp-1"
  },
  setFieldLinkageRules: {
    target: {
      uid: "employees-form-uid"
    },
    rules: [
      {
        key: "recomputeTotals",
        when: {
          logic: "$and",
          items: [
            {
              path: "formValues.amount",
              operator: "$notEmpty"
            }
          ]
        },
        then: [
          {
            type: "assignField",
            items: [
              {
                targetPath: "subtotal",
                value: {
                  source: "runjs",
                  version: "v2",
                  code: "const amount = Number(ctx.formValues?.amount || 0); return amount;"
                }
              },
              {
                targetPath: "total",
                value: {
                  source: "runjs",
                  version: "v2",
                  code: "const amount = Number(ctx.formValues?.amount || 0); const taxRate = Number(ctx.formValues?.taxRate || 0); return amount + amount * taxRate;"
                }
              }
            ]
          }
        ]
      }
    ],
    expectedFingerprint: "field-linkage-fp-1"
  },
  setActionLinkageRules: {
    target: {
      uid: "refresh-action-uid"
    },
    expectedFingerprint: "action-linkage-fp-1",
    rules: [
      {
        key: "disableRefresh",
        when: {
          logic: "$and",
          items: [
            {
              path: "params.query.readonly",
              operator: "$isTruly"
            }
          ]
        },
        then: [{ type: "setActionState", state: "disabled" }]
      }
    ]
  },
  compose: {
    target: {
      uid: "page-grid-uid"
    },
    mode: "append",
    blocks: [
      {
        key: "filter",
        type: "filterForm",
        resource: {
          dataSourceKey: "main",
          collectionName: "users"
        },
        fields: [
          {
            fieldPath: "username",
            target: "table"
          },
          {
            fieldPath: "nickname",
            target: "table"
          }
        ],
        fieldsLayout: {
          rows: [
            [
              { key: "nickname", span: 12 },
              { key: "username", span: 12 }
            ]
          ]
        },
        actions: ["submit", "reset", "collapse"]
      },
      {
        key: "table",
        type: "table",
        resource: {
          dataSourceKey: "main",
          collectionName: "users"
        },
        defaultFilter: makePublicBlockDefaultFilter(),
        fields: ["username", "nickname", { fieldPath: "roles.title" }],
        actions: [
          {
            type: "filter",
            settings: {
              defaultFilter: makePublicBlockDefaultFilter([
                {
                  path: "username",
                  operator: "$includes",
                  value: ""
                },
                {
                  path: "email",
                  operator: "$includes",
                  value: ""
                },
                {
                  path: "status",
                  operator: "$eq",
                  value: "active"
                },
                {
                  path: "phone",
                  operator: "$includes",
                  value: ""
                }
              ])
            }
          },
          "addNew",
          "refresh",
          "bulkDelete",
          "link"
        ],
        recordActions: [
          "view",
          "edit",
          {
            type: "popup",
            popup: {
              mode: "replace",
              blocks: [
                {
                  key: "details",
                  type: "details",
                  resource: {
                    dataSourceKey: "main",
                    collectionName: "users"
                  },
                  fields: ["username", "nickname"]
                }
              ]
            }
          },
          "updateRecord",
          "delete"
        ]
      }
    ],
    layout: {
      rows: [
        [
          {
            key: "filter",
            span: 3
          },
          {
            key: "table",
            span: 7
          }
        ]
      ]
    }
  },
  composeStatic: {
    target: {
      uid: "page-grid-uid"
    },
    blocks: [
      {
        key: "markdown",
        type: "markdown",
        settings: {
          content: "# Team handbook"
        }
      },
      {
        key: "iframe",
        type: "iframe",
        settings: {
          mode: "url",
          url: "https://example.com/embed",
          height: 360
        }
      },
      {
        key: "panel",
        type: "actionPanel",
        settings: {
          layout: "list",
          ellipsis: false
        }
      }
    ],
    layout: {
      rows: [["markdown", "iframe"], ["panel"]]
    }
  },
  composeListRich: {
    target: {
      uid: "page-grid-uid"
    },
    blocks: [
      {
        key: "employeesList",
        type: "list",
        resource: {
          dataSourceKey: "main",
          collectionName: "employees"
        },
        defaultFilter: makePublicBlockDefaultFilter([
          {
            path: "nickname",
            operator: "$includes",
            value: ""
          },
          {
            path: "email",
            operator: "$includes",
            value: ""
          },
          {
            path: "status",
            operator: "$eq",
            value: ""
          },
          {
            path: "phone",
            operator: "$includes",
            value: ""
          }
        ]),
        fields: [
          "nickname",
          {
            fieldPath: "department.name"
          }
        ],
        actions: ["addNew", "refresh"],
        recordActions: [
          "view",
          "edit",
          {
            type: "popup",
            popup: {
              mode: "replace",
              blocks: [
                {
                  key: "details",
                  type: "details",
                  resource: {
                    dataSourceKey: "main",
                    collectionName: "employees"
                  },
                  fields: ["nickname"]
                }
              ]
            }
          },
          "delete"
        ],
        settings: {
          pageSize: 20,
          layout: "vertical"
        }
      }
    ]
  },
  composeGridCardRich: {
    target: {
      uid: "page-grid-uid"
    },
    blocks: [
      {
        key: "employeeCards",
        type: "gridCard",
        resource: {
          dataSourceKey: "main",
          collectionName: "employees"
        },
        defaultFilter: makePublicBlockDefaultFilter([
          {
            path: "nickname",
            operator: "$includes",
            value: ""
          },
          {
            path: "email",
            operator: "$includes",
            value: ""
          },
          {
            path: "status",
            operator: "$eq",
            value: ""
          },
          {
            path: "phone",
            operator: "$includes",
            value: ""
          }
        ]),
        fields: [
          "nickname",
          {
            fieldPath: "department.name"
          }
        ],
        actions: ["addNew", "refresh"],
        recordActions: ["view", "edit", "updateRecord", "delete"],
        settings: {
          columns: 3,
          rowCount: 2,
          layout: "vertical"
        }
      }
    ]
  },
  composeJsBlock: {
    target: {
      uid: "page-grid-uid"
    },
    blocks: [
      {
        key: "customHero",
        type: "jsBlock",
        settings: {
          title: "Custom hero",
          description: "Rendered by JS block runtime",
          className: "hero-shell",
          showBlockCard: true,
          version: "1.0.0",
          code: "ctx.render('<div>Hello from JS block</div>');"
        }
      }
    ]
  },
  configure: {
    target: {
      uid: "details-field-uid"
    },
    changes: {
      clickToOpen: true,
      openView: {
        dataSourceKey: "main",
        collectionName: "departments",
        associationName: "users.department",
        mode: "drawer"
      }
    }
  },
  configureAssociationPopup: {
    target: {
      uid: "roles-field-wrapper-uid"
    },
    changes: {
      clickToOpen: true,
      openView: {
        dataSourceKey: "main",
        collectionName: "roles",
        associationName: "users.roles",
        mode: "drawer"
      }
    }
  },
  configureBlock: {
    target: {
      uid: "list-block-uid"
    },
    changes: {
      pageSize: 50,
      dataScope: {
        logic: "$and",
        items: [
          {
            path: "nickname",
            operator: "$eq",
            value: "beta"
          }
        ]
      },
      sorting: [
        {
          field: "username",
          direction: "asc"
        }
      ],
      layout: "vertical"
    }
  },
  createMenu: {
    title: "Employees",
    type: "item",
    parentMenuRouteId: 1001
  },
  updateMenu: {
    menuRouteId: 1002,
    title: "Employees Center",
    parentMenuRouteId: null
  },
  configureAction: {
    target: {
      uid: "update-record-action-uid"
    },
    changes: {
      title: "Quick update",
      type: "primary",
      color: "gold",
      htmlType: "button",
      position: "end",
      confirm: {
        enable: true,
        title: "Confirm update",
        content: "Apply assigned values?"
      },
      assignValues: {
        status: "active"
      },
      triggerWorkflows: [
        {
          workflowKey: "employee_status_changed",
          context: "department"
        }
      ]
    }
  },
  configureJsBlock: {
    target: {
      uid: "js-block-uid"
    },
    changes: {
      title: "Users hero",
      description: "Rendered from FlowSurfaces configure",
      className: "users-hero",
      showBlockCard: true,
      version: "1.0.1",
      code: "ctx.render('<div>Users hero</div>');"
    }
  },
  configureJsAction: {
    target: {
      uid: "js-action-uid"
    },
    changes: {
      title: "Run diagnostics",
      type: "primary",
      version: "1.0.1",
      code: 'ctx.console.log("diagnostics");'
    }
  },
  configureJsItemAction: {
    target: {
      uid: "js-item-action-uid"
    },
    changes: {
      title: "Run item diagnostics",
      type: "default",
      version: "1.0.1",
      code: 'const { Button } = ctx.antd;\n\nfunction JsItemAction() {\n  return <Button onClick={() => ctx.message.success("Item diagnostics complete")}>Run item diagnostics</Button>;\n}\n\nctx.render(<JsItemAction />);'
    }
  },
  configureJsField: {
    target: {
      uid: "js-field-wrapper-uid"
    },
    changes: {
      label: "Custom renderer",
      version: "1.0.1",
      code: "ctx.render(String(ctx.record?.nickname?.toUpperCase?.() || ''));"
    }
  },
  configureJsColumn: {
    target: {
      uid: "js-column-uid"
    },
    changes: {
      title: "JS column",
      width: 240,
      fixed: "left",
      version: "1.0.1",
      code: "ctx.render(String(ctx.record?.username || ''));"
    }
  },
  configureJsItem: {
    target: {
      uid: "js-item-uid"
    },
    changes: {
      label: "JS item",
      showLabel: true,
      labelWidth: 120,
      version: "1.0.1",
      code: "ctx.render(String(ctx.record?.nickname || ''));"
    }
  },
  configurePage: {
    target: {
      uid: "employees-page-uid"
    },
    changes: {
      icon: "UserOutlined",
      enableHeader: false
    }
  },
  configureTableAdvanced: {
    target: {
      uid: "tree-table-block-uid"
    },
    changes: {
      quickEdit: true,
      treeTable: true,
      defaultExpandAllRows: true,
      dragSort: true,
      dragSortBy: "sort"
    }
  },
  configureEditForm: {
    target: {
      uid: "edit-form-block-uid"
    },
    changes: {
      colon: false,
      dataScope: {
        logic: "$and",
        items: [
          {
            path: "status",
            operator: "$eq",
            value: "draft"
          }
        ]
      }
    }
  },
  configureDetailsCompatibility: {
    target: {
      uid: "details-block-uid"
    },
    changes: {
      colon: true,
      linkageRules: [
        {
          when: {
            path: "status",
            operator: "$eq",
            value: "archived"
          },
          set: {
            hidden: true
          }
        }
      ]
    }
  },
  composePopupCurrentRecord: {
    target: {
      uid: "view-action-uid"
    },
    mode: "replace",
    blocks: [
      {
        key: "details",
        type: "details",
        resource: {
          binding: "currentRecord"
        },
        fields: ["nickname", "department.title"]
      }
    ]
  },
  composePopupAssociatedRecords: {
    target: {
      uid: "association-popup-action-uid"
    },
    mode: "replace",
    blocks: [
      {
        key: "employees",
        type: "table",
        resource: {
          binding: "associatedRecords",
          associationField: "employee"
        },
        fields: ["nickname", "status"],
        actions: ["refresh"],
        recordActions: ["view", "edit"]
      }
    ]
  },
  configureActionModesCompatibility: {
    target: {
      uid: "compose-email-action-uid"
    },
    changes: {
      linkageRules: [
        {
          when: {
            path: "status",
            operator: "$eq",
            value: "draft"
          },
          set: {
            disabled: true
          }
        }
      ],
      editMode: "drawer",
      updateMode: "overwrite",
      duplicateMode: "popup",
      collapsedRows: 2,
      defaultCollapsed: true,
      emailFieldNames: ["email", "backupEmail"],
      defaultSelectAllRecords: true
    }
  },
  createPage: {
    menuRouteId: 1002,
    title: "Employees",
    tabTitle: "Overview",
    enableTabs: true,
    displayTitle: true,
    documentTitle: "Employees workspace",
    tabDocumentTitle: "Employees overview"
  },
  addTab: {
    target: {
      uid: "employees-page-uid"
    },
    title: "Details",
    icon: "TableOutlined",
    documentTitle: "Employee details tab"
  },
  updateTab: {
    target: {
      uid: "details-tab-schema"
    },
    title: "Details",
    icon: "TableOutlined",
    documentTitle: "Employee details tab",
    flowRegistry: {
      beforeRenderApply: {
        key: "beforeRenderApply",
        on: "beforeRender",
        steps: {}
      }
    }
  },
  addPopupTab: {
    target: {
      uid: "view-action-popup-page-uid"
    },
    title: "Popup details",
    icon: "TableOutlined",
    documentTitle: "Popup details tab"
  },
  updatePopupTab: {
    target: {
      uid: "popup-secondary-tab-uid"
    },
    title: "Popup details updated",
    icon: "AppstoreOutlined",
    documentTitle: "Popup details updated tab",
    flowRegistry: {
      beforeRenderApply: {
        key: "beforeRenderApply",
        on: "beforeRender",
        steps: {}
      }
    }
  },
  movePopupTab: {
    sourceUid: "popup-secondary-tab-uid",
    targetUid: "popup-primary-tab-uid",
    position: "before"
  },
  removePopupTab: {
    target: {
      uid: "popup-secondary-tab-uid"
    }
  },
  addBlock: {
    target: {
      uid: "view-action-uid"
    },
    type: "details",
    resource: {
      binding: "currentRecord"
    }
  },
  addTableBlockWithDefaultFilters: {
    target: {
      uid: "page-grid-uid"
    },
    type: "table",
    defaultFilter: makePublicBlockDefaultFilter([
      {
        path: "username",
        operator: "$includes",
        value: "staff"
      },
      {
        path: "email",
        operator: "$includes",
        value: ""
      },
      {
        path: "status",
        operator: "$eq",
        value: ""
      },
      {
        path: "phone",
        operator: "$includes",
        value: ""
      }
    ]),
    resourceInit: {
      dataSourceKey: "main",
      collectionName: "users"
    },
    defaultActionSettings: {
      filter: {
        filterableFieldNames: ["username", "email", "status", "phone"],
        defaultFilter: {
          logic: "$and",
          items: [
            {
              path: "username",
              operator: "$includes",
              value: ""
            },
            {
              path: "email",
              operator: "$includes",
              value: ""
            },
            {
              path: "status",
              operator: "$eq",
              value: ""
            },
            {
              path: "phone",
              operator: "$includes",
              value: ""
            }
          ]
        }
      }
    }
  },
  addPopupAssociatedBlock: {
    target: {
      uid: "association-popup-action-uid"
    },
    type: "table",
    resource: {
      binding: "associatedRecords",
      associationField: "employee"
    }
  },
  addPopupOtherRecordsBlock: {
    target: {
      uid: "popup-action-uid"
    },
    type: "table",
    resource: {
      binding: "otherRecords",
      dataSourceKey: "main",
      collectionName: "departments"
    }
  },
  addJsBlock: {
    target: {
      uid: "page-grid-uid"
    },
    type: "jsBlock",
    settings: {
      title: "Users banner",
      description: "Custom JS rendered banner",
      showBlockCard: true,
      version: "1.0.0",
      code: "ctx.render('<div>Users banner</div>');"
    }
  },
  addField: {
    target: {
      uid: "create-form-block-uid"
    },
    fieldPath: "nickname",
    renderer: "js",
    settings: {
      label: "Nickname (JS)",
      code: "ctx.render(String(ctx.value?.toUpperCase?.() || ctx.value || ''));",
      version: "1.0.0"
    }
  },
  addAssociationField: {
    target: {
      uid: "table-block-uid"
    },
    fieldPath: "title",
    associationPathName: "department",
    settings: {
      title: "Department title",
      width: 240
    },
    popup: {
      mode: "replace",
      blocks: [
        {
          key: "departmentDetails",
          type: "details",
          resource: {
            binding: "currentRecord"
          },
          fields: ["title", "manager.nickname"]
        }
      ]
    }
  },
  addJsColumn: {
    target: {
      uid: "table-block-uid"
    },
    type: "jsColumn",
    settings: {
      title: "Runtime column",
      width: 240,
      version: "1.0.0",
      code: "ctx.render(String(ctx.record?.nickname || ''));"
    }
  },
  addJsItem: {
    target: {
      uid: "create-form-grid-uid"
    },
    type: "jsItem",
    settings: {
      label: "Runtime item",
      showLabel: true,
      version: "1.0.0",
      code: "ctx.render(String(ctx.record?.nickname || ''));"
    }
  },
  addFieldPopupTemplate: {
    target: {
      uid: "details-block-uid"
    },
    fieldPath: "nickname",
    popup: {
      template: {
        uid: "employee-popup-template",
        mode: "reference"
      }
    }
  },
  addFieldAutoPopupTemplate: {
    target: {
      uid: "details-block-uid"
    },
    fieldPath: "department.title",
    popup: {
      tryTemplate: true
    }
  },
  addFieldDefaultEditPopup: {
    target: {
      uid: "details-block-uid"
    },
    fieldPath: "department.title",
    popup: {
      defaultType: "edit"
    }
  },
  addFieldSavePopupTemplate: {
    target: {
      uid: "details-block-uid"
    },
    fieldPath: "nickname",
    popup: {
      blocks: [
        {
          key: "employee-popup-details",
          type: "details",
          resource: {
            binding: "currentRecord"
          },
          fields: ["nickname"]
        }
      ],
      saveAsTemplate: {
        name: "employee-popup-template",
        description: "Save this explicit field popup as a reusable popup template."
      }
    }
  },
  addAction: {
    target: {
      uid: "create-form-block-uid"
    },
    type: "submit",
    settings: {
      title: "Submit user",
      confirm: false,
      triggerWorkflows: [
        {
          workflowKey: "employee_created"
        }
      ]
    }
  },
  addLinkAction: {
    target: {
      uid: "table-block-uid"
    },
    type: "link",
    settings: {
      title: "Open docs"
    }
  },
  addAutoPopupAction: {
    target: {
      uid: "table-block-uid"
    },
    type: "popup",
    popup: {
      tryTemplate: true
    }
  },
  addSavePopupAction: {
    target: {
      uid: "table-block-uid"
    },
    type: "popup",
    popup: {
      blocks: [
        {
          key: "employee-popup-table",
          type: "table",
          resource: {
            binding: "currentCollection"
          },
          fields: ["username", "nickname"]
        }
      ],
      saveAsTemplate: {
        name: "employee-popup-template",
        description: "Save this explicit action popup as a reusable popup template."
      }
    }
  },
  addJsAction: {
    target: {
      uid: "action-panel-uid"
    },
    type: "js",
    settings: {
      title: "Run JS",
      type: "primary",
      version: "1.0.0",
      code: 'ctx.console.log("hello");'
    }
  },
  addJsItemAction: {
    target: {
      uid: "create-form-uid"
    },
    type: "jsItem",
    settings: {
      title: "Run item JS",
      type: "default",
      version: "1.0.0",
      code: 'const { Button } = ctx.antd;\n\nfunction JsItemAction() {\n  return <Button onClick={() => ctx.message.success("Item JS complete")}>Run item JS</Button>;\n}\n\nctx.render(<JsItemAction />);'
    }
  },
  addAIEmployeeAction: {
    target: {
      uid: "table-block-uid"
    },
    type: "aiEmployee",
    settings: makeAIEmployeeActionSettings()
  },
  addRecordAction: {
    target: {
      uid: "table-block-uid"
    },
    type: "view",
    settings: {
      title: "View user",
      openView: {
        dataSourceKey: "main",
        collectionName: "users",
        mode: "drawer"
      }
    },
    popup: {
      mode: "replace",
      blocks: [
        {
          key: "details",
          type: "details",
          resource: {
            dataSourceKey: "main",
            collectionName: "users"
          },
          fields: ["username", "nickname"]
        }
      ]
    }
  },
  addRecordUpdateAction: {
    target: {
      uid: "table-block-uid"
    },
    type: "updateRecord",
    settings: {
      title: "Mark active",
      assignValues: {
        status: "active"
      },
      triggerWorkflows: [
        {
          workflowKey: "employee_status_changed",
          context: "department"
        }
      ]
    }
  },
  addRecordAutoPopupTemplate: {
    target: {
      uid: "table-block-uid"
    },
    type: "view",
    popup: {
      tryTemplate: true
    }
  },
  addRecordSavePopupTemplate: {
    target: {
      uid: "table-block-uid"
    },
    type: "view",
    popup: {
      blocks: [
        {
          key: "employee-record-popup-details",
          type: "details",
          resource: {
            binding: "currentRecord"
          },
          fields: ["username", "nickname"]
        }
      ],
      saveAsTemplate: {
        name: "employee-popup-template",
        description: "Save this explicit record-action popup as a reusable popup template."
      }
    }
  },
  addRecordAddChildAction: {
    target: {
      uid: "tree-table-block-uid"
    },
    type: "addChild",
    settings: {
      title: "Add child category",
      openView: {
        dataSourceKey: "main",
        collectionName: "categories",
        mode: "drawer"
      }
    }
  },
  addRecordJsAction: {
    target: {
      uid: "details-block-uid"
    },
    type: "js",
    settings: {
      title: "Inspect record",
      type: "default",
      version: "1.0.0",
      code: "return currentRecord?.id;"
    }
  },
  addRecordAIEmployeeAction: {
    target: {
      uid: "table-block-uid"
    },
    type: "aiEmployee",
    settings: makeAIEmployeeActionSettings()
  },
  addBlocks: {
    target: {
      uid: "page-grid-uid"
    },
    blocks: [
      {
        key: "usersTable",
        type: "table",
        defaultFilter: makePublicBlockDefaultFilter([
          {
            path: "username",
            operator: "$includes",
            value: "staff"
          },
          {
            path: "email",
            operator: "$includes",
            value: ""
          },
          {
            path: "status",
            operator: "$eq",
            value: ""
          },
          {
            path: "phone",
            operator: "$includes",
            value: ""
          }
        ]),
        resourceInit: {
          dataSourceKey: "main",
          collectionName: "users"
        },
        settings: {
          title: "Users table",
          pageSize: 50
        },
        defaultActionSettings: {
          filter: {
            filterableFieldNames: ["username", "email", "status", "phone"],
            defaultFilter: {
              logic: "$and",
              items: [
                {
                  path: "username",
                  operator: "$includes",
                  value: ""
                },
                {
                  path: "email",
                  operator: "$includes",
                  value: ""
                },
                {
                  path: "status",
                  operator: "$eq",
                  value: ""
                },
                {
                  path: "phone",
                  operator: "$includes",
                  value: ""
                }
              ]
            }
          }
        }
      },
      {
        key: "userForm",
        type: "createForm",
        resourceInit: {
          dataSourceKey: "main",
          collectionName: "users"
        },
        fields: [
          {
            key: "rolesField",
            fieldPath: "roles",
            fieldType: "popupSubTable",
            fields: ["title", "name"]
          }
        ],
        fieldsLayout: {
          rows: [["rolesField"]]
        }
      }
    ]
  },
  addFields: {
    target: {
      uid: "create-form-block-uid"
    },
    fields: [
      {
        key: "username",
        fieldPath: "username",
        settings: {
          title: "User name",
          width: 220
        },
        popup: {
          mode: "replace",
          blocks: [
            {
              key: "details",
              type: "details",
              resource: {
                binding: "currentRecord"
              },
              fields: ["username", "nickname"]
            }
          ]
        }
      },
      {
        key: "rolesField",
        fieldPath: "roles",
        fieldType: "popupSubTable",
        fields: ["title", "name"],
        settings: {
          title: "Roles"
        }
      }
    ]
  },
  addActions: {
    target: {
      uid: "filter-form-block-uid"
    },
    actions: [
      {
        key: "submit",
        type: "submit",
        settings: {
          title: "Search",
          confirm: false
        }
      },
      {
        key: "reset",
        type: "reset",
        settings: {
          title: "Reset filters"
        }
      }
    ]
  },
  addRecordActions: {
    target: {
      uid: "table-block-uid"
    },
    recordActions: [
      {
        key: "view",
        type: "view",
        settings: {
          title: "View user",
          openView: {
            dataSourceKey: "main",
            collectionName: "users",
            mode: "drawer"
          }
        },
        popup: {
          mode: "replace",
          blocks: [
            {
              key: "details",
              type: "details",
              resource: {
                dataSourceKey: "main",
                collectionName: "users"
              },
              fields: ["username"]
            }
          ]
        }
      },
      {
        key: "edit",
        type: "edit",
        settings: {
          title: "Edit user"
        }
      },
      {
        key: "delete",
        type: "delete",
        settings: {
          title: "Delete user"
        }
      }
    ]
  },
  addRecordAddChildActions: {
    target: {
      uid: "tree-table-block-uid"
    },
    recordActions: [
      {
        key: "addChild",
        type: "addChild",
        settings: {
          title: "Add child category",
          openView: {
            dataSourceKey: "main",
            collectionName: "categories",
            mode: "drawer"
          }
        }
      }
    ]
  },
  updateSettings: {
    target: {
      uid: "table-block-uid"
    },
    stepParams: {
      tableSettings: {
        pageSize: {
          pageSize: 50
        },
        tableDensity: {
          size: "middle"
        }
      }
    },
    flowRegistry: {
      beforeRenderApply: {
        key: "beforeRenderApply",
        on: "beforeRender",
        steps: {}
      }
    }
  },
  updateAIEmployeeSettings: {
    target: {
      uid: "ai-employee-action-uid"
    },
    tasks: [
      {
        title: "Generate table insights",
        prompt: "Summarize the current table and identify risks.",
        message: {
          workContext: [{ target: "self" }]
        },
        autoSend: true,
        webSearch: false
      }
    ],
    style: {
      mask: true
    }
  },
  getEventFlowMeta: {
    target: {
      uid: "submit-action-uid"
    }
  },
  addEventFlow: {
    target: {
      uid: "employee-form-uid"
    },
    key: "submitGuard",
    eventName: "submit",
    steps: {
      runGuard: {
        use: "runjs",
        defaultParams: {
          code: 'ctx.message.info("Submitting");'
        }
      }
    },
    condition: {
      logic: "$and",
      items: []
    }
  },
  setEventFlow: {
    target: {
      uid: "employee-form-uid"
    },
    key: "submitGuard",
    flow: {
      key: "submitGuard",
      on: {
        eventName: "submit",
        phase: "beforeAllFlows"
      },
      steps: {
        runGuard: {
          use: "runjs",
          defaultParams: {
            code: 'ctx.message.success("Updated");'
          }
        }
      }
    }
  },
  removeEventFlow: {
    target: {
      uid: "employee-form-uid"
    },
    key: "submitGuard"
  },
  setEventFlows: {
    target: {
      uid: "view-action-uid"
    },
    flowRegistry: {
      popupSettings: {
        key: "popupSettings",
        on: "click",
        steps: {
          openView: {
            params: {
              title: "Employee details",
              size: "large"
            }
          }
        }
      }
    }
  },
  setLayout: {
    target: {
      uid: "page-grid-uid"
    },
    rows: {
      row1: [["block-a"], ["block-b"]]
    },
    sizes: {
      row1: [12, 12]
    },
    rowOrder: ["row1"]
  },
  moveNode: {
    sourceUid: "block-b",
    targetUid: "block-a",
    position: "before"
  },
  removeNode: {
    target: {
      uid: "obsolete-block-uid"
    }
  },
  mutate: {
    atomic: true,
    ops: [
      {
        opId: "menu",
        type: "createMenu",
        values: {
          title: "Employees",
          type: "item"
        }
      },
      {
        opId: "page",
        type: "createPage",
        values: {
          menuRouteId: {
            step: "menu",
            path: "routeId"
          },
          tabTitle: "Overview"
        }
      },
      {
        opId: "table",
        type: "addBlock",
        values: {
          target: {
            uid: {
              step: "page",
              path: "tabSchemaUid"
            }
          },
          type: "table",
          resourceInit: {
            dataSourceKey: "main",
            collectionName: "employees"
          }
        }
      },
      {
        type: "addField",
        values: {
          target: {
            uid: {
              step: "table",
              path: "uid"
            }
          },
          fieldPath: "nickname"
        }
      }
    ]
  },
  apply: {
    target: {
      uid: "page-grid-uid"
    },
    mode: "replace",
    spec: {
      popup: {
        tryTemplate: true
      },
      subModels: {
        items: [
          {
            clientKey: "table-a",
            use: "TableBlockModel",
            stepParams: {
              resourceSettings: {
                init: {
                  dataSourceKey: "main",
                  collectionName: "employees"
                }
              }
            }
          },
          {
            clientKey: "markdown-a",
            use: "MarkdownBlockModel",
            props: {
              content: "Employee handbook"
            }
          }
        ]
      }
    }
  },
  getPopupQuery: {
    uid: "view-action-uid"
  },
  getPageQuery: {
    pageSchemaUid: "employees-page-schema"
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  flowSurfaceExamples
});
