import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _isEqual from "lodash/isEqual";
import React, { useState, useEffect } from "react";
import { connect } from "../redux";
import { Spin } from '@whalecloud/fdx';
import { formBuilderConfig } from "../../config/config";
import { registerFormBuilderModels } from "../utils";
import BuildForm from "./BuildForm";

var FormBuilder = function FormBuilder(props) {
  var saveConfig = props.saveConfig,
      _props$extraConfig = props.extraConfig,
      extraConfig = _props$extraConfig === void 0 ? {} : _props$extraConfig,
      restProps = _objectWithoutProperties(props, ["saveConfig", "extraConfig"]);

  var _useState = useState(false),
      _useState2 = _slicedToArray(_useState, 2),
      load = _useState2[0],
      setLoad = _useState2[1];

  useEffect(function () {
    // 导入编辑器model
    registerFormBuilderModels();
    setLoad(true); // 保存config设置

    var config = _objectSpread(_objectSpread(_objectSpread({}, formBuilderConfig), extraConfig), restProps);

    saveConfig({
      config: config
    });
  }, []);
  return load ? /*#__PURE__*/React.createElement(BuildForm, props) : /*#__PURE__*/React.createElement(Spin, null);
};

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

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