"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.RotateWheelComponent = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _select = _interopRequireDefault(require("@alifd/next/lib/select"));
var _react = _interopRequireWildcard(require("react"));
var _boxSlotComponent = _interopRequireDefault(require("../../_components/boxSlotComponent"));
var _locale = require("../../../../src/locale");
var _schemaService = require("../../../_utils/schemaService");
var _renderByFormKey = _interopRequireDefault(require("../../_components/renderByFormKey"));
var _utils = require("../config/utils");
var _utils2 = require("../../../_utils/utils");
var _formKeyType = require("../../../_utils/formKeyType");
var _type = require("../type");
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 RotateWheelComponent = exports.RotateWheelComponent = function RotateWheelComponent(props) {
  var type = props.type,
    value = props.value,
    onChange = props.onChange;
  var _useState = (0, _react.useState)((value === null || value === void 0 ? void 0 : value.componentKey) || ""),
    componentKey = _useState[0],
    setComponentKey = _useState[1];
  var _useState2 = (0, _react.useState)((0, _utils.handleStringToRequest)(value === null || value === void 0 ? void 0 : value.responseParams)),
    responseParams = _useState2[0],
    setResponseParams = _useState2[1];
  var _useState3 = (0, _react.useState)([]),
    rotateWheelDataSource = _useState3[0],
    setRotateWheelDataSource = _useState3[1];
  var _useState4 = (0, _react.useState)([]),
    telegramRelationOption = _useState4[0],
    setTelegramRelationOption = _useState4[1];
  (0, _react.useEffect)(function () {
    var schemaService = new _schemaService.SchemaService();
    var gList = schemaService.getRotateWheelListData();
    setRotateWheelDataSource(gList);
    setTelegramRelationOption((0, _formKeyType.getRelationList)());
  }, []);
  (0, _react.useEffect)(function () {
    onChange({
      componentKey: componentKey,
      responseParams: responseParams
    });
  }, [componentKey, responseParams]);
  return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_boxSlotComponent["default"], {
    title: (0, _locale.t)("setter.RotateWheelComponent")
  }, /*#__PURE__*/_react["default"].createElement(_select["default"], {
    placeholder: (0, _locale.t)("setter.selectPlaceHolder"),
    notFoundContent: (0, _locale.t)("setter.notFoundContent"),
    showSearch: true,
    value: componentKey,
    dataSource: rotateWheelDataSource,
    onChange: function onChange(v) {
      setComponentKey(v);
    }
  })), type === _type.OperationType.stop && /*#__PURE__*/_react["default"].createElement(_boxSlotComponent["default"], {
    title: "" + (0, _locale.t)("setter.result")
  }, /*#__PURE__*/_react["default"].createElement(_renderByFormKey["default"], {
    relationOption: telegramRelationOption,
    value: responseParams,
    onChange: function onChange(v) {
      (0, _utils2.handleRenderByFormKeyData)(v, function (newItem) {
        var newData = (0, _extends2["default"])({}, responseParams, newItem);
        setResponseParams(newData);
      });
    }
  })));
};