import _extends from "@babel/runtime/helpers/extends";
import BoxSlotComponent from "../../_components/boxSlotComponent";
import RenderByFormKey from "../../_components/renderByFormKey";
import { DataSourceType, getRelationList } from "../../../_utils/formKeyType";
import { handleRenderByFormKeyData, uuid } from "../../../_utils/utils";
import React, { useEffect, useState } from "react";
import { t } from "../../../../src/locale";
export var CopyToClipboardComponent = function CopyToClipboardComponent(props) {
  var value = props.value,
    onChange = props.onChange;
  var _useState = useState(value || {}),
    copyData = _useState[0],
    setCopyData = _useState[1];
  var _useState2 = useState([]),
    relationOption = _useState2[0],
    setRelationOption = _useState2[1];
  useEffect(function () {
    setRelationOption(getRelationList());
    if (!value) {
      var newCopyData = {
        id: uuid(),
        formKey: DataSourceType.defaultType,
        data: "",
        treeData: []
      };
      setCopyData(newCopyData);
    }
  }, []);
  useEffect(function () {
    onChange(copyData);
  }, [copyData]);
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(BoxSlotComponent, {
    title: t("setter.copyDataSource")
  }, /*#__PURE__*/React.createElement(RenderByFormKey, {
    relationOption: relationOption,
    value: copyData,
    onChange: function onChange(v) {
      handleRenderByFormKeyData(v, function (newItem) {
        var newCopy = _extends({}, copyData, newItem);
        setCopyData(newCopy);
      });
    }
  })));
};