"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 _config = require("./config");
var _dialogComponent = require("./comComponent/dialogComponent");
var _type = require("./type");
var _alterStateComponent = require("./comComponent/alterStateComponent");
var _type2 = require("../../../src/utils/CLowCodeService/type");
var _boxSlotComponent = _interopRequireDefault(require("../_components/boxSlotComponent"));
var _ = require("..");
var _openComponent = require("./comComponent/openComponent");
var _closeComponent = require("./comComponent/closeComponent");
var _refreshBoxComponent = require("./comComponent/refreshBoxComponent");
var _copyToClipboardComponent = require("./comComponent/copyToClipboardComponent");
var _awaitComponent = require("./comComponent/awaitComponent");
var _utils = require("../cFlowEvent-setter/page/utils");
var _locale = require("../../../src/locale");
var _storageDataComponent = require("./comComponent/storageDataComponent");
var _formKeyType = require("../../_utils/formKeyType");
var _utils2 = require("./config/utils");
var _changeWalletEnvComponent = require("./comComponent/changeWalletEnvComponent");
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; }
// import { RuleBoxComponent } from "./comComponent/ruleBoxComponent";

var CBehaviorSetter = function CBehaviorSetter(props) {
  var value = props.value,
    onChange = props.onChange;
  var _useState = (0, _react.useState)((value === null || value === void 0 ? void 0 : value.type) || ""),
    type = _useState[0],
    setType = _useState[1];
  var _useState2 = (0, _react.useState)(value === null || value === void 0 ? void 0 : value.data),
    data = _useState2[0],
    setData = _useState2[1];
  (0, _react.useEffect)(function () {
    if (type) {
      var obj = {
        type: type,
        data: data
      };
      onChange(obj);
    }
  }, [type, data]);
  var initSetData = function initSetData(v) {
    if (v === _type2.BehaviorType.closeBehavior) {
      setData({
        operateType: _config.OperateEnumType.Dialog,
        modelName: [],
        modelTreeData: []
      });
    } else if (v === _type2.BehaviorType.alterStateBehavior || v === _type2.BehaviorType.requestBehavior || v === _type2.BehaviorType.refreshBehavior) {
      setData([]);
    } else if (v === _type2.BehaviorType.openBehavior) {
      setData({
        operateType: _config.OperateEnumType.Dialog,
        modelName: [],
        modelTreeData: [],
        messageConfig: {
          openType: false,
          modeTypeList: [],
          contentList: []
        }
      });
    } else if (v === _type2.BehaviorType.closeProBehavior) {
      setData({
        operateType: _config.OperateEnumType.RotateWheel
      });
    } else if (v === _type2.BehaviorType.copyToClipboard || v === _type2.BehaviorType.awaitBehavior) {
      setData(null);
    } else if (v === _type2.BehaviorType.storageDataBehavior) {
      var _data = {
        type: _type.StorageDataBType.Local,
        localConfig: {
          type: _type.StorageLocalType.LocalStorage,
          key: (0, _utils2.getInitStateKey)(_formKeyType.DataSourceType.defaultType, ''),
          value: (0, _utils2.getInitStateKey)(_formKeyType.DataSourceType.defaultType, '')
        }
      };
      setData(_data);
    }
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "CBehaviorBox"
  }, /*#__PURE__*/_react["default"].createElement(_boxSlotComponent["default"], {
    title: (0, _locale.t)("setter.actionType")
  }, /*#__PURE__*/_react["default"].createElement(_select["default"], {
    className: "itemOne_select",
    style: {
      width: 100 + "%",
      minWidth: 0
    },
    placeholder: (0, _locale.t)("setter.selectPlaceHolder"),
    notFoundContent: (0, _locale.t)("setter.notFoundContent"),
    dataSource: (0, _utils.getActionDataSource)(),
    value: type,
    onChange: function onChange(v) {
      setType(v);
      initSetData(v);
    }
  })), type === _type2.BehaviorType.closeBehavior && /*#__PURE__*/_react["default"].createElement(_dialogComponent.DialogComponent, {
    title: (0, _locale.t)("setter.closeBehavior"),
    value: data,
    onChange: function onChange(e) {
      setData(e);
    }
  }), type === _type2.BehaviorType.closeProBehavior && /*#__PURE__*/_react["default"].createElement(_closeComponent.CloseComponent, {
    value: data,
    onChange: function onChange(e) {
      setData(e);
    }
  }), type === _type2.BehaviorType.alterStateBehavior && /*#__PURE__*/_react["default"].createElement(_alterStateComponent.AlterStateComponent, {
    value: data,
    onChange: function onChange(e) {
      setData(e ? e : []);
    }
  }), type === _type2.BehaviorType.openBehavior && /*#__PURE__*/_react["default"].createElement(_openComponent.OpenComponent, {
    value: data,
    onChange: function onChange(e) {
      setData(e);
    }
  }), type === _type2.BehaviorType.requestBehavior && /*#__PURE__*/_react["default"].createElement(_.CDataSourceListSetter, {
    value: data,
    onChange: function onChange(e) {
      setData(e ? e : []);
    }
  }), type === _type2.BehaviorType.refreshBehavior && /*#__PURE__*/_react["default"].createElement(_refreshBoxComponent.RefreshBoxComponent, {
    value: data,
    onChange: function onChange(e) {
      setData(e);
    }
  }), type === _type2.BehaviorType.copyToClipboard && /*#__PURE__*/_react["default"].createElement(_copyToClipboardComponent.CopyToClipboardComponent, {
    value: data,
    onChange: function onChange(e) {
      setData(e);
    }
  }), type === _type2.BehaviorType.awaitBehavior && /*#__PURE__*/_react["default"].createElement(_awaitComponent.AwaitComponent, {
    value: data,
    onChange: function onChange(e) {
      setData(e);
    }
  }), type === _type2.BehaviorType.storageDataBehavior && /*#__PURE__*/_react["default"].createElement(_storageDataComponent.StorageDataComponent, {
    value: data,
    onChange: function onChange(e) {
      setData(e);
    }
  }), type === _type2.BehaviorType.changeWalletEnv && /*#__PURE__*/_react["default"].createElement(_changeWalletEnvComponent.ChangeWalletEnvComponent, {
    value: data,
    onChange: function onChange(e) {
      setData(e);
    }
  }));
};
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(CBehaviorSetter, this.props);
  };
  return _default;
}(_react.Component);