"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _select = _interopRequireDefault(require("@alifd/next/lib/select"));
var _react = _interopRequireWildcard(require("react"));
var _locale = require("../../../src/locale");
var _utils = require("../../_utils/utils");
var _rulePanelService = require("../cFlowEvent-setter/page/service/rulePanelService");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
/**
 * 主要用于解析事件流里面的规则节点
 * 多条件的情况下有多组规则，需要依次获取
 * 主要在编辑态切换给CPanelSetter 使用
 */

var PubSub = window.PubSub;
var CRuleNodeListSetter = function CRuleNodeListSetter(props) {
  var field = props.field,
    value = props.value,
    onChange = props.onChange;
  var propsField = field.parent;
  var rulePanelService = new _rulePanelService.RulePanelService();
  var _useState = (0, _react.useState)(value === null || value === void 0 ? void 0 : value.ruleGroupId),
    ruleGroupId = _useState[0],
    setRuleGroupId = _useState[1];
  var _useState2 = (0, _react.useState)(value === null || value === void 0 ? void 0 : value.ruleConfig),
    ruleConfig = _useState2[0],
    setRuleConfig = _useState2[1];
  var _useState3 = (0, _react.useState)([]),
    ruleOptions = _useState3[0],
    setRuleOptions = _useState3[1];
  (0, _react.useEffect)(function () {
    var otherValue = propsField.getPropValue("flowEventConfig");
    if (otherValue) {
      handleFlowEventConfig("", otherValue);
    }
    if (PubSub) {
      var key = _utils.SetterEventName.flowEventConfig + "-" + propsField.id;
      PubSub.subscribe(key, handleFlowEventConfig);
      return function () {
        PubSub.unsubscribe(key, handleFlowEventConfig);
      };
    }
  }, []);
  (0, _react.useEffect)(function () {
    var newData = {
      ruleGroupId: ruleGroupId,
      ruleConfig: ruleConfig
    };
    onChange(newData);
    if (PubSub) {
      var key = _utils.SetterEventName.ruleNodeGroupConfig + "-" + propsField.id;
      PubSub.publish(key, newData);
    }
  }, [ruleGroupId, ruleConfig]);
  var handleFlowEventConfig = function handleFlowEventConfig(key, data) {
    var options = rulePanelService.getRuleNodeOptions(data);
    setRuleOptions(options);
  };
  return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_select["default"], {
    className: "itemOne_select",
    style: {
      width: 100 + "%",
      minWidth: 0
    },
    placeholder: (0, _locale.t)('setter.selectPlaceHolder'),
    dataSource: ruleOptions,
    value: ruleGroupId,
    onChange: function onChange(v, type, item) {
      setRuleGroupId(v);
      setRuleConfig(item);
    }
  }));
};
var _default = exports["default"] = /*#__PURE__*/function (_Component) {
  function _default() {
    return _Component.apply(this, arguments) || this;
  }
  (0, _inheritsLoose2["default"])(_default, _Component);
  var _proto = _default.prototype;
  _proto.render = function render() {
    return /*#__PURE__*/_react["default"].createElement(CRuleNodeListSetter, this.props);
  };
  return _default;
}(_react.Component);