import _Button from "@alifd/next/es/button";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React from 'react';
import { plugins, project } from '@alilc/lowcode-engine';
import AliLowCodeEngineExt from '@alilc/lowcode-engine-ext';
import UndoRedoPlugin from '@alilc/lowcode-plugin-undo-redo';
import ComponentsPane from '@alilc/lowcode-plugin-components-pane';
import ZhEnPlugin from '@alilc/lowcode-plugin-zh-en';
import CodeGenPlugin from '@alilc/lowcode-plugin-code-generator';
import DataSourcePanePlugin from '@alilc/lowcode-plugin-datasource-pane';
import SchemaPlugin from '@alilc/lowcode-plugin-schema';
import CodeEditor from "@alilc/lowcode-plugin-code-editor";
import ManualPlugin from "@alilc/lowcode-plugin-manual";
import SimulatorResizer from '@alilc/lowcode-plugin-simulator-select';
import Logo from './logo';
var registerDefaultPlugins = /*#__PURE__*/function () {
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
    var builtinPluginRegistry, setterRegistry, saveSample, previewSample;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            _context5.next = 2;
            return plugins.register(ManualPlugin);
          case 2:
            // await plugins.register(Inject);

            // plugin API 见 https://lowcode-engine.cn/docV2/ibh9fh
            SchemaPlugin.pluginName = 'SchemaPlugin';
            _context5.next = 5;
            return plugins.register(SchemaPlugin);
          case 5:
            SimulatorResizer.pluginName = 'SimulatorResizer';
            plugins.register(SimulatorResizer);
            builtinPluginRegistry = function builtinPluginRegistry(ctx) {
              return {
                name: 'builtin-plugin-registry',
                init: function init() {
                  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
                    var _componentsPane$disab;
                    var skeleton, componentsPane;
                    return _regeneratorRuntime.wrap(function _callee$(_context) {
                      while (1) {
                        switch (_context.prev = _context.next) {
                          case 0:
                            skeleton = ctx.skeleton; // 注册 logo 面板
                            skeleton.add({
                              area: 'topArea',
                              type: 'Widget',
                              name: 'logo',
                              content: Logo,
                              contentProps: {
                                logo: 'https://img.alicdn.com/imgextra/i4/O1CN013w2bmQ25WAIha4Hx9_!!6000000007533-55-tps-137-26.svg',
                                href: 'https://lowcode-engine.cn'
                              },
                              props: {
                                align: 'left'
                              }
                            });

                            // 注册组件面板
                            componentsPane = skeleton.add({
                              area: 'leftArea',
                              type: 'PanelDock',
                              name: 'componentsPane',
                              content: ComponentsPane,
                              contentProps: {},
                              props: {
                                align: 'top',
                                icon: 'zujianku',
                                description: '组件库'
                              }
                            });
                            componentsPane === null || componentsPane === void 0 ? void 0 : (_componentsPane$disab = componentsPane.disable) === null || _componentsPane$disab === void 0 ? void 0 : _componentsPane$disab.call(componentsPane);
                            project.onSimulatorRendererReady(function () {
                              var _componentsPane$enabl;
                              componentsPane === null || componentsPane === void 0 ? void 0 : (_componentsPane$enabl = componentsPane.enable) === null || _componentsPane$enabl === void 0 ? void 0 : _componentsPane$enabl.call(componentsPane);
                            });
                          case 5:
                          case "end":
                            return _context.stop();
                        }
                      }
                    }, _callee);
                  }))();
                }
              };
            };
            builtinPluginRegistry.pluginName = 'builtinPluginRegistry';
            _context5.next = 11;
            return plugins.register(builtinPluginRegistry);
          case 11:
            // 设置内置 setter 和事件绑定、插件绑定面板
            setterRegistry = function setterRegistry(ctx) {
              var setterMap = AliLowCodeEngineExt.setterMap,
                pluginMap = AliLowCodeEngineExt.pluginMap;
              return {
                name: 'ext-setters-registry',
                init: function init() {
                  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
                    var setters, skeleton;
                    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
                      while (1) {
                        switch (_context2.prev = _context2.next) {
                          case 0:
                            setters = ctx.setters, skeleton = ctx.skeleton; // 注册setterMap
                            setters.registerSetter(setterMap);
                            // 注册插件
                            // 注册事件绑定面板
                            skeleton.add({
                              area: 'centerArea',
                              type: 'Widget',
                              content: pluginMap.EventBindDialog,
                              name: 'eventBindDialog',
                              props: {}
                            });

                            // 注册变量绑定面板
                            skeleton.add({
                              area: 'centerArea',
                              type: 'Widget',
                              content: pluginMap.VariableBindDialog,
                              name: 'variableBindDialog',
                              props: {}
                            });
                          case 4:
                          case "end":
                            return _context2.stop();
                        }
                      }
                    }, _callee2);
                  }))();
                }
              };
            };
            setterRegistry.pluginName = 'setterRegistry';
            _context5.next = 15;
            return plugins.register(setterRegistry);
          case 15:
            _context5.next = 17;
            return plugins.register(UndoRedoPlugin);
          case 17:
            _context5.next = 19;
            return plugins.register(ZhEnPlugin);
          case 19:
            // 注册保存面板
            saveSample = function saveSample(ctx) {
              return {
                name: 'saveSample',
                init: function init() {
                  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
                    var skeleton, hotkey;
                    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
                      while (1) {
                        switch (_context3.prev = _context3.next) {
                          case 0:
                            skeleton = ctx.skeleton, hotkey = ctx.hotkey;
                            skeleton.add({
                              name: 'saveSample',
                              area: 'topArea',
                              type: 'Widget',
                              props: {
                                align: 'right'
                              },
                              content: /*#__PURE__*/React.createElement(_Button, {
                                onClick: function onClick() {}
                              }, "\u4FDD\u5B58\u5230\u672C\u5730")
                            });
                            skeleton.add({
                              name: 'resetSchema',
                              area: 'topArea',
                              type: 'Widget',
                              props: {
                                align: 'right'
                              },
                              content: /*#__PURE__*/React.createElement(_Button, {
                                onClick: function onClick() {}
                              }, "\u91CD\u7F6E\u9875\u9762")
                            });
                            hotkey.bind('command+s', function (e) {
                              e.preventDefault();
                              // saveSchema();
                            });
                          case 4:
                          case "end":
                            return _context3.stop();
                        }
                      }
                    }, _callee3);
                  }))();
                }
              };
            };
            saveSample.pluginName = 'saveSample';
            _context5.next = 23;
            return plugins.register(saveSample);
          case 23:
            DataSourcePanePlugin.pluginName = 'DataSourcePane';
            // 插件参数声明 & 传递，参考：https://www.yuque.com/lce/doc/ibh9fh#peEmG
            _context5.next = 26;
            return plugins.register(DataSourcePanePlugin, {
              importPlugins: [],
              dataSourceTypes: [{
                type: 'fetch'
              }, {
                type: 'jsonp'
              }]
            });
          case 26:
            CodeEditor.pluginName = 'CodeEditor';
            _context5.next = 29;
            return plugins.register(CodeEditor);
          case 29:
            // 注册出码插件
            CodeGenPlugin.pluginName = 'CodeGenPlugin';
            _context5.next = 32;
            return plugins.register(CodeGenPlugin);
          case 32:
            previewSample = function previewSample(ctx) {
              return {
                name: 'previewSample',
                init: function init() {
                  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
                    var skeleton;
                    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
                      while (1) {
                        switch (_context4.prev = _context4.next) {
                          case 0:
                            skeleton = ctx.skeleton;
                            skeleton.add({
                              name: 'previewSample',
                              area: 'topArea',
                              type: 'Widget',
                              props: {
                                align: 'right'
                              },
                              content: /*#__PURE__*/React.createElement(_Button, {
                                type: "primary",
                                onClick: function onClick() {}
                              }, "\u9884\u89C8")
                            });
                          case 2:
                          case "end":
                            return _context4.stop();
                        }
                      }
                    }, _callee4);
                  }))();
                }
              };
            };
            previewSample.pluginName = 'previewSample';
            _context5.next = 36;
            return plugins.register(previewSample);
          case 36:
            console.log('完成内置插件注册');
          case 37:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return function registerDefaultPlugins() {
    return _ref.apply(this, arguments);
  };
}();
export default registerDefaultPlugins;