import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _extends from "@babel/runtime/helpers/extends";
import React, { Component, useEffect, useState } from "react";
import BoxSlotComponent from "../../../../_components/boxSlotComponent";
import ConditionDialogRender from "../../components/conditionDialogRender";
import { ConditionType } from "../../../../../_utils/conditionRenderService/type";
import { t } from "../../../../../../src/locale";
import { ConditionRenderService } from "../../../../../_utils/conditionRenderService";
var ConditionSetterPanel = function ConditionSetterPanel(props) {
  var _current$config;
  var current = props.current,
    onChange = props.onChange;
  var conditionRenderService = new ConditionRenderService();
  var _useState = useState((_current$config = current.config) === null || _current$config === void 0 ? void 0 : _current$config.detail),
    conditionData = _useState[0],
    setConditionData = _useState[1];
  useEffect(function () {
    if (conditionData && conditionData.data && conditionData.resultData) return;

    // 初始化数据
    var _data = conditionRenderService.createInitItemOneByType(ConditionType.all);
    var resultData = conditionRenderService.createInitResultData();
    setConditionData({
      data: [_data],
      resultData: resultData
    });
  }, []);
  var onConditionChange = function onConditionChange(data) {
    var obj = _extends({}, current, {
      config: {
        detail: data
      }
    });
    onChange(obj);
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "condition-box"
  }, /*#__PURE__*/React.createElement(BoxSlotComponent, {
    title: t("setter.conditionSet")
  }, /*#__PURE__*/React.createElement(ConditionDialogRender, {
    value: conditionData,
    onChange: onConditionChange
  })));
};
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(ConditionSetterPanel, this.props);
  };
  return _default;
}(Component);
export { _default as default };