"use strict";

exports.__esModule = true;
exports.coreModelFactory = void 0;
var _lowcodeEditorCore = require("@gant-lowcode/lowcode-editor-core");
var _lowcodeDesigner = require("@gant-lowcode/lowcode-designer");
var _lowcodeEditorSkeleton = require("@gant-lowcode/lowcode-editor-skeleton");
var _lowcodeTypes = require("@gant-lowcode/lowcode-types");
var _lowcodeShell = require("@gant-lowcode/lowcode-shell");
var _lowcodeUtils = require("@gant-lowcode/lowcode-utils");
var _shellModelFactory = require("./shell-model-factory");
var CoreModelFactory = /*#__PURE__*/function () {
  function CoreModelFactory() {}
  var _proto = CoreModelFactory.prototype;
  _proto.createCore = function createCore(innerWorkspace, viewName, workspaceMode, registerLevel, editorWindow) {
    var workspace = new _lowcodeShell.Workspace(innerWorkspace);
    var editor = new _lowcodeEditorCore.Editor(viewName, workspaceMode);
    var engineContext = {};
    var innerSkeleton = new _lowcodeEditorSkeleton.Skeleton(editor, viewName);
    editor.set('skeleton', innerSkeleton);
    var designer = new _lowcodeDesigner.Designer({
      editor: editor,
      viewName: viewName,
      shellModelFactory: _shellModelFactory.shellModelFactory
    });
    editor.set('designer', designer);
    var innerProject = designer.project;
    var innerHotkey = new _lowcodeEditorCore.Hotkey(viewName);
    var hotkey = new _lowcodeShell.Hotkey(innerHotkey, workspaceMode);
    var project = new _lowcodeShell.Project(innerProject, workspaceMode);
    var skeleton = new _lowcodeShell.Skeleton(innerSkeleton, 'any', workspaceMode);
    var innerSetters = new _lowcodeEditorCore.Setters(viewName);
    var setters = new _lowcodeShell.Setters(innerSetters, workspaceMode);
    var innerCommand = new _lowcodeEditorCore.Command();
    if (!workspaceMode) {
      var command = new _lowcodeShell.Command(innerCommand, engineContext);
      engineContext.command = command;
    }
    var material = new _lowcodeShell.Material(editor, workspaceMode);
    var commonUI = new _lowcodeShell.CommonUI(editor);
    editor.set('setters', setters);
    editor.set('project', project);
    editor.set('material', material);
    editor.set('hotkey', hotkey);
    editor.set('innerHotkey', innerHotkey);
    var config;
    if (!workspaceMode) {
      config = new _lowcodeShell.Config(_lowcodeEditorCore.engineConfig);
    } else {
      config = _lowcodeEditorCore.engineConfig;
    }
    var event = new _lowcodeShell.Event(_lowcodeEditorCore.commonEvent, {
      prefix: 'common'
    });
    var logger = (0, _lowcodeUtils.getLogger)({
      level: 'warn',
      bizName: 'common'
    });
    var canvas = new _lowcodeShell.Canvas(editor, workspaceMode);
    var common = new _lowcodeShell.Common(editor, innerSkeleton);
    var plugins;
    var pluginContextApiAssembler = {
      assembleApis: function assembleApis(context, pluginName, meta) {
        context.hotkey = hotkey;
        context.project = project;
        context.skeleton = new _lowcodeShell.Skeleton(innerSkeleton, pluginName, true);
        context.setters = setters;
        context.material = material;
        var eventPrefix = (meta === null || meta === void 0 ? void 0 : meta.eventPrefix) || 'common';
        var commandScope = meta === null || meta === void 0 ? void 0 : meta.commandScope;
        context.event = new _lowcodeShell.Event(_lowcodeEditorCore.commonEvent, {
          prefix: eventPrefix
        });
        context.config = config;
        context.common = common;
        context.plugins = plugins;
        context.logger = new _lowcodeShell.Logger({
          level: 'warn',
          bizName: "plugin:" + pluginName
        });
        context.canvas = canvas;
        context.commonUI = commonUI;
        context.workspace = workspace;
        if (editorWindow) {
          context.editorWindow = new _lowcodeShell.Window(editorWindow);
        }
        context.command = new _lowcodeShell.Command(innerCommand, context, {
          commandScope: commandScope
        });
        if (registerLevel) {
          context.registerLevel = registerLevel;
        }
        context.isPluginRegisteredInWorkspace = registerLevel === _lowcodeTypes.IPublicEnumPluginRegisterLevel.Workspace;
        editor.set('pluginContext', context);
      }
    };
    var innerPlugins = new _lowcodeDesigner.LowCodePluginManager(pluginContextApiAssembler, viewName);
    plugins = new _lowcodeShell.Plugins(innerPlugins, true).toProxy();
    editor.set('plugins', plugins);
    editor.set('innerPlugins', innerPlugins);
    engineContext.skeleton = skeleton;
    engineContext.plugins = plugins;
    engineContext.project = project;
    engineContext.setters = setters;
    engineContext.material = material;
    engineContext.event = event;
    engineContext.logger = logger;
    engineContext.hotkey = hotkey;
    engineContext.common = common;
    engineContext.workspace = workspace;
    engineContext.canvas = canvas;
    engineContext.commonUI = commonUI;
    engineContext.innerSetters = innerSetters;
    engineContext.innerSkeleton = innerSkeleton;
    engineContext.innerProject = innerProject;
    engineContext.innerHotkey = innerHotkey;
    engineContext.innerPlugins = innerPlugins;
    return {
      designer: designer,
      engineContext: engineContext,
      editor: editor,
      plugins: plugins,
      config: config
    };
  };
  return CoreModelFactory;
}();
var coreModelFactory = exports.coreModelFactory = new CoreModelFactory();