import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React, { useState, useEffect } from "react";
import { Spin } from '@whalecloud/fdx';
import RenderForm from "./RenderForm";
import appRender from "../../models/appRender";
import ui from "../../models/ui"; // const errorMsg = (name) => {
//   Modal.error({
//     title: '错误！',
//     content: `nameSpace ${name}命名不允许重复！请检查`,
//   });
// }

var FormRender = function FormRender(props) {
  var nameSpace = props.nameSpace;

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

  useEffect(function () {
    var models = window.g_app._models || []; // 注册ui model

    if (models.findIndex(function (v) {
      return v.namespace === ui.namespace;
    }) <= -1) {
      window.g_app.model(ui);
    }

    var registFlag = false;

    if (nameSpace) {
      var exit = models.findIndex(function (v) {
        return v.namespace === nameSpace;
      }) > -1; // if (exit) {
      //   errorMsg(nameSpace);
      // } else {
      //   registFlag = true;
      // }

      registFlag = !exit;
    } else if (!models.some(function (v) {
      return v.namespace === 'appRender';
    })) {
      registFlag = true;
    }

    if (registFlag) {
      // 注册
      window.g_app.model(appRender(nameSpace));
    }

    setLoad(true);
  }, []);
  return load ? /*#__PURE__*/React.createElement(RenderForm, props) : /*#__PURE__*/React.createElement(Spin, null);
};

export default FormRender;
//# sourceMappingURL=FormRender.js.map