// 点赞
import React from 'react';
import { LikeFilled } from '@ant-design/icons';
import classNames from 'classnames';
import { useRequest } from 'ahooks';
import { putCommentLike, putCommentReplyLike } from "../../service";
import "./index.less";
var ThumbsUp = function ThumbsUp(_ref) {
  var id = _ref.id,
    count = _ref.count,
    selected = _ref.selected,
    type = _ref.type,
    getToken = _ref.getToken,
    onChange = _ref.onChange;
  var _useRequest = useRequest(type === 'minor' ? putCommentReplyLike : putCommentLike, {
      manual: true
    }),
    runAsync = _useRequest.runAsync,
    loading = _useRequest.loading;
  var onClick = function onClick() {
    if (loading) return;
    getToken().then(function (data) {
      runAsync({
        id: id,
        flag: !selected,
        accessToken: data === null || data === void 0 ? void 0 : data.accessToken
      }).then(function () {
        onChange(id, {
          allowedCancelLike: !selected,
          likeNumber: selected ? count - 1 : count + 1
        }, type);
      });
    });
  };
  return /*#__PURE__*/React.createElement("span", {
    className: classNames('m-thumbs-up', {
      'm-thumbs-up-active': selected
    }),
    onClick: onClick
  }, /*#__PURE__*/React.createElement(LikeFilled, null), /*#__PURE__*/React.createElement("span", null, count));
};
export default ThumbsUp;