import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _Select from "@alifd/next/es/select";
/**
 * 主要用于解析事件流里面的规则节点
 * 多条件的情况下有多组规则，需要依次获取
 * 主要在编辑态切换给CPanelSetter 使用
 */

import React, { Component, useEffect, useState } from "react";
import { t } from "../../../src/locale";
import { SetterEventName } from "../../_utils/utils";
import { RulePanelService } from "../cFlowEvent-setter/page/service/rulePanelService";
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();
  var _useState = useState(value === null || value === void 0 ? void 0 : value.ruleGroupId),
    ruleGroupId = _useState[0],
    setRuleGroupId = _useState[1];
  var _useState2 = useState(value === null || value === void 0 ? void 0 : value.ruleConfig),
    ruleConfig = _useState2[0],
    setRuleConfig = _useState2[1];
  var _useState3 = useState([]),
    ruleOptions = _useState3[0],
    setRuleOptions = _useState3[1];
  useEffect(function () {
    var otherValue = propsField.getPropValue("flowEventConfig");
    if (otherValue) {
      handleFlowEventConfig("", otherValue);
    }
    if (PubSub) {
      var key = SetterEventName.flowEventConfig + "-" + propsField.id;
      PubSub.subscribe(key, handleFlowEventConfig);
      return function () {
        PubSub.unsubscribe(key, handleFlowEventConfig);
      };
    }
  }, []);
  useEffect(function () {
    var newData = {
      ruleGroupId: ruleGroupId,
      ruleConfig: ruleConfig
    };
    onChange(newData);
    if (PubSub) {
      var key = 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.createElement("div", null, /*#__PURE__*/React.createElement(_Select, {
    className: "itemOne_select",
    style: {
      width: 100 + "%",
      minWidth: 0
    },
    placeholder: t('setter.selectPlaceHolder'),
    dataSource: ruleOptions,
    value: ruleGroupId,
    onChange: function onChange(v, type, item) {
      setRuleGroupId(v);
      setRuleConfig(item);
    }
  }));
};
var _default = /*#__PURE__*/function (_Component) {
  function _default() {
    return _Component.apply(this, arguments) || this;
  }
  _inheritsLoose(_default, _Component);
  var _proto = _default.prototype;
  _proto.render = function render() {
    return /*#__PURE__*/React.createElement(CRuleNodeListSetter, this.props);
  };
  return _default;
}(Component);
export { _default as default };