import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _isEqual from "lodash/isEqual";
import React, { useEffect } from 'react';
import { Provider, useStore } from 'react-redux';
import HTML5Backend from 'react-dnd-html5-backend';
import { DndProvider } from 'react-dnd';
import { Editor } from "./Editor";
import { connect } from "../redux";
import { EditorPluginsLoader } from "./PluginsLoader/PluginsLoader";
import { PageBuilderProvider } from "../../contexts/PageBuilder/PageBuilderContext";
import "./formBuilder.less";
import "./formBuilder.css";
import "./formApp.css";

var PageBuilderContainer = function PageBuilderContainer(props) {
  var save = props.save,
      pageContent = props.pageContent,
      setInitialPageJson = props.setInitialPageJson,
      afterRegister = props.afterRegister,
      restProps = _objectWithoutProperties(props, ["save", "pageContent", "setInitialPageJson", "afterRegister"]);

  useEffect(function () {
    try {
      if (pageContent && pageContent !== '{}') {
        var content = JSON.parse(pageContent);

        if (content.id) {
          setInitialPageJson({
            content: content
          });
        }
      }
    } catch (e) {
      console.error("\u521D\u59CB\u6570\u636E\u89E3\u6790\u9519\u8BEF: ".concat(pageContent, " \u89E3\u6790\u6709\u8BEF\uFF0C\u8BF7\u68C0\u67E5"), e);
    }
  }, [pageContent]);
  var store = useStore();
  return /*#__PURE__*/React.createElement(EditorPluginsLoader, {
    type: "edit",
    afterRegister: afterRegister
  }, /*#__PURE__*/React.createElement(PageBuilderProvider, null, /*#__PURE__*/React.createElement(Provider, {
    store: store
  }, /*#__PURE__*/React.createElement(DndProvider, {
    backend: HTML5Backend
  }, /*#__PURE__*/React.createElement(Editor, Object.assign({
    save: save
  }, restProps, {
    showProperty: true
  }))))));
};

var mapDispatchToProps = function mapDispatchToProps(dispatch) {
  return {
    setInitialPageJson: function setInitialPageJson(payload) {
      dispatch({
        type: 'appBuilder/setInitialPageJson',
        payload: payload
      });
    }
  };
};

export default connect(null, mapDispatchToProps, null, {
  areStatePropsEqual: _isEqual
})(PageBuilderContainer);
//# sourceMappingURL=PageBuilderContainer.js.map