// 精选
import React, { useContext } from 'react';
import { FireFilled } from '@ant-design/icons';
import { useRequest } from 'ahooks';
import classNames from 'classnames';
import { ConfigContext } from "../../../config-provider/context";
import { putCommentSelection } from "../../service";
import "./index.less";
var Selection = function Selection(_ref) {
  var id = _ref.id,
    selected = _ref.selected,
    type = _ref.type,
    getToken = _ref.getToken,
    onChange = _ref.onChange;
  var _useContext = useContext(ConfigContext),
    uiLocale = _useContext.uiLocale;
  var _useRequest = useRequest(putCommentSelection, {
      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, {
          chosen: !selected
        }, type);
      });
    });
  };
  return /*#__PURE__*/React.createElement("span", {
    className: classNames('m-selection', {
      'm-selection-active': selected
    }),
    onClick: onClick
  }, /*#__PURE__*/React.createElement(FireFilled, null), selected ? uiLocale.Comment.cancelSelected : uiLocale.Comment.selected);
};
export default Selection;