import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _extends from "@babel/runtime/helpers/extends";
import { getRelationList } from "../../_utils/formKeyType";
import React, { Component, useState, useEffect } from "react";
import "./index.less";
import { handleStringToRequest } from "../cBehavior-setter/config/utils";
import { handleRenderByFormKeyData } from "../../_utils/utils";
import RenderByFormKey from "../_components/renderByFormKey";

/**
 * 处理默认值数据
 * @param props
 * @returns
 */
var CDefaultValueSetter = function CDefaultValueSetter(props) {
  var _useState = useState([]),
    telegramRelationOption = _useState[0],
    setTelegramRelationOption = _useState[1];
  var _useState2 = useState(handleStringToRequest(props.value)),
    defaultData = _useState2[0],
    setDefaultData = _useState2[1];
  useEffect(function () {
    setTelegramRelationOption(getRelationList());
  }, []);
  useEffect(function () {
    props.onChange(defaultData);
  }, [defaultData]);
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(RenderByFormKey, {
    relationOption: telegramRelationOption,
    value: defaultData,
    onChange: function onChange(v) {
      handleRenderByFormKeyData(v, function (newItem) {
        var newData = _extends({}, defaultData, newItem);
        setDefaultData(newData);
      });
    }
  }));
};
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(CDefaultValueSetter, this.props);
  };
  return _default;
}(Component);
export { _default as default };