import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import React from 'react';
import cloneDeep from 'lodash/cloneDeep';
import { registerPlugins, getPlugins } from "../../../plugins";
import { ElementGroup } from "../../../constant";
import { ReactComponent as PluginIcon } from "@svgr/webpack!../../assets/icons/private_block.svg";
import { PreviewBox, createRow } from "../../utils";
export default (function (el) {
  if (!el.content) {
    return;
  }

  var content = JSON.parse(el.content);
  var rootPlugin = getPlugins('pb-editor-page-element').find(function (pl) {
    return content && pl.elementType === content.type;
  });

  if (!rootPlugin) {
    return;
  }

  var name = "saved-element-".concat(el.name);

  var plugin = _objectSpread(_objectSpread({}, rootPlugin), {}, {
    name: name,
    type: 'pb-editor-page-element',
    elementType: name,
    target: rootPlugin.target,
    toolbar: {
      title: el.name,
      group: ElementGroup.SAVE,
      // 区块统一放至'pb-editor-element-group-saved'分组下
      preview: function preview() {
        // 暂时写死
        return /*#__PURE__*/React.createElement(PreviewBox, null, /*#__PURE__*/React.createElement(PluginIcon, null));
      }
    },
    settings: rootPlugin ? rootPlugin.settings : [],
    create: function create() {
      var block = cloneDeep(content);
      var container = block;

      if (block.type === 'column') {
        container = createRow({
          elements: [block]
        });
      }

      return container;
    }
  });

  registerPlugins([plugin]);
  return plugin;
});
//# sourceMappingURL=createElementsPlugin.js.map