"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"), _typeof = require("@babel/runtime/helpers/typeof");

Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")), _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")), _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")), _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")), _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), _react = _interopRequireWildcard(require("react")), _propTypes = _interopRequireDefault(require("prop-types")), _rayEventpool = require("ray-eventpool"), _property = _interopRequireDefault(require("./property")), _RuleStage = _interopRequireDefault(require("./RuleStage")), _TriggerEditor = _interopRequireDefault(require("./TriggerEditor")), _stageConf = require("./modelConf/stageConf"), _RuleConfigPanel = _interopRequireDefault(require("./../ruleSetting/RuleConfigPanel"));

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : t;
  })(e);
}

function _interopRequireWildcard(e, t) {
  if (!t && e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var r = _getRequireWildcardCache(t);
  if (r && r.has(e)) return r.get(e);
  var i = {}, a = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var o in e) if ("default" !== o && Object.prototype.hasOwnProperty.call(e, o)) {
    var n = a ? Object.getOwnPropertyDescriptor(e, o) : null;
    n && (n.get || n.set) ? Object.defineProperty(i, o, n) : i[o] = e[o];
  }
  return i.default = e, r && r.set(e, i), i;
}

function ownKeys(e, t) {
  var r = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var i = Object.getOwnPropertySymbols(e);
    t && (i = i.filter((function(t) {
      return Object.getOwnPropertyDescriptor(e, t).enumerable;
    }))), r.push.apply(r, i);
  }
  return r;
}

function _objectSpread(e) {
  for (var t = 1; t < arguments.length; t++) {
    var r = null != arguments[t] ? arguments[t] : {};
    t % 2 ? ownKeys(Object(r), !0).forEach((function(t) {
      (0, _defineProperty2.default)(e, t, r[t]);
    })) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : ownKeys(Object(r)).forEach((function(t) {
      Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(r, t));
    }));
  }
  return e;
}

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, i = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var a = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(i, arguments, a);
    } else r = i.apply(this, arguments);
    return (0, _possibleConstructorReturn2.default)(this, r);
  };
}

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), 
    !0;
  } catch (e) {
    return !1;
  }
}

var StageLayout = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var i;
    return (0, _classCallCheck2.default)(this, r), i = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(i), "handleStatusConnLink", (function(e, t, r) {
      i.setState({
        sourceStatus: {
          id: e.id,
          label: e.textContent
        },
        targetStatus: {
          id: t.id,
          label: t.textContent
        },
        linkId: r.id,
        showTriggerEditor: !1,
        showStatusEditor: !0
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "closeTriggerDesigner", (function() {
      i.setState({
        showTriggerEditor: !1,
        showStatusEditor: !1
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(i), "toggleReloadStage", (function() {
      var e = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
      i.setState({
        needReloadStage: e
      });
    })), i.state = {
      showTriggerEditor: !1,
      showStatusEditor: !1,
      showFlowDesigner: !1,
      actionFlowId: "",
      triggerId: "",
      triggerConfig: {},
      parentConfig: {},
      needReloadStage: !1,
      sourceStatus: {},
      targetStatus: {},
      linkId: "",
      config: {}
    }, i;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentDidMount",
    value: function() {
      var e = this;
      this.pubsub = _rayEventpool.PubSub.subscribe(_stageConf.eleTypeTopic.stage, (function(t, r) {
        var i = r.id, a = (r.preStatus, r.nextStatus, r.config);
        r.parentConfig;
        e.setState({
          showStatusEditor: !0,
          showFlowDesigner: !0,
          actionFlowId: i,
          config: _objectSpread(_objectSpread({}, a), {}, {
            id: i
          })
        });
      }));
    }
  }, {
    key: "componentWillUnmount",
    value: function() {
      _rayEventpool.PubSub.unsubscribe(this.pubsub);
    }
  }, {
    key: "render",
    value: function() {
      var e = this.state, t = e.showStatusEditor, r = e.needReloadStage, i = e.config, a = this.props.params, o = (void 0 === a ? {} : a).libkey;
      return _react.default.createElement("div", {
        className: "rule-layout"
      }, _react.default.createElement("div", {
        className: "rule-stage-container"
      }, _react.default.createElement(_property.default, {
        addNode: this.addNode
      }), _react.default.createElement(_RuleStage.default, {
        objId: o,
        needReloadStage: r,
        toggleReloadStage: this.toggleReloadStage,
        onStatusConnLink: this.handleStatusConnLink
      })), _react.default.createElement(_TriggerEditor.default, {
        expanded: t,
        closeDesigner: this.closeTriggerDesigner
      }, t && _react.default.createElement(_RuleConfigPanel.default, {
        objId: o,
        config: i,
        closeTriggerDesigner: this.closeTriggerDesigner
      })));
    }
  } ]), r;
}(_react.Component);

(0, _defineProperty2.default)(StageLayout, "propTypes", {
  params: _propTypes.default.object
}), StageLayout.displayName = "StageLayout";

var _default = StageLayout;

exports.default = _default;