"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.TelegramComponent = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _select = _interopRequireDefault(require("@alifd/next/lib/select"));
var _react = _interopRequireWildcard(require("react"));
var _type = require("../type");
var _boxSlotComponent = _interopRequireDefault(require("../../_components/boxSlotComponent"));
var _renderByFormKey = _interopRequireDefault(require("../../_components/renderByFormKey"));
var _locale = require("../../../../src/locale");
var _formKeyType = require("../../../_utils/formKeyType");
var _utils = require("../../../_utils/utils");
var _utils2 = require("../config/utils");
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 TelegramOptions = [{
  label: (0, _locale.t)("setter.share"),
  value: _type.TelegramType.share
}, {
  label: (0, _locale.t)("setter.link"),
  value: _type.TelegramType.link
}, {
  label: (0, _locale.t)("setter.touch"),
  value: _type.TelegramType.touch
}];
var TouchOptions = [{
  label: (0, _locale.t)("setter.touchSoft"),
  value: _type.TouchSelectType.soft
}, {
  label: (0, _locale.t)("setter.touchRigid"),
  value: _type.TouchSelectType.rigid
}, {
  label: (0, _locale.t)("setter.touchLight"),
  value: _type.TouchSelectType.light
}, {
  label: (0, _locale.t)("setter.touchMedium"),
  value: _type.TouchSelectType.medium
}, {
  label: (0, _locale.t)("setter.touchHeavy"),
  value: _type.TouchSelectType.heavy
}];
var TelegramComponent = exports.TelegramComponent = function TelegramComponent(props) {
  var _value$data, _value$data2, _value$data2$shareDat, _value$data3, _value$data3$shareDat, _value$data4, _value$data4$shareDat, _value$data5;
  var value = props.value,
    onChange = props.onChange;
  var _useState = (0, _react.useState)((value === null || value === void 0 ? void 0 : value.type) || _type.TelegramType.share),
    type = _useState[0],
    setType = _useState[1];
  var _useState2 = (0, _react.useState)((value === null || value === void 0 ? void 0 : (_value$data = value.data) === null || _value$data === void 0 ? void 0 : _value$data.linkUrl) || (0, _utils2.getInitStateKey)(_formKeyType.DataSourceType.defaultType, '')),
    linkUrl = _useState2[0],
    setLinkUrl = _useState2[1];
  var _useState3 = (0, _react.useState)((0, _utils2.handleStringToRequest)(value === null || value === void 0 ? void 0 : (_value$data2 = value.data) === null || _value$data2 === void 0 ? void 0 : (_value$data2$shareDat = _value$data2.shareData) === null || _value$data2$shareDat === void 0 ? void 0 : _value$data2$shareDat.url)),
    shareUrl = _useState3[0],
    setShareUrl = _useState3[1];
  var _useState4 = (0, _react.useState)((value === null || value === void 0 ? void 0 : (_value$data3 = value.data) === null || _value$data3 === void 0 ? void 0 : (_value$data3$shareDat = _value$data3.shareData) === null || _value$data3$shareDat === void 0 ? void 0 : _value$data3$shareDat.startApp) || (0, _utils2.getInitStateKey)(_formKeyType.DataSourceType.defaultType, '')),
    shareStartApp = _useState4[0],
    setShareStartApp = _useState4[1];
  var _useState5 = (0, _react.useState)((0, _utils2.handleStringToRequest)(value === null || value === void 0 ? void 0 : (_value$data4 = value.data) === null || _value$data4 === void 0 ? void 0 : (_value$data4$shareDat = _value$data4.shareData) === null || _value$data4$shareDat === void 0 ? void 0 : _value$data4$shareDat.content)),
    shareContent = _useState5[0],
    setShareContent = _useState5[1];
  var _useState6 = (0, _react.useState)((value === null || value === void 0 ? void 0 : (_value$data5 = value.data) === null || _value$data5 === void 0 ? void 0 : _value$data5.touchType) || _type.TouchSelectType.soft),
    touchType = _useState6[0],
    setTouchType = _useState6[1];
  var _useState7 = (0, _react.useState)([]),
    telegramRelationOption = _useState7[0],
    setTelegramRelationOption = _useState7[1];
  (0, _react.useEffect)(function () {
    setTelegramRelationOption((0, _formKeyType.getRelationList)());
  }, []);
  (0, _react.useEffect)(function () {
    var obj = {
      type: type,
      data: {
        linkUrl: linkUrl,
        shareData: {
          url: shareUrl,
          startApp: shareStartApp,
          content: shareContent
        },
        touchType: touchType
      }
    };
    onChange(obj);
  }, [type, linkUrl, shareUrl, shareStartApp, shareContent, touchType]);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "awaitComponentBox"
  }, /*#__PURE__*/_react["default"].createElement(_boxSlotComponent["default"], {
    title: "" + (0, _locale.t)('setter.linkType')
  }, /*#__PURE__*/_react["default"].createElement(_select["default"], {
    className: "itemOne_select",
    style: {
      width: 100 + "%",
      minWidth: 0
    },
    placeholder: (0, _locale.t)("setter.selectPlaceHolder"),
    notFoundContent: (0, _locale.t)('setter.notFoundContent'),
    dataSource: TelegramOptions,
    value: type,
    onChange: function onChange(v) {
      setType(v);
    }
  })), type === _type.TelegramType.link && /*#__PURE__*/_react["default"].createElement(_boxSlotComponent["default"], {
    title: "" + (0, _locale.t)('setter.linkOriginUrl')
  }, /*#__PURE__*/_react["default"].createElement(_renderByFormKey["default"], {
    relationOption: telegramRelationOption,
    value: linkUrl,
    onChange: function onChange(v) {
      (0, _utils.handleRenderByFormKeyData)(v, function (newItem) {
        var newData = (0, _extends2["default"])({}, linkUrl, newItem);
        setLinkUrl(newData);
      });
    }
  })), type === _type.TelegramType.share && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_boxSlotComponent["default"], {
    title: "" + (0, _locale.t)('setter.shareLink')
  }, /*#__PURE__*/_react["default"].createElement(_renderByFormKey["default"], {
    relationOption: telegramRelationOption,
    value: shareUrl,
    onChange: function onChange(v) {
      (0, _utils.handleRenderByFormKeyData)(v, function (newItem) {
        var newData = (0, _extends2["default"])({}, shareUrl, newItem);
        setShareUrl(newData);
      });
    }
  })), /*#__PURE__*/_react["default"].createElement(_boxSlotComponent["default"], {
    title: "" + (0, _locale.t)('setter.shareStartAppId')
  }, /*#__PURE__*/_react["default"].createElement(_renderByFormKey["default"], {
    relationOption: telegramRelationOption,
    value: shareStartApp,
    onChange: function onChange(v) {
      (0, _utils.handleRenderByFormKeyData)(v, function (newItem) {
        var newData = (0, _extends2["default"])({}, shareStartApp, newItem);
        setShareStartApp(newData);
      });
    }
  })), /*#__PURE__*/_react["default"].createElement(_boxSlotComponent["default"], {
    title: "" + (0, _locale.t)('setter.shareContent')
  }, /*#__PURE__*/_react["default"].createElement(_renderByFormKey["default"], {
    relationOption: telegramRelationOption,
    value: shareContent,
    onChange: function onChange(v) {
      (0, _utils.handleRenderByFormKeyData)(v, function (newItem) {
        var newData = (0, _extends2["default"])({}, shareContent, newItem);
        setShareContent(newData);
      });
    }
  }))), type === _type.TelegramType.touch && /*#__PURE__*/_react["default"].createElement(_boxSlotComponent["default"], {
    title: "" + (0, _locale.t)('setter.touch')
  }, /*#__PURE__*/_react["default"].createElement(_select["default"], {
    className: "itemOne_select",
    style: {
      width: 100 + "%",
      minWidth: 0
    },
    placeholder: (0, _locale.t)("setter.selectPlaceHolder"),
    notFoundContent: (0, _locale.t)('setter.notFoundContent'),
    dataSource: TouchOptions,
    value: touchType,
    onChange: function onChange(v) {
      setTouchType(v);
    }
  })));
};