import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _Select from "@alifd/next/es/select";
import React, { Component, useEffect, useState } from "react";
import { OperateEnumType } from "./config";
import { DialogComponent } from "./comComponent/dialogComponent";
import { StorageDataBType, StorageLocalType } from "./type";
import { AlterStateComponent } from "./comComponent/alterStateComponent";
import { BehaviorType } from "../../../src/utils/CLowCodeService/type";
import BoxSlotComponent from "../_components/boxSlotComponent";
import { CDataSourceListSetter } from "..";
import { OpenComponent } from "./comComponent/openComponent";
import { CloseComponent } from "./comComponent/closeComponent";
import { RefreshBoxComponent } from "./comComponent/refreshBoxComponent";
import { CopyToClipboardComponent } from "./comComponent/copyToClipboardComponent";
import { AwaitComponent } from "./comComponent/awaitComponent";
import { getActionDataSource } from "../cFlowEvent-setter/page/utils";
import { t } from "../../../src/locale";
import { StorageDataComponent } from "./comComponent/storageDataComponent";
import { DataSourceType } from "../../_utils/formKeyType";
import { getInitStateKey } from "./config/utils";
import { ChangeWalletEnvComponent } from "./comComponent/changeWalletEnvComponent";
// import { RuleBoxComponent } from "./comComponent/ruleBoxComponent";

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