import _extends from "@babel/runtime/helpers/extends";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import * as React from 'react';
import { Suspense } from 'react';
import { PluginMode, EntrySchema, Env } from '@cverse/core-lib-beta';
import { applyVueInReact } from 'veaury';
import { CLowCodeService } from "../../utils/CLowCodeService";
import VueComp from "./index.vue";
//打包
var ReactComp = applyVueInReact(VueComp);
var Governance = function Governance(props) {
  var entrySchema = props.entrySchema,
    __designMode = props.__designMode,
    cusTomEntry = props.cusTomEntry,
    beforeFlowEventConfig = props.beforeFlowEventConfig,
    afterFlowEventConfig = props.afterFlowEventConfig;
  var cLowCodeService = new CLowCodeService();
  var flowEventCallbackBeforeFn = /*#__PURE__*/function () {
    var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(data) {
      var result;
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            result = false;
            if (!beforeFlowEventConfig) {
              _context.next = 6;
              break;
            }
            cLowCodeService.loadPageProps(props);
            _context.next = 5;
            return cLowCodeService.handleFlowEvent(beforeFlowEventConfig);
          case 5:
            result = _context.sent;
          case 6:
            return _context.abrupt("return", result);
          case 7:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function flowEventCallbackBeforeFn(_x) {
      return _ref.apply(this, arguments);
    };
  }();
  var flowEventCallbackAfterFn = /*#__PURE__*/function () {
    var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(data) {
      return _regeneratorRuntime.wrap(function _callee2$(_context2) {
        while (1) switch (_context2.prev = _context2.next) {
          case 0:
            if (!afterFlowEventConfig) {
              _context2.next = 4;
              break;
            }
            cLowCodeService.loadPageProps(props);
            _context2.next = 4;
            return cLowCodeService.handleFlowEvent(afterFlowEventConfig);
          case 4:
          case "end":
            return _context2.stop();
        }
      }, _callee2);
    }));
    return function flowEventCallbackAfterFn(_x2) {
      return _ref2.apply(this, arguments);
    };
  }();
  if (entrySchema == undefined) {
    return /*#__PURE__*/React.createElement("div", null);
  }
  var _entrySchema = entrySchema ? JSON.parse(entrySchema) : new EntrySchema();
  var mode = __designMode === 'design' ? PluginMode.EmbedEdit : PluginMode.EmbedCall;
  if (cusTomEntry) {
    _entrySchema.entry = _extends({}, cusTomEntry, _entrySchema.entry, {
      env: Env.IDE_WEB
    });
  }
  if (beforeFlowEventConfig) {
    _entrySchema.entry = _extends({}, _entrySchema.entry, {
      flowEventCallbackBefore: flowEventCallbackBeforeFn
    });
  }
  if (afterFlowEventConfig) {
    _entrySchema.entry = _extends({}, _entrySchema.entry, {
      flowEventCallbackAfter: flowEventCallbackAfterFn
    });
  }
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Suspense, {
    fallback: /*#__PURE__*/React.createElement("div", null)
  }, /*#__PURE__*/React.createElement(ReactComp, {
    instance: _entrySchema.instance,
    entry: _entrySchema.entry,
    mode: mode
  })));
};
Governance.displayName = 'Governance';
export default Governance;