// 删除评论
import React, { useContext } from 'react';
import { message } from 'antd';
import { useRequest } from 'ahooks';
import Iconfont from "../../../iconfont";
import { ConfigContext } from "../../../config-provider/context";
import { delComment, delCommentReply } from "../../service";
import "./index.less";
var DeleteComment = function DeleteComment(_ref) {
  var id = _ref.id,
    type = _ref.type,
    getToken = _ref.getToken,
    onChange = _ref.onChange;
  var _useContext = useContext(ConfigContext),
    uiLocale = _useContext.uiLocale;
  var _useRequest = useRequest({
      main: delComment,
      minor: delCommentReply
    }[type], {
      manual: true
    }),
    loading = _useRequest.loading,
    runAsync = _useRequest.runAsync;
  var onClick = function onClick() {
    if (loading) return;
    getToken().then(function (data) {
      runAsync({
        id: id,
        accessToken: data === null || data === void 0 ? void 0 : data.accessToken
      }).then(function () {
        message.success(uiLocale.Comment.deleteSuccess);
        onChange(id, type);
      });
    });
  };
  return /*#__PURE__*/React.createElement("span", {
    className: "m-comment-operate-delete",
    onClick: onClick
  }, /*#__PURE__*/React.createElement(Iconfont, {
    type: "icon-ehr-ui-shanchu"
  }), uiLocale.Comment.delete);
};
export default DeleteComment;