"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports["default"] = void 0;

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var _lowcodeEngine = require("@alilc/lowcode-engine");

var _utils = require("../utils");

var _logo = _interopRequireDefault(require("../plugins/logo"));

require("../plugins/register-plugins");

require("../setters/register-setters");

require("./global.scss");

require("./cover.scss");

var isNewEngineVersion = !!_lowcodeEngine.material;

function initPlugins(init, customPlugins, options) {
  var _ref = options || {},
      logo = _ref.logo;

  _lowcodeEngine.plugins.register(_logo["default"], logo);

  if (customPlugins && Array.isArray(customPlugins) && customPlugins.length) {
    customPlugins.map(function (plugin) {
      _lowcodeEngine.plugins.register(plugin);
    });
  }

  if (init) {
    init.pluginName = 'editorInit';
    return _lowcodeEngine.plugins.register(init);
  } // 默认 init 插件


  _lowcodeEngine.plugins.register(function () {
    return {
      name: "editor-init",
      init: function init() {
        return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
          var assets, schema;
          return _regenerator["default"].wrap(function _callee$(_context) {
            while (1) {
              switch (_context.prev = _context.next) {
                case 0:
                  _context.next = 2;
                  return _lowcodeEngine.editor.utils.get('https://unpkg.alibaba-inc.com/@ali/ali-lowcode-materials/dist/assets.json');

                case 2:
                  assets = _context.sent;

                  if (isNewEngineVersion) {
                    _lowcodeEngine.material.setAssets(assets);
                  } else {
                    _lowcodeEngine.editor.setAssets(assets);
                  }

                  _context.t0 = (0, _utils.getPageSchema)();

                  if (_context.t0) {
                    _context.next = 9;
                    break;
                  }

                  _context.next = 8;
                  return _lowcodeEngine.editor.utils.get("./schema.json");

                case 8:
                  _context.t0 = _context.sent;

                case 9:
                  schema = _context.t0;

                  if (isNewEngineVersion) {
                    _lowcodeEngine.project.openDocument(schema);
                  } else {
                    _lowcodeEngine.project.open(schema);
                  }

                case 11:
                case "end":
                  return _context.stop();
              }
            }
          }, _callee);
        }))();
      }
    };
  });
}

var _default = initPlugins;
exports["default"] = _default;