import _extends from "@babel/runtime/helpers/extends";
import React, { useEffect, useState } from "react";
import BoxSlotComponent from "../../_components/boxSlotComponent";
import { t } from "../../../../src/locale";
import RenderByFormKey from "../../_components/renderByFormKey";
import { getRelationList } from "../../../_utils/formKeyType";
import { handleStringToRequest } from "../config/utils";
import { handleRenderByFormKeyData } from "../../../_utils/utils";
export var ToLinkComponent = function ToLinkComponent(props) {
  var _useState = useState([]),
    telegramRelationOption = _useState[0],
    setTelegramRelationOption = _useState[1];
  var _useState2 = useState(handleStringToRequest(props.value)),
    link = _useState2[0],
    setLink = _useState2[1];
  useEffect(function () {
    setTelegramRelationOption(getRelationList());
  }, []);
  useEffect(function () {
    props.onChange(link);
  }, [link]);
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(BoxSlotComponent, {
    title: t("setter.toLinkUrl")
  }, /*#__PURE__*/React.createElement(RenderByFormKey, {
    relationOption: telegramRelationOption,
    value: link,
    onChange: function onChange(v) {
      handleRenderByFormKeyData(v, function (newItem) {
        var newData = _extends({}, link, newItem);
        setLink(newData);
      });
    }
  })));
};