"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 _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _boxSlotComponent = _interopRequireDefault(require("../../../../_components/boxSlotComponent"));
var _conditionDialogRender = _interopRequireDefault(require("../../components/conditionDialogRender"));
var _type = require("../../../../../_utils/conditionRenderService/type");
var _locale = require("../../../../../../src/locale");
var _conditionRenderService = require("../../../../../_utils/conditionRenderService");
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; }
var ConditionSetterPanel = function ConditionSetterPanel(props) {
  var _current$config;
  var current = props.current,
    onChange = props.onChange;
  var conditionRenderService = new _conditionRenderService.ConditionRenderService();
  var _useState = (0, _react.useState)((_current$config = current.config) === null || _current$config === void 0 ? void 0 : _current$config.detail),
    conditionData = _useState[0],
    setConditionData = _useState[1];
  (0, _react.useEffect)(function () {
    if (conditionData && conditionData.data && conditionData.resultData) return;

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