var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/comment/list/comment-detail/index.tsx
var comment_detail_exports = {};
__export(comment_detail_exports, {
  default: () => comment_detail_default
});
module.exports = __toCommonJS(comment_detail_exports);
var import_react = __toESM(require("react"));
var import_icons = require("@ant-design/icons");
var import_antd = require("antd");
var import_ahooks = require("ahooks");
var import_moment = __toESM(require("moment"));
var import_context = require("../../../config-provider/context");
var import_iconfont = __toESM(require("../../../iconfont"));
var import_comment_editor = __toESM(require("../../../comment-editor"));
var import_set_inner_html = __toESM(require("../set-inner-html"));
var import_delete = __toESM(require("../delete"));
var import_thumbs_up = __toESM(require("../thumbs-up"));
var import_selection = __toESM(require("../selection"));
var import_service = require("../../service");
var import_index = require("./index.less");
var CommentItemDetail = ({
  issueId,
  commentId,
  parentReplyId,
  type,
  maxLength,
  className = "",
  record,
  hideSelection,
  hideDelete,
  hideLike,
  getToken,
  onReply,
  onDelete,
  onChangeComment,
  renderUser,
  renderAt
}) => {
  const { uiLocale } = (0, import_react.useContext)(import_context.ConfigContext);
  const [visible, setVisible] = (0, import_react.useState)(false);
  const [show, setShow] = (0, import_react.useState)(false);
  const { runAsync: postReply } = (0, import_ahooks.useRequest)(import_service.postCommentReply, { manual: true });
  const evReply = (value) => getToken().then((data) => {
    postReply({ id: issueId, commentId, parentReplyId, accessToken: data == null ? void 0 : data.accessToken, ...value }).then((res) => {
      onReply(record.id, res);
      setVisible(false);
      setShow(false);
    });
  });
  const renderUserInfo = (info) => {
    const name = (info == null ? void 0 : info.name) || uiLocale.Comment.anonymity;
    return renderUser ? renderUser(info ? { id: info.id, name: info.name, other: JSON.parse(info.other || "{}") } : null) : [name, name];
  };
  const renderOperate = () => /* @__PURE__ */ import_react.default.createElement(import_antd.Space, { size: [16, 0] }, record.allowedChosen && type === "main" && !hideSelection && /* @__PURE__ */ import_react.default.createElement(import_selection.default, { id: record.id, type, selected: record.chosen, onChange: onChangeComment, getToken }), record.allowedDelete && !hideDelete && /* @__PURE__ */ import_react.default.createElement(import_delete.default, { id: record.id, type, onChange: onDelete, getToken }), /* @__PURE__ */ import_react.default.createElement("span", { onClick: () => setVisible(!visible), className: "comment-operate-item" }, visible ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_iconfont.default, { type: "icon-ehr-ui-shouqi" }), uiLocale.Comment.collapse) : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_iconfont.default, { type: "icon-ehr-ui-huifu" }), uiLocale.Comment.reply)), !hideLike && /* @__PURE__ */ import_react.default.createElement(
    import_thumbs_up.default,
    {
      id: record.id,
      type,
      count: record.likeNumber || 0,
      selected: record.allowedCancelLike,
      onChange: onChangeComment,
      getToken
    }
  ));
  const renderName = () => record.parentReplyId ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("a", null, renderUserInfo(record.commentor)[1]), " ", uiLocale.Comment.reply, " ", /* @__PURE__ */ import_react.default.createElement("a", null, renderUserInfo(record.toReplier)[1])) : /* @__PURE__ */ import_react.default.createElement("a", null, renderUserInfo(record.commentor)[1]);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: `comment-item-detail ${className} `, onMouseEnter: () => setShow(true), onMouseLeave: () => setShow(false) }, type === "main" && /* @__PURE__ */ import_react.default.createElement("div", { className: "comment-item-detail-main" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "comment-item-detail-head comment-item-detail-head-main" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "name" }, renderName()), record.chosen && /* @__PURE__ */ import_react.default.createElement("span", { className: "selection" }, /* @__PURE__ */ import_react.default.createElement(import_icons.FireFilled, null), " ", uiLocale.Comment.selected)), /* @__PURE__ */ import_react.default.createElement("div", { className: "comment-item-detail-content" }, /* @__PURE__ */ import_react.default.createElement(import_set_inner_html.default, { html: record.content, renderAt })), /* @__PURE__ */ import_react.default.createElement("div", { className: "comment-operate" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "time" }, (0, import_moment.default)(record.createTime).format("YYYY-MM-DD HH:mm")), /* @__PURE__ */ import_react.default.createElement("div", null, renderOperate())), visible && /* @__PURE__ */ import_react.default.createElement(
    import_comment_editor.default,
    {
      maxLength,
      placeholder: `${uiLocale.Comment.replyTo} ${renderUserInfo(record.commentor)[0]}：`,
      onSubmit: evReply
    }
  )), type === "minor" && /* @__PURE__ */ import_react.default.createElement("div", { className: "comment-item-detail-minor" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "comment-item-detail-head" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "name" }, renderName(), "："), /* @__PURE__ */ import_react.default.createElement(import_set_inner_html.default, { html: record.content, renderAt })), /* @__PURE__ */ import_react.default.createElement("div", { className: "comment-item-detail-footer" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "time" }, (0, import_moment.default)(record.createTime).format("YYYY-MM-DD HH:mm")), show && /* @__PURE__ */ import_react.default.createElement("div", { className: "comment-operate" }, renderOperate())), visible && /* @__PURE__ */ import_react.default.createElement(
    import_comment_editor.default,
    {
      maxLength,
      placeholder: `${uiLocale.Comment.replyTo} ${renderUserInfo(record.commentor)[0]}：`,
      onSubmit: evReply
    }
  )));
};
var comment_detail_default = CommentItemDetail;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});
